public void RemoveRange_ShouldFail_WhenRemovingAllNonExistingEntities(string petId1, string name1, int fkAnimalTypeId1, string petId2, string name2, int fkAnimalTypeId2) { //Arrange Guid wrongGuid = Guid.Parse("c3b922ac-a2bf-4b75-a9dc-5b3c44798264"); Guid petGuid1 = Guid.Parse(petId1); Guid petGuid2 = Guid.Parse(petId2); tblPet pet1 = new tblPet() { Id = petGuid1, Name = name1, FKAnimalTypeId = fkAnimalTypeId1 }; tblPet pet2 = new tblPet() { Id = petGuid2, Name = name2, FKAnimalTypeId = fkAnimalTypeId2 }; var entities = new tblPet[] { pet1, pet2 }; _mockPetRepository.Setup(x => x.FindAsync(It.IsAny <Expression <Func <tblPet, bool> > >())) .ReturnsAsync(new tblPet[] { pet1 }); //Act var task = _service.RemoveRange(entities.Select(x => x.Id)); //Assert _mockPetRepository.Verify(x => x.FindAsync(It.IsAny <Expression <Func <tblPet, bool> > >()), Times.Once()); Assert.ThrowsAsync <InvalidOperationException>(() => task); _mockPetRepository.Verify(x => x.RemoveRange(entities), Times.Never()); Assert.False(task.IsCompletedSuccessfully); }
public void RemoveRange_ShouldSucceed_WithMatchingIds(string petId1, string name1, int fkAnimalTypeId1, string petId2, string name2, int fkAnimalTypeId2) { //Arrange Guid petGuid1 = Guid.Parse(petId1); Guid petGuid2 = Guid.Parse(petId2); tblPet pet1 = new tblPet() { Id = petGuid1, Name = name1, FKAnimalTypeId = fkAnimalTypeId1 }; tblPet pet2 = new tblPet() { Id = petGuid2, Name = name2, FKAnimalTypeId = fkAnimalTypeId2 }; var entities = new tblPet[] { pet1, pet2 }; _mockPetRepository.Setup(x => x.FindAsync(It.IsAny <Expression <Func <tblPet, bool> > >())) .ReturnsAsync(entities); //Act var result = _service.RemoveRange(entities.Select(x => x.Id)); //Assert _mockPetRepository.Verify(x => x.FindAsync(It.IsAny <Expression <Func <tblPet, bool> > >()), Times.Once()); _mockPetRepository.Verify(x => x.RemoveRange(entities), Times.Once()); Assert.True(result.IsCompletedSuccessfully); }