public void GetAll_Success_NoResults() { var animalServ = GetMockedAnimalService(); animalServ.Setup(x => x.GetAll()).Returns(new OperationResult <List <AnimalContract> >(true, "Success", new List <AnimalContract>())); var service = new AdoptionService(null, animalServ.Object, null); var result = service.GetAll(); Assert.AreEqual(result.Result.Count, 0); Assert.IsTrue(result.Success); }
public void GetFreeAnimals_Fail_AnimalRepositoryException() { var animalService = GetMockedAnimalService(); string failMessage = "fail"; animalService.Setup(x => x.GetAll()).Throws(new Exception(failMessage)); var service = new AdoptionService(null, animalService.Object, null); var result = service.GetAll(); Assert.IsFalse(result.Success); Assert.AreEqual(result.Message, failMessage); }
public void GetAll_Fail_AdopterServiceException() { var animalServ = GetMockedAnimalService(); var adopterServ = GetMockedAdopterService(); var animalGuid = Guid.NewGuid(); var adopterGuid = Guid.NewGuid(); string failMessage = "fail"; animalServ.Setup(x => x.GetAll()).Returns(GetAnimalOperationResultList(adopterGuid, animalGuid)); adopterServ.Setup(x => x.Get(It.IsAny <Guid>())).Throws(new Exception(failMessage)); var service = new AdoptionService(null, animalServ.Object, adopterServ.Object); var result = service.GetAll(); Assert.IsNull(result.Result); Assert.False(result.Success); Assert.AreEqual(result.Message, failMessage); }
public void GetAll_Success() { var animalServ = GetMockedAnimalService(); var adopterServ = GetMockedAdopterService(); var animalGuid = Guid.NewGuid(); var adopterGuid = Guid.NewGuid(); animalServ.Setup(x => x.GetAll()).Returns(GetAnimalOperationResultList(adopterGuid, animalGuid)); adopterServ.Setup(x => x.Get(adopterGuid)).Returns(new OperationResult <AdopterContract>(true, "Success", new AdopterContract() { ID = adopterGuid })); var service = new AdoptionService(null, animalServ.Object, adopterServ.Object); var result = service.GetAll(); Assert.Greater(result.Result.Count, 0); var adoption = result.Result.First(); Assert.AreEqual(adoption.Animal.AdoptedBy, adoption.Adopter.ID); Assert.IsTrue(result.Success); Assert.IsNotEmpty(result.Message); }