コード例 #1
0
ファイル: Person.cs プロジェクト: yszilagyi/Shelter
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="shelter">Shelter</param>
 /// <param name="identifier">Kind of animal</param>
 public Animal BuyAnimal <T>(ShelterLogic shelter, string identifier)
 {
     if (this.IsOldEnoughToBuyAnimal())
     {
         return(shelter.BuyAnimal <T>(this, identifier));
     }
     else
     {
         throw new Exception($"{this.Name} is not old enough to buy a pet.");
     }
 }
コード例 #2
0
        public void BuyAnimalTest2()
        {
            var shelter = new ShelterRepository(1);
            var logic   = new ShelterLogic(shelter);
            var cat     = new Animal {
                Name = "cat", AgeInHumanYears = 2
            };

            shelter.AddAnimal(cat);
            var person = new Person
            {
                Name         = "John",
                Age          = 18,
                Money        = 9.99,
                OwnedAnimals = new Dictionary <string, Animal>()
            };

            logic.BuyAnimal <Animal>(person, cat.Name);
        }
コード例 #3
0
        public void BuyAnimalTest1()
        {
            var shelter = new ShelterRepository(1);
            var logic   = new ShelterLogic(shelter);
            var cat     = new Cat {
                Name = "cat", AgeInHumanYears = 2
            };
            var person = new Person
            {
                Name         = "John",
                Age          = 18,
                Money        = 9.99,
                OwnedAnimals = new Dictionary <string, Animal>()
            };
            Animal expected = null;
            var    actual   = logic.BuyAnimal <Cat>(person, cat.Name);

            Assert.AreEqual(expected, actual);
        }