public void CallAGLService_And_ReturnAnEmptyListForBirdOwners()
        {
            // Arrange
            var petService   = new PetService("http://agl-developer-test.azurewebsites.net/people.json");
            var petRetriever = new PetRetriever(petService);

            // Act
            var birdOwners    = petRetriever.GetListOfPetsByPetType(PetType.Bird);
            var numberOfBirds = birdOwners.Count();

            // Assert
            Assert.IsNotNull(birdOwners);
            Assert.AreEqual(0, numberOfBirds);
        }
        public void CallAGLService_And_ReturnAListOfDogshAndTheirOwners()
        {
            // Arrange
            var petService   = new PetService("http://agl-developer-test.azurewebsites.net/people.json");
            var petRetriever = new PetRetriever(petService);

            // Act
            var dogOwners    = petRetriever.GetListOfPetsByPetType(PetType.Dog);
            var numberOfDogs = dogOwners.Count();

            // Assert
            Assert.IsNotNull(dogOwners);
            Assert.AreEqual(2, numberOfDogs);
        }
        public void CallAGLService_And_FindNonExistentPetOwner()
        {
            // Arrange
            var petService   = new PetService("http://agl-developer-test.azurewebsites.net/people.json");
            var petRetriever = new PetRetriever(petService);

            // Act
            var allPetsAndOwners = petRetriever.GetListOfPetsByPetType(PetType.All).GetPetList();
            var sandiPets        = allPetsAndOwners.FindAll(x => x.OwnerName.ToLower() == "sandi");

            // Assert
            Assert.IsNotNull(sandiPets);
            Assert.AreEqual(0, sandiPets.Count);
        }
Example #4
0
        public void ReturnAListOfPetsAndOwners_Successful()
        {
            // Arrange
            var mockHttpClient   = new Mock <IHttpClient>();
            var jsonStringObject = JsonConvert.SerializeObject(_petOwnerList);
            var petRetriever     = new PetRetriever(mockHttpClient.Object);

            mockHttpClient.Setup(x => x.GetResultsAsync()).Returns(Task.FromResult(jsonStringObject));

            // Act
            var catOwnerListGroupByGender = petRetriever.GetListOfPetsByPetType(PetType.Cat);

            // Assert
            Assert.IsNotNull(catOwnerListGroupByGender);
        }
Example #5
0
        public void ReturnAnEmptyListOfPetsAndOwners_ForNonExistingPets()
        {
            // Arrange
            var mockHttpClient   = new Mock <IHttpClient>();
            var jsonStringObject = JsonConvert.SerializeObject(_petOwnerList);
            var petRetriever     = new PetRetriever(mockHttpClient.Object);

            mockHttpClient.Setup(x => x.GetResultsAsync()).Returns(Task.FromResult(jsonStringObject));

            // Act
            var birdOwnerListGroup = petRetriever.GetListOfPetsByPetType(PetType.Bird).GetPetList();

            // Assert
            Assert.IsNotNull(birdOwnerListGroup);
            Assert.AreEqual(0, birdOwnerListGroup.Count);
        }
        public void CallAGLService_And_GroupCatOwnersByOwnerGender()
        {
            // Arrange
            var petService   = new PetService("http://agl-developer-test.azurewebsites.net/people.json");
            var petRetriever = new PetRetriever(petService);

            // Act
            var catOwners       = petRetriever.GetListOfPetsByPetType(PetType.Cat).GroupByGender();
            var maleCatOwners   = catOwners.FindAll(x => x.OwnerGender.ToLower() == "male");
            var femaleCatOwners = catOwners.FindAll(x => x.OwnerGender.ToLower() == "female");

            // Assert
            Assert.IsNotNull(catOwners);
            Assert.AreEqual(2, catOwners.Count);
            Assert.AreEqual(4, maleCatOwners[0].PetName.Count);
            Assert.AreEqual(3, femaleCatOwners[0].PetName.Count);
        }
Example #7
0
        public void ReturnAListOfPetsForKyara_Successful()
        {
            // Arrange
            var mockHttpClient   = new Mock <IHttpClient>();
            var jsonStringObject = JsonConvert.SerializeObject(_petOwnerList);
            var petRetriever     = new PetRetriever(mockHttpClient.Object);

            mockHttpClient.Setup(x => x.GetResultsAsync()).Returns(Task.FromResult(jsonStringObject));

            // Act
            var allPetsAndOwners = petRetriever.GetListOfPetsByPetType(PetType.All).GetPetList();
            var kyaraPets        = allPetsAndOwners.FindAll(x => x.OwnerName.ToLower() == "kyara");

            // Assert
            Assert.IsNotNull(kyaraPets);
            Assert.AreEqual(2, kyaraPets.Count);
            Assert.AreEqual("Thunder", kyaraPets[0].PetName);
            Assert.AreEqual("Lightning", kyaraPets[1].PetName);
        }
Example #8
0
        static void Main(string[] args)
        {
            var  service = new PetService("http://agl-developer-test.azurewebsites.net/people.json");
            IPet pet     = new PetRetriever(service);

            // Use fluent API to chain the actions until we get the grouping of pets by the owner's gender
            var result = pet.GetListOfPetsByPetType(PetType.Cat)
                         .GroupByGender();

            // Print out the groups
            foreach (var group in result)
            {
                Console.WriteLine(group.OwnerGender);
                foreach (var groupPetName in group.PetName)
                {
                    Console.WriteLine($"\t{groupPetName}");
                }
            }

            Console.ReadKey();
        }
Example #9
0
        public void ReturnAListOfCatsAndOwners_Successful()
        {
            // Arrange
            var mockHttpClient   = new Mock <IHttpClient>();
            var jsonStringObject = JsonConvert.SerializeObject(_petOwnerList);
            var petRetriever     = new PetRetriever(mockHttpClient.Object);

            mockHttpClient.Setup(x => x.GetResultsAsync()).Returns(Task.FromResult(jsonStringObject));

            // Act
            var catOwnerListGroupByGender = petRetriever.GetListOfPetsByPetType(PetType.Cat)
                                            .GroupByGender();

            // Assert
            Assert.IsNotNull(catOwnerListGroupByGender);
            Assert.AreEqual(2, catOwnerListGroupByGender.Count);
            Assert.AreEqual("Male", catOwnerListGroupByGender[0].OwnerGender);
            Assert.AreEqual("Molly", catOwnerListGroupByGender[0].PetName[0]);
            Assert.AreEqual("Female", catOwnerListGroupByGender[1].OwnerGender);
            Assert.AreEqual("Kitty", catOwnerListGroupByGender[1].PetName[0]);
        }