public void Remove_ExistingEntity_EntityDeleted()
        {
            var eventStore = _dbContext.Persons.Add(new PersonEventStore {
                Id = 12
            }).Entity;

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

            var repo = new PersonDbEventStoreRepository(new EfCoreDbContext <TestDbContext>(_dbContext));

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

            entity.Should().NotBeNull();

            repo.Remove(entity);
            _dbContext.SaveChanges();

            _dbContext.Persons.Count().Should().Be(0);
            _dbContext.Persons.SelectMany(s => s.Events).Count().Should().Be(0);
        }
Пример #2
0
        public void Remove_NonExistingEntity_ExceptionThrown()
        {
            var repo = new PersonDbEventStoreRepository(new EfCoreDbContext <TestDbContext>(_dbContext));

            var entity = new Person(123);

            Action act = () => repo.Remove(entity);

            act.Should().Throw <EventStoreNotFoundException>();
        }
        public void Remove_NonExistingEntity_ReturnsNull()
        {
            var repo = new PersonDbEventStoreRepository(new EfCoreDbContext <TestDbContext>(_dbContext));

            var entity = new Person(123);

            var result = repo.Remove(entity);

            result.Should().BeNull();
        }