Exemple #1
0
        public void GetAggregateEntity_ExistingIdWithPastSnapshot_OnlyRelevantEventsApplied()
        {
            var eventStore = new PersonEventStore {
                PersonId = 12
            };

            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewName\": \"Silverback\"" +
                                  "}",
                Timestamp = DateTime.Parse("2000-05-05")
            });
            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewName\": \"Sergio\"" +
                                  "}",
                Timestamp = DateTime.Parse("2000-03-01")
            });
            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+AgeChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewAge\": 16" +
                                  "}",
                Timestamp = DateTime.Parse("2000-02-01")
            });
            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+AgeChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewAge\": 35" +
                                  "}",
                Timestamp = DateTime.Parse("2019-07-06")
            });

            var repo = new PersonEventStoreRepository(eventStore);

            var entity = repo.GetSnapshotById(12, DateTime.Parse("2000-03-01"));

            entity.Name.Should().Be("Sergio");
            entity.Age.Should().Be(16);
        }