public async Task DeleteByIdAsync_KnownEntity_ShouldDeleteEntity() { // Arrange TestEntity[] entities = _fixture.CreateMany <TestEntity>(2).ToArray(); var dbContextMock = new DbContextMock <TestDbContext>(_options); dbContextMock.CreateDbSetMock(x => x.TestEntities, (x, _) => (x.Id), entities); var repository = new ReadWriteRepository <TestEntity, Guid>(() => dbContextMock.Object); // Act await repository.DeleteByIdAsync(entities[0].Id); await repository.CommitAsync(); TestEntity[] getAll = await repository.GetAllAsync(); // Assert getAll.SingleOrDefault(x => x.Id == entities[0].Id).Should().BeNull(); getAll.Should().HaveCount(1); }
public async Task DeleteAsync_UnknownEntity_ShouldNotThrowException() { // Arrange TestEntity[] entities = _fixture.CreateMany <TestEntity>(2).ToArray(); var dbContextMock = new DbContextMock <TestDbContext>(_options); dbContextMock.CreateDbSetMock(x => x.TestEntities, (x, _) => (x.Id), entities); var repository = new ReadWriteRepository <TestEntity, Guid>(() => dbContextMock.Object); // Act await repository.DeleteAsync(_fixture.Create <TestEntity>()); await repository.CommitAsync(); TestEntity[] getAll = await repository.GetAllAsync(); // Assert getAll.Should().ContainEquivalentOf(entities[0]); getAll.Should().HaveCount(2); }