Example #1
0
        public void ShouldProduceValidContentResultWhenServiceAvailableAsync()
        {
            var petApiServiceMock = new Mock <IPetApiService>();

            petApiServiceMock.Setup(s => s.LoadPetOwners()).Returns(
                Task.FromResult <List <PetOwner> >(new List <PetOwner> {
                new PetOwner {
                    Gender = "female",
                    Pets   = new List <Pet> {
                        new Pet {
                            Name = "Rock", Type = "Dog"
                        },
                        new Pet {
                            Name = "Ket", Type = "Cat"
                        }
                    }
                }
            }));

            var logCatControllerMock = new Mock <ILogger <CatController> >();

            var catController = new CatController(petApiServiceMock.Object, logCatControllerMock.Object);
            var content       = catController.GetCatNamesByOwnerGender();

            var expected = "<html><body><h5>female</h5><ul><li>Ket</li></ul></body></html>";

            Assert.AreEqual(expected, content.Result.Content.ToString());
        }
Example #2
0
        public void ShouldThrowExceptionWhenServiceUnAvailable()
        {
            // it will be taken care by global exception handling
            var petApiServiceMock = new Mock <IPetApiService>();

            petApiServiceMock.Setup(s => s.LoadPetOwners()).Returns(
                Task.FromResult <List <PetOwner> >(null));

            var logCatControllerMock = new Mock <ILogger <CatController> >();

            var catController = new CatController(petApiServiceMock.Object, logCatControllerMock.Object);

            var content = catController.GetCatNamesByOwnerGender();

            Assert.AreEqual("Faulted", content.Status.ToString());
        }