public async Task RemoveAsync_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 = await repo.GetAsync(p => p.Id == 12);

            entity.Should().NotBeNull();

            await repo.RemoveAsync(entity);

            await _dbContext.SaveChangesAsync();

            _dbContext.Persons.Count().Should().Be(0);
            _dbContext.Persons.SelectMany(s => s.Events).Count().Should().Be(0);
        }
Ejemplo n.º 2
0
        public async Task RemoveAsync_NonExistingEntity_ExceptionThrown()
        {
            var repo = new PersonDbEventStoreRepository(new EfCoreDbContext <TestDbContext>(_dbContext));

            var entity = new Person(123);

            Func <Task> act = () => repo.RemoveAsync(entity);

            await act.Should().ThrowAsync <EventStoreNotFoundException>();
        }
        public async Task RemoveAsync_NonExistingEntity_ReturnsNull()
        {
            var repo = new PersonDbEventStoreRepository(new EfCoreDbContext <TestDbContext>(_dbContext));

            var entity = new Person(123);

            var result = await repo.RemoveAsync(entity);

            result.Should().BeNull();
        }