Beispiel #1
0
        public void CanSaveEvent()
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");
            IEvent @event           = agg.GetUncommittedEvents().Single();

            SaveEvent(@event, _conn);
            Assert.Equal(1, GetRowCount("events"));
        }
Beispiel #2
0
        public void SQLiteEnforcesNoSavingDuplicates()
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");
            IEvent @event           = agg.GetUncommittedEvents().Single();

            SaveEvent(@event, _conn);

            Assert.ThrowsAny <Exception>(() => SaveEvent(@event, _conn));
        }
Beispiel #3
0
        public void EditingSimpleAggregateCreatesEvents()
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");

            Assert.Single(agg.GetUncommittedEvents());
            Assert.Equal("foo", agg.Text);

            agg.Text = "bar";
            Assert.Equal(2, agg.GetUncommittedEvents().Count());
            Assert.Equal("bar", agg.Text);
        }
Beispiel #4
0
        public void ContainsEventWorks(IEventRepository repo)
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");

            agg.Text = "bar";

            foreach (IEvent @event in agg.GetUncommittedEvents())
            {
                Assert.False(repo.ContainsEvent(@event.Id));
                repo.Save(@event);
                Assert.True(repo.ContainsEvent(@event.Id));
            }
        }
Beispiel #5
0
        public void GetSerializedEventsWorks()
        {
            SQLiteEventRepository repo = new SQLiteEventRepository(new SqliteConnection("DataSource=:memory:"));

            SimpleTextAggregate agg = new SimpleTextAggregate("foo");

            agg.Text = "bar";

            foreach (IEvent @event in agg.GetUncommittedEvents())
            {
                repo.Save(@event);
            }

            Assert.Equal(2, repo.GetAllSerializedEvents().Count());
        }
Beispiel #6
0
        public async Task CanSaveAndRetrieveSingleEvent()
        {
            List <string> serialized = await _serverCaller.PullAllSerializedEventsAsync();

            Assert.Empty(serialized);

            SimpleTextAggregate agg = new SimpleTextAggregate("foo");
            IEvent @event           = agg.GetUncommittedEvents().Single();
            await _serverCaller.PushEventAsync(@event);

            serialized = await _serverCaller.PullAllSerializedEventsAsync();

            IEvent deserializedEvent = await EventSerialization.DeserializeAsync(serialized.Single());

            AssertEventsAreEqual(@event, deserializedEvent);
        }
Beispiel #7
0
        public void EventCountWorks(IEventRepository repo)
        {
            repo.CountOfAllEvents().Should().Be(0);

            SimpleTextAggregate agg = new SimpleTextAggregate("foo");

            agg.Text = "bar";

            repo.Save(_eventFactory.GetCreatedEvent(Guid.NewGuid(), "foo", "bar"));

            repo.CountOfAllEvents().Should().Be(1);

            repo.Save(_eventFactory.GetPlayedEvent(Guid.NewGuid()));

            repo.CountOfAllEvents().Should().Be(2);
        }
Beispiel #8
0
        public void CanHookUpEventAutoSave()
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");
            IEvent @event           = agg.GetUncommittedEvents().Single();

            SaveEvent(@event, _conn);

            agg.Commit();

            agg.EventCreated += Agg_EventCreated;

            agg.Text = "bar";

            Assert.Empty(agg.GetUncommittedEvents());

            Assert.Equal(2, GetRowCount("events"));
        }
Beispiel #9
0
        public void WillNotSaveSameEventTwice(IEventRepository repo)
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");

            agg.Text = "bar";

            foreach (IEvent @event in agg.GetUncommittedEvents())
            {
                repo.Save(@event);
            }

            Assert.Equal(2, repo.GetAllEvents().Count());

            foreach (IEvent @event in agg.GetUncommittedEvents())
            {
                repo.Save(@event);
            }

            Assert.Equal(2, repo.GetAllEvents().Count());
        }
Beispiel #10
0
        public void TestSimpleTextAggregate()
        {
            Guid     guid        = Guid.NewGuid();
            DateTime createdDate = new DateTime(2020, 12, 25);

            SimpleTextAggregateCreatedEvent createdEvent = new SimpleTextAggregateCreatedEvent(Guid.NewGuid(), guid, createdDate, "foo");

            SimpleTextAggregate agg = new SimpleTextAggregate();

            agg.Apply(new List <IEvent>()
            {
                createdEvent
            });

            Assert.Equal(guid, agg.AggregateId);
            Assert.Equal("foo", agg.Text);

            agg.Apply(new SimpleTextAggregateUpdatedEvent(Guid.NewGuid(), guid, DateTime.UtcNow, "bar"));

            Assert.Equal("bar", agg.Text);
        }
Beispiel #11
0
        public void CanPersistAndRehydrateSimpleAggregate(IEventRepository repo)
        {
            SimpleTextAggregate agg = new SimpleTextAggregate("foo");

            agg.Text = "bar";

            foreach (IEvent @event in agg.GetUncommittedEvents())
            {
                repo.Save(@event);
            }

            Assert.Equal(2, repo.GetEvents(agg.AggregateId).Count());

            agg.Commit();

            SimpleTextAggregate agg2 = new SimpleTextAggregate();

            agg2.Apply(repo.GetEvents(agg.AggregateId));

            Assert.Equal(agg.AggregateId, agg2.AggregateId);
            Assert.Equal(agg.Text, agg2.Text);
        }