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 ReadWriteBaseRepository <TestEntity, Guid, TestDbContext>(dbContextMock.Object); // Act await repository.Delete(_fixture.Create <TestEntity>()); await repository.CommitAsync(); TestEntity[] getAll = await repository.GetAll(); // Assert getAll.Should().ContainEquivalentOf(entities[0]); getAll.Should().HaveCount(2); }
public async Task DeleteAsync_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 ReadWriteBaseRepository <TestEntity, Guid, TestDbContext>(dbContextMock.Object); // Act await repository.Delete(entities[0]); await repository.CommitAsync(); TestEntity[] getAll = await repository.GetAll(); // Assert getAll.SingleOrDefault(x => x.Id == entities[0].Id).Should().BeNull(); getAll.Should().HaveCount(1); }