public void GivenEvents_WhenInlineTransformationIsApplied_ThenReturnsSameNumberOfTransformedItems() { var issue1Id = Guid.NewGuid(); var issue2Id = Guid.NewGuid(); var events = new IIssueEvent[] { new IssueCreated { IssueId = issue1Id, Description = "Description 1" }, new IssueUpdated { IssueId = issue1Id, Description = "Description 1 New" }, new IssueCreated { IssueId = issue2Id, Description = "Description 2" }, new IssueUpdated { IssueId = issue1Id, Description = "Description 1 Super New" }, new IssueUpdated { IssueId = issue2Id, Description = "Description 2 New" }, }; //1. Create events EventStore.StartStream <IssuesList>(events); Session.SaveChanges(); //2. Get transformed events var changeLogs = Session.Query <IssueChangesLog>().ToList(); changeLogs.Should().Have.Count.EqualTo(events.Length); changeLogs.Select(ev => ev.IssueId) .Should().Have.SameValuesAs(events.Select(ev => ev.IssueId)); changeLogs.Count(ev => ev.ChangeType == ChangeType.Creation) .Should().Be.EqualTo(events.OfType <IssueCreated>().Count()); changeLogs.Count(ev => ev.ChangeType == ChangeType.Modification) .Should().Be.EqualTo(events.OfType <IssueUpdated>().Count()); changeLogs.Count(ev => ev.IssueId == issue1Id) .Should().Be.EqualTo(events.Count(ev => ev.IssueId == issue1Id)); changeLogs.Count(ev => ev.IssueId == issue2Id) .Should().Be.EqualTo(events.Count(ev => ev.IssueId == issue2Id)); }
public void GivenEvents_WhenInlineTransformationIsApplied_ThenReturnsSameNumberOfTransformedItems() { var issue1Id = Guid.NewGuid(); var issue2Id = Guid.NewGuid(); var events = new IIssueEvent[] { new IssueCreated { IssueId = issue1Id, Description = "Description 1" }, new IssueUpdated { IssueId = issue1Id, Description = "Description 1 New" }, new IssueCreated { IssueId = issue2Id, Description = "Description 2" }, new IssueUpdated { IssueId = issue1Id, Description = "Description 1 Super New" }, new IssueUpdated { IssueId = issue2Id, Description = "Description 2 New" }, }; //1. Create events var streamId = EventStore.StartStream <IssuesList>(events).Id; Session.SaveChanges(); //2. Get live agregation var issuesListFromLiveAggregation = EventStore.AggregateStream <IssuesList>(streamId); //3. Get inline aggregation var issuesListFromInlineAggregation = Session.Load <IssuesList>(streamId); var projection = Session.Query <IssueDescriptionView>().FirstOrDefault(); issuesListFromLiveAggregation.Should().Not.Be.Null(); issuesListFromInlineAggregation.Should().Not.Be.Null(); issuesListFromLiveAggregation.List.Count.Should().Be.EqualTo(2); issuesListFromLiveAggregation.List.Count.Should().Be.EqualTo(issuesListFromInlineAggregation.List.Count); }
public void GivenOutOfOrderEvents_WhenPublishedWithSetVersion_ThenLiveAggregationWorksFine() { var firstTaskId = Guid.NewGuid(); var secondTaskId = Guid.NewGuid(); var events = new IIssueEvent[] { new IssueUpdated { IssueId = firstTaskId, Description = "Final First Issue Description", IssueVersion = 4 }, new IssueCreated { IssueId = firstTaskId, Description = "First Issue", IssueVersion = 1 }, new IssueCreated { IssueId = secondTaskId, Description = "Second Issue 2", IssueVersion = 2 }, new IssueUpdated { IssueId = firstTaskId, Description = "Intermediate First Issue Description", IssueVersion = 3 }, new IssueUpdated { IssueId = secondTaskId, Description = "Final Second Issue Description", IssueVersion = 5 }, }; //1. Create events var streamId = EventStore.StartStream <IssuesList>(events).Id; Session.SaveChanges(); //2. Get live agregation var issuesListFromLiveAggregation = EventStore.AggregateStream <IssuesList>(streamId); //3. Get inline aggregation var issuesListFromInlineAggregation = Session.Load <IssuesList>(streamId); issuesListFromLiveAggregation.Should().Not.Be.Null(); issuesListFromInlineAggregation.Should().Not.Be.Null(); issuesListFromLiveAggregation.List.Count.Should().Be.EqualTo(2); issuesListFromLiveAggregation.List.Count.Should().Be.EqualTo(issuesListFromInlineAggregation.List.Count); }