示例#1
0
        public void DogFactory_NotConfigured()
        {
            Pet expectedPet = new Pet();

            expectedPet.Type = "fish";
            Pet generatedPet = _petFactory.GetPet("fish");

            Assert.Equal(expectedPet.Type, generatedPet.Type);
        }
示例#2
0
        public static void Main(string[] args)
        {
            var petFactory = new PetFactory();

            var pet = petFactory.GetPet(PetType.Dog);

            pet.Speak();

            pet = petFactory.GetPet(PetType.Duck);

            pet.Speak();
        }
示例#3
0
        public void UpdateStats()
        {
            Pet   generatedPet       = _petFactory.GetPet();
            float initialHapiness    = generatedPet.Happiness;
            float initialHungriness  = generatedPet.Hungriness;
            float minutesElapsed     = 5.0f;
            float expectedHapiness   = initialHapiness + minutesElapsed * generatedPet.HappinessRate;
            float expectedHungriness = initialHungriness + minutesElapsed * generatedPet.HungrinessRate;

            generatedPet.LastUpdate = DateTime.UtcNow - TimeSpan.FromMinutes(minutesElapsed);
            generatedPet.UpdateMetrics();
            Assert.Equal(generatedPet.Hungriness, expectedHungriness);
            Assert.Equal(generatedPet.Happiness, expectedHapiness);
        }
示例#4
0
        public void Run()
        {
            string input = reader.ReadLine();

            while (input != "End")
            {
                string[] splitted = input.Split();

                string type = splitted[0];

                ICitizen citizen = null;
                IRobot   robot   = null;
                IPet     pet     = null;

                if (type == "Citizen")
                {
                    citizen = citizenFactory.GetCitizen(splitted);
                    list.Add(citizen.Birthdate);
                }
                else if (type == "Robot")
                {
                    robot = robotFactory.GetRobot(splitted);
                }
                else if (type == "Pet")
                {
                    pet = petFactory.GetPet(splitted);
                    list.Add(pet.Birthdate);
                }

                input = reader.ReadLine();
            }

            string year = reader.ReadLine();

            foreach (var item in list)
            {
                if (item.EndsWith(year))
                {
                    writer.WriteLine(item);
                }
            }
        }
示例#5
0
        static void Main(string[] args)
        {
            bool quit = false;

            do
            {
                Console.WriteLine("What size of pet do you prefer (small, medium, large)?");
                string petSize = Console.ReadLine();

                var myPet = PetFactory.GetPet(petSize);
                if (myPet != null)
                {
                    myPet.Companion();
                }
                else
                {
                    quit = true;
                }
            }while (quit == false);

            Console.WriteLine("Finished making pets");
        }
示例#6
0
        public Pet Create(string id, string petType)
        {
            // Prevent non-existing types of Pets to be created. A null return will result in a
            // BadRequest response on the side of the Controller
            Pet newPet = _petFactory.GetPet(petType);

            if (newPet == null)
            {
                return(null);
            }
            if (_owners.CountDocuments(user => user.Id.Equals(id)) == 0)
            {
                return(null);
            }
            newPet.OwnerID    = id;
            newPet.LastUpdate = DateTime.UtcNow;
            _pets.InsertOne(newPet);
            // Owners get their pet list updated accordingly
            var update = Builders <User> .Update.Push <string>(owner => owner.OwnedPets, newPet.Id);

            _owners.UpdateOne(user => user.Id.Equals(newPet.OwnerID), update);
            return(newPet);
        }
示例#7
0
        public IActionResult GetName(int petId)
        {
            Pet eq = PetFactory.GetPet(petId);

            return(Json(eq.Description));
        }
示例#8
0
        public IActionResult GetPetActions(int petId)
        {
            Pet eq = PetFactory.GetPet(petId);

            return(Json(eq.frameBooks.Where(c => c.Value.FirstOrDefault()?.frames?.Count() > 0).ToDictionary(c => c.Key, c => c.Value.FirstOrDefault()?.frames?.Count() ?? 0)));
        }
示例#9
0
 public IActionResult GetPet(int petId) => Json(PetFactory.GetPet(petId));
示例#10
0
        private static void Main(string[] args)
        {
            IPet pet = PetFactory.GetPet("Bird");

            pet.Move();
        }