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);
            }
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
 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));
        }
Beispiel #8
0
        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 }));
        }
Beispiel #9
0
        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);
        }
Beispiel #13
0
 public void False_for_empty_buffer() => EventBuffer.Empty(17).HasUncommitted.Should().BeFalse();
Beispiel #14
0
 public void False_for_non_empty_buffer() => EventBuffer.Empty(17).Add(new EmptyEvent()).IsEmpty.Should().BeFalse();
Beispiel #15
0
 public void True_for_empty_buffer() => EventBuffer.Empty(17).IsEmpty.Should().BeTrue();
Beispiel #16
0
 public void Empty_with_initial_has_equals(int version)
 => EventBuffer.Empty(Guid.NewGuid(), version).Version.Should().Be(version);
Beispiel #17
0
 public void AddRange()
 => Assert.That(() => EventBuffer.Empty(666).AddRange(Array.Empty <object>()), Is.Not.Null);
Beispiel #18
0
 public void ClearCommitted()
 => Assert.That(() => EventBuffer.Empty(666).ClearCommitted(), Is.Not.Null);
Beispiel #19
0
 public void True_for_non_empty_buffer() => EventBuffer.Empty(17).Add(new EmptyEvent()).HasUncommitted.Should().BeTrue();
Beispiel #20
0
 public void False_for_non_empty_buffer_all_marked_as_committed()
 => EventBuffer.Empty(17).Add(new EmptyEvent()).MarkAllAsCommitted().HasUncommitted.Should().BeFalse();
Beispiel #21
0
 public void Empty_has_version_0()
 => EventBuffer.Empty(Guid.NewGuid()).Version.Should().Be(0);