コード例 #1
0
        public void Store_ConcurrentlyModifyExistingEntity_ExceptionThrown()
        {
            var eventStore = new PersonEventStore {
                PersonId = 12, EntityVersion = 1
            };

            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewName\": \"Silverback\"" +
                                  "}"
            });

            var repo = new PersonEventStoreRepository(eventStore);

            var person  = repo.GetById(12);
            var person2 = repo.GetById(12);

            person.ChangeName("Sergio");
            person.ChangeAge(35);
            person2.ChangeName("Sergio");
            person2.ChangeAge(35);

            repo.Store(person);
            Action act = () => repo.Store(person2);

            act.Should().Throw <SilverbackConcurrencyException>();
        }
コード例 #2
0
        public void Store_ExistingEntity_NewEventsSaved()
        {
            var eventStore = new PersonEventStore {
                PersonId = 12, EntityVersion = 1
            };

            eventStore.Events.Add(new PersonEventStore.PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.Tests\"," +
                                  "\"NewName\": \"Silverback\"" +
                                  "}"
            });

            var repo = new PersonEventStoreRepository(eventStore);

            var person = repo.GetById(12);

            person.ChangeName("Sergio");
            person.ChangeAge(35);

            repo.Store(person);

            repo.EventStores.Count.Should().Be(1);
            repo.EventStores.First().Events.Count.Should().Be(3);
        }
コード例 #3
0
        public void Store_ExistingEntity_NewEventsSaved()
        {
            var eventStore = _dbContext.Persons.Add(new PersonEventStore {
                Id = 12, EntityVersion = 1
            }).Entity;

            eventStore.Events.Add(new PersonEvent
            {
                SerializedEvent = "{" +
                                  "\"$type\": \"Silverback.Tests.EventSourcing.EntityFrameworkCore.TestTypes.Person+NameChangedEvent, Silverback.EventSourcing.EntityFrameworkCore.Tests\"," +
                                  "\"NewName\": \"Silverback\"" +
                                  "}"
            });
            _dbContext.SaveChanges();

            var repo = new PersonEventStoreRepository(_dbContext);

            var person = repo.Get(p => p.Id == 12);

            person.ChangeName("Sergio");
            person.ChangeAge(35);

            repo.Store(person);
            _dbContext.SaveChanges();

            _dbContext.Persons.Count().Should().Be(1);
            _dbContext.Persons.First().Events.Count.Should().Be(3);
        }
コード例 #4
0
        public void Store_EntityWithSomeEvents_VersionCalculated()
        {
            var repo   = new PersonEventStoreRepository();
            var person = new Person();

            person.ChangeName("Sergio");
            person.ChangeAge(35);

            repo.Store(person);

            repo.EventStores.First().EntityVersion.Should().Be(2);
        }
コード例 #5
0
        public void Store_EntityWithSomeEvents_EventsSaved()
        {
            var repo   = new PersonEventStoreRepository();
            var person = new Person();

            person.ChangeName("Sergio");
            person.ChangeAge(35);

            repo.Store(person);

            repo.EventStores.Count.Should().Be(1);
            repo.EventStores.First().Events.Count.Should().Be(2);
        }