Skip to content

Commit

Permalink
* #1302 - Added test for the ProjectView / DeleteEvent and rebuilding…
Browse files Browse the repository at this point in the history
… projections
  • Loading branch information
oskardudycz committed Jun 3, 2020
1 parent 6e2f1aa commit aef64bf
Showing 1 changed file with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Baseline.Dates;
using Marten.Events.Projections;
using Marten.Events.Projections.Async;
using Marten.Services;
using Marten.Testing.Documents;
using Marten.Testing.Harness;
using Shouldly;
using Xunit;
Expand Down Expand Up @@ -441,6 +445,51 @@ public async Task default_id_event_should_not_create_new_document()
documentCount.ShouldBe(0);
}

[Fact]
public async Task projectview_withdeleteevent_should_be_respected_during_projection_rebuild()
{
StoreOptions(_ =>
{
_.AutoCreateSchemaObjects = AutoCreate.All;
_.Events.InlineProjections.AggregateStreamsWith<Project>();
_.Events.ProjectView<Project, Guid>().DeleteEvent<ProjectClosed>();
});

var projectId = Guid.NewGuid();

theSession.Events.Append(projectId, new ProjectStarted { Id = projectId, Name = "Marten"});
theSession.SaveChanges();

theSession.Query<Project>().Count().ShouldBe(1);

theSession.Events.Append(projectId, new ProjectClosed { Id = projectId });
theSession.SaveChanges();

theSession.Query<Project>().Count().ShouldBe(0);

var settings = new DaemonSettings
{
LeadingEdgeBuffer = 0.Seconds()
};

using (var daemon = theStore.BuildProjectionDaemon(new[] {typeof(User)}, settings: settings))
{
await daemon.RebuildAll();
}

//fails as user is back in the database after rebuilding
theSession.Query<Project>().Count().ShouldBe(0);

theSession.Events.StartStream<QuestParty>(streamId, started);
theSession.SaveChanges();

var document = await theSession.LoadAsync<PersistedView>(streamId);
document.ShouldBeNull();

var documentCount = await theSession.Query<PersistedView>().CountAsync();
documentCount.ShouldBe(0);
}

public project_events_from_multiple_streams_into_view(DefaultStoreFixture fixture) : base(fixture)
{
}
Expand Down Expand Up @@ -604,4 +653,31 @@ private void Persist(NewsletterSubscription view, NewsletterOpened @event)
}

// ENDSAMPLE

public class Project
{
public Guid Id { get; set; }
public string Name { get; set; }

public void Apply(ProjectStarted e)
{
Id = e.Id;
Name = e.Name;
}

public void Apply(ProjectClosed e)
{
}
}

public class ProjectStarted
{
public Guid Id { get; set; }
public string Name { get; set; }
}

public class ProjectClosed
{
public Guid Id { get; set; }
}
}

0 comments on commit aef64bf

Please sign in to comment.