public void HasUncommittedEvents_WithMissingEvents_DisplayedInTheMessage() { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new object[] { new EmptyEvent(), new OtherEvent { Value = 3 } }); var x = Assert.Catch <AssertionFailed>(() => AggregateRootAssert.HasUncommittedEvents(buffer, new EmptyEvent(), new OtherEvent { Value = 3 }, new SimpleEvent { Value = 5 }, new OtherEvent { Value = 9 } )); Assert.AreEqual(@"Assertion failed: [0] EmptyEvent [1] OtherEvent [2] Missing: SimpleEvent [3] Missing: OtherEvent ", x.Message); }
public void HasUncommittedEvents_DiffrentEventValues_DisplayedInTheMessage() { using (CultureInfoScope.NewInvariant()) { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new object[] { new EmptyEvent(), new Complex { Value = 17, Message = "Same", Date = new DateTime(2017, 06, 11) }, new SimpleEvent(), }); var x = Assert.Catch <AssertionFailed>(() => AggregateRootAssert.HasUncommittedEvents(buffer, new EmptyEvent(), new Complex { Value = 23, Message = "Same", Date = new DateTime(1980, 06, 30) }, new SimpleEvent() )); Assert.AreEqual(@"Assertion failed: [0] EmptyEvent [1] Expected: { Value: 23, Date: 06/30/1980 00:00:00 } Actual: { Value: 17, Date: 06/11/2017 00:00:00 } [2] SimpleEvent ", x.Message); } }
public void with_uncommitted() { var buffer = EventBuffer.Empty(Guid.Parse("1F8B5071-C03B-457D-B27F-442C5AAC5785")) .Add(new EmptyEvent()); DebuggerDisplayAssert.HasResult("Version: 1 (Committed: 0), Aggregate: 1f8b5071-c03b-457d-b27f-442c5aac5785", buffer); }
public static Result <Game> Handle(object command, Buffer buffer = null) { buffer ??= EventBuffer.Empty(GameId); var processor = new TestProcessor(buffer, 17); var result = processor.Send(command); return(result.IsValid ? Result.For(processor.Buffer.Load(), result.Messages) : Result.WithMessages <Game>(result.Messages)); }
public static Buffer BeneluxWithoutArmies(int roundLimit = 10) => EventBuffer.Empty(GameId) .Add(new SettingsInitialized(2, roundLimit, false)) .Add(new MapInitialized( Continents: new[] { new ContinentInitialized("Benelux", 3, new[] { Netherlands, Belgium, Luxembourg }) }, Countries: new[] { new CountryInitialized("Netherlands", new [] { Belgium }), new CountryInitialized("Belgium", new [] { Netherlands, Luxembourg }), new CountryInitialized("Luxembourg", new [] { Belgium }), }));
public void HasUncommittedEvents_EqualArrayValues_IsTrue() { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new ArrayEvent { Numbers = new[] { 17 } }); AggregateRootAssert.HasUncommittedEvents(buffer, new ArrayEvent { Numbers = new[] { 17 } }); }
public void from_buffer() { var id = Guid.Parse("58B82A50-B906-4178-87EC-A8C31B49368B"); var buffer = EventBuffer.Empty(id).Add(new NameUpdated { Name = "Jimi Hendrix" }); var replayed = AggregateRoot.FromStorage <SimpleEventSourcedRoot, Guid>(buffer); Assert.That(replayed.Version, Is.EqualTo(1)); Assert.That(replayed.Id, Is.EqualTo(id)); Assert.That(replayed.Buffer.Count(), Is.EqualTo(1)); }
public void convert_uses_version_according_to_buffer() { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new EmptyEvent()) .Add(new EmptyEvent()) .Add(new EmptyEvent()) .MarkAllAsCommitted() .Add(new EmptyEvent()) .Add(new EmptyEvent()); var selected = buffer.SelectUncommitted((id, version, @event) => version); Assert.That(selected.Count(), Is.EqualTo(2)); Assert.That(selected, Is.EqualTo(new[] { 4, 5 })); }
public void convert_uses_aggregate_id() { var buffer = EventBuffer.Empty("my-id-007") .Add(new EmptyEvent()) .Add(new EmptyEvent()) .Add(new EmptyEvent()); var selected = buffer.SelectUncommitted((id, version, @event) => new StoredEvent(id, version, @event)); selected.Should().BeEquivalentTo(new[] { new StoredEvent("my-id-007", 1, new EmptyEvent()), new StoredEvent("my-id-007", 2, new EmptyEvent()), new StoredEvent("my-id-007", 3, new EmptyEvent()), }); }
public void HasUncommittedEvents_DifferentArrayValues_DisplayedInTheMessage() { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new ArrayEvent { Numbers = new[] { 17 } }); var x = Assert.Catch <AssertionFailed>(() => AggregateRootAssert.HasUncommittedEvents(buffer, new ArrayEvent { Numbers = new[] { 18 } } )); Assert.AreEqual(@"Assertion failed: [0] Expected: { Numbers: [ 18 ] } Actual: { Numbers: [ 17 ] } ", x.Message); }
public void HasUncommittedEvents_IsTrue() { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new object[] { new EmptyEvent(), new SimpleEvent { Value = 3 }, new OtherEvent { Value = 3 } }); AggregateRootAssert.HasUncommittedEvents(buffer, new EmptyEvent(), new SimpleEvent { Value = 3 }, new OtherEvent { Value = 3 } ); }
public void HasUncommittedEvents_DiffrentEventTypes_DisplayedInTheMessage() { var buffer = EventBuffer.Empty(Guid.NewGuid()) .Add(new object[] { new EmptyEvent(), new SimpleEvent(), new SimpleEvent() }); var x = Assert.Catch <AssertionFailed>(() => AggregateRootAssert.HasUncommittedEvents(buffer, new EmptyEvent(), new OtherEvent(), new SimpleEvent() )); Assert.AreEqual(@"Assertion failed: [0] EmptyEvent [1] Expected: TestEvents.OtherEvent Actual: TestEvents.SimpleEvent [2] SimpleEvent ", x.Message); }
public void False_for_empty_buffer() => EventBuffer.Empty(17).HasUncommitted.Should().BeFalse();
public void False_for_non_empty_buffer() => EventBuffer.Empty(17).Add(new EmptyEvent()).IsEmpty.Should().BeFalse();
public void True_for_empty_buffer() => EventBuffer.Empty(17).IsEmpty.Should().BeTrue();
public void Empty_with_initial_has_equals(int version) => EventBuffer.Empty(Guid.NewGuid(), version).Version.Should().Be(version);
public void AddRange() => Assert.That(() => EventBuffer.Empty(666).AddRange(Array.Empty <object>()), Is.Not.Null);
public void ClearCommitted() => Assert.That(() => EventBuffer.Empty(666).ClearCommitted(), Is.Not.Null);
public void True_for_non_empty_buffer() => EventBuffer.Empty(17).Add(new EmptyEvent()).HasUncommitted.Should().BeTrue();
public void False_for_non_empty_buffer_all_marked_as_committed() => EventBuffer.Empty(17).Add(new EmptyEvent()).MarkAllAsCommitted().HasUncommitted.Should().BeFalse();
public void Empty_has_version_0() => EventBuffer.Empty(Guid.NewGuid()).Version.Should().Be(0);