Пример #1
0
        public void Setup()
        {
            _dto = new ZooAnimalTypeDto()
            {
                DyingTimeInSeconds          = 10,
                MinHealthRequiredForLife    = 30,
                MinHealthRequiredForWalking = 40,
                Name = "Giraffe"
            };

            _zooAnimalType    = new ZooAnimalType(_dto);
            _generalZooAnimal = new ZooAnimal(_zooAnimalType, Mock.Of <IZoo>());
        }
Пример #2
0
        public void WhenFeedIsCalledWithDefaultValue_ThenAnimalsHealthGoesUp()
        {
            _zoo.Start((animalTypes) =>
            {
                animalTypes.Where(at => at.Name == "Giraffe").FirstOrDefault().Population  = 1;
                animalTypes.Where(at => at.Name == "Elephant").FirstOrDefault().Population = 2;
                animalTypes.Where(at => at.Name == "Monkey").FirstOrDefault().Population   = 0;
            });

            var randomizer = new Random();

            //the animal types should probably be a dictionary
            ZooAnimalType giraffe  = _zoo.AnimalTypes.Where(at => at.Name == "Giraffe").First();
            ZooAnimalType elephant = _zoo.AnimalTypes.Where(at => at.Name == "Elephant").First();

            var giraffeFood = new Food()
            {
                AnimalType = giraffe, NutritionalValue = randomizer.Next(10, 25)
            };
            var elephantFood = new Food()
            {
                AnimalType = elephant, NutritionalValue = randomizer.Next(10, 25)
            };

            List <Food> feed = new List <Food>()
            {
                giraffeFood,
                elephantFood
            };

            //need to decrease them first
            _zoo.AdvanceTime();
            _zoo.AdvanceTime();
            //three times! - hope no one dies
            _zoo.AdvanceTime();

            var overallHealthBefore = _zoo.Animals.Sum(a => a.Health);

            _zoo.FeedAnimals(feed);

            var overallHealthAfter = _zoo.Animals.Sum(a => a.Health);

            Assert.Greater(overallHealthAfter, overallHealthBefore);
        }