public async Task DeleteByIdAsync_UnknownEntity_ShouldThrowException() { // 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 Func <Task> deleteEntity = async() => await repository.DeleteByIdAsync(Guid.NewGuid()); // Assert FluentAssertions.Specialized.ExceptionAssertions <NullReferenceException> result = await deleteEntity.Should().ThrowAsync <NullReferenceException>(); }
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); }