示例#1
0
        public void TestGetCatsByOwnerGenderAndPetName()
        {
            // mock pet owners
            List <PetOwner> petOwners = new List <PetOwner>();

            petOwners.Add(new PetOwner {
                name = "Bob", gender = "Male", age = 21, pets = new List <Pet> {
                    new Pet {
                        name = "Heathcliff", type = "Cat"
                    }, new Pet {
                        name = "Rocky", type = "Dog"
                    }
                }
            });
            petOwners.Add(new PetOwner {
                name = "Jennifer", gender = "Female", age = 22, pets = new List <Pet> {
                    new Pet {
                        name = "Garfield", type = "Cat"
                    }, new Pet {
                        name = "Odie", type = "Dog"
                    }
                }
            });
            petOwners.Add(new PetOwner {
                name = "Billy", gender = "Male", age = 23, pets = new List <Pet> {
                    new Pet {
                        name = "Wilson", type = "Cat"
                    }, new Pet {
                        name = "Lion", type = "Cat"
                    }
                }
            });
            petOwners.Add(new PetOwner {
                name = "Rey", gender = "Female", age = 24, pets = new List <Pet> {
                    new Pet {
                        name = "Boots", type = "Cat"
                    }, new Pet {
                        name = "Dory", type = "Fish"
                    }
                }
            });
            AppSettings           settings       = new AppSettings();
            Mock <IPetRepository> mockRepository = new Mock <IPetRepository>();

            mockRepository.CallBase = true;
            mockRepository.Setup(p => p.GetPetOwners()).Returns(petOwners);

            PetManager manager = new PetManager(mockRepository.Object);

            // test get cats
            List <KeyValuePair <string, string> > result = manager.GetCatsByOwnerGenderAndPetName();

            Assert.IsNotNull(result);
            Assert.AreEqual(5, result.Count);
            Assert.AreEqual("Male", result[0].Key);
            Assert.AreEqual("Heathcliff", result[0].Value);
            Assert.AreEqual("Male", result[1].Key);
            Assert.AreEqual("Lion", result[1].Value);
            Assert.AreEqual("Male", result[2].Key);
            Assert.AreEqual("Wilson", result[2].Value);

            Assert.AreEqual("Female", result[3].Key);
            Assert.AreEqual("Boots", result[3].Value);
            Assert.AreEqual("Female", result[4].Key);
            Assert.AreEqual("Garfield", result[4].Value);
        }