Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }