Exemplo n.º 1
0
        public void Should_retrieve_data_from_petowner_api()
        {
            var path = ConfigurationManager.AppSettings["PetOwnerAPI.Url"];
            var uri  = new Uri(path);

            IJsonToPetOwnerConverter converter = new JsonToPetOwnerConverter();
            var httpClient = new HttpClient();
            IPetOwnerApiService apiService = new PetOwnerApiService(httpClient, uri);

            IPetFinder         petFinder      = new CatFinder();
            IPetOwnerFinder    petOwnerFinder = new PetOwnerFinder();
            IPetOwnerFilter    petOwnerFilter = new PetOwnerFilter(petOwnerFinder, petFinder);
            IComparer <string> comparer       = new AlphabeticComparer();
            IPetSorter         petSorter      = new PetNameAlphabeticalSorter(comparer);
            IPetOwnerGrouper   grouper        = new PetOwnerGrouper();
            var apiClient = new PetOwnerApiClient.Client.PetOwnerApiClient(converter, apiService, petOwnerFilter, petSorter, grouper);
            var apiResult = apiClient.GetPetsByPetOwnerGender().Result;

            Assert.IsTrue(apiResult != null);
            Assert.IsTrue(string.IsNullOrEmpty(apiResult.Error));
            if (apiResult.PetsByGender != null)
            {
                var distinctGenders = apiResult.PetsByGender.Select(x => x.Gender).Distinct().ToList();
                var allGenders      = apiResult.PetsByGender.Select(x => x.Gender).ToList();

                Assert.IsTrue(distinctGenders.SequenceEqual(allGenders));
                foreach (var pet in apiResult.PetsByGender)
                {
                    Assert.IsTrue(pet.PetNames.Count() > 0);
                }
            }
        }
Exemplo n.º 2
0
        public void Should_return_true_and_set_pets_correctly_when_pet_finder_condition_is_true()
        {
            var mock = new Mock <IPetFinder>();

            mock.Setup(x => x.Find(It.IsAny <Pet>())).Returns(true);

            var mockOwnerFinder = new Mock <IPetOwnerFinder>();

            var filter = new PetOwnerFilter(mockOwnerFinder.Object, mock.Object);
            var pets   = new List <Pet>();

            pets.Add(new Pet {
                Name = "Fido", Type = "Dog"
            });
            var petowner = new PetOwner {
                Age = 20, Name = "Jack", Gender = "Male", Pets = pets
            };

            PetOwner actualOwner = filter.FilterByPetType(petowner);

            Assert.AreEqual(petowner.Age, actualOwner.Age);
            Assert.AreEqual(petowner.Gender, actualOwner.Gender);
            Assert.AreEqual(petowner.Name, actualOwner.Name);
            Assert.AreEqual(pets[0].Name, actualOwner.Pets[0].Name);
            Assert.AreEqual(pets[0].Type, actualOwner.Pets[0].Type);
        }