示例#1
0
        public void RetrieveInvalidData_Test()
        {
            AnimalRepository repo = new AnimalRepository();

            repo.Add(firstAnimal);
            repo.Add(secondAnimal);
            Animal first  = repo.GetById(1);
            Animal second = repo.GetById(2);

            Assert.AreEqual("Bobita", first.Name);
            Assert.AreEqual("Cat", first.Description);
            Assert.AreEqual(3, first.Id);
        }
示例#2
0
        public void AnimalEntryArchiveTest()
        {
            //-- Arrange
            AnimalRepository animalRepos = new AnimalRepository();
            Animal           animal      = new Animal()
            {
                AnimalType = "Cat",
                AnimalName = "MyKitty",
                AnimalAge  = 5,
                AnimalId   = "TESTID"
            };
            var expected = true;

            //-- Act
            animalRepos.Add(animal, "test.csv");
            animalRepos.Archive(animal.AnimalId, "test.csv");
            var actual          = true;
            var animalRetrieved = animalRepos.Retrieve(animal.AnimalId, "test.csv");

            if (animalRetrieved.InShelterState != AnimalStateOption.Returned)
            {
                actual = false;
            }
            File.Delete("test.csv");

            //-- Assert
            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void InserirAnimalData()
        {
            AnimalRepository AnimalRep = new AnimalRepository(new SistemaCompraGadoDGContexto());
            Animal           _Animal   = new Animal();

            _Animal.Descricao = "Mimoza";
            _Animal.Preco     = "1,00";

            AnimalRep.Add(_Animal);
        }
示例#4
0
        public void AnimalEntryUpdateTest()
        {
            //-- Arrange
            AnimalRepository animalRepos = new AnimalRepository();
            Animal           animal      = new Animal()
            {
                AnimalType = "Cat",
                AnimalName = "MyKitty",
                AnimalAge  = 5,
                AnimalId   = "TESTID"
            };
            Animal animalUpdated = new Animal()
            {
                AnimalType = "Cat",
                AnimalName = "MyKitty",
                AnimalAge  = float.Parse("5.6"),
                AnimalId   = "TESTID"
            };
            var expected = true;

            //-- Act
            animalRepos.Add(animal, "test.csv");
            animalRepos.Update(animalUpdated, animal.AnimalId, "test.csv");
            var  animalRetrieved = animalRepos.Retrieve(animal.AnimalId, "test.csv");
            var  actual          = true;
            Type type            = typeof(Animal);

            if (animalRetrieved != null)
            {
                foreach (System.Reflection.PropertyInfo pi in type.GetProperties())
                {
                    var exptValue = type.GetProperty(pi.Name).GetValue(animalUpdated);
                    var actValue  = type.GetProperty(pi.Name).GetValue(animalRetrieved);
                    if (exptValue != null && !exptValue.Equals(actValue))
                    {
                        actual = false;
                        break;
                    }
                    else if (exptValue == null && actValue != null && !actValue.Equals("") && !actValue.Equals("=\"\""))
                    {
                        actual = false;
                        break;
                    }
                }
            }
            File.Delete("test.csv");

            //-- Assert
            Assert.AreEqual(expected, actual);
        }
示例#5
0
        public void AnimalRepository_Add_NotName_Exception()
        {
            //Arrange (Preparación)
            ClinicContext        context    = new ClinicContext();
            IRepository <Animal> repository = new AnimalRepository(context);
            Animal animal = new Animal()
            {
                Id = 1
            };

            //Act (Ejecución)
            Action testCode = () => repository.Add(animal);

            //Assert (Comprobación)
            Assert.Throws <ArgumentNullException>(testCode);
        }
示例#6
0
        private void buttonAddNewAnimal_Click(object sender, EventArgs e)
        {
            if (comboBoxOwnerList.SelectedItem == null)
            {
                return;
            }

            int ownerId = ((Owner)comboBoxOwnerList.SelectedItem).Id;

            Animal newAnimal = new Animal
            {
                Name        = textBoxAnimalName.Text,
                Breed       = textBoxAnimalBreed.Text,
                DateOfBirth = dateTimePickerAnimalDate.Value,
                OwnerId     = ownerId
            };

            textBoxAnimalName.Text        = "";
            textBoxAnimalBreed.Text       = "";
            dateTimePickerAnimalDate.Text = "";

            using (RepositoryContext db = new RepositoryContext("RepositoryContext"))
            {
                OwnerRepository  ownerRepo  = new OwnerRepository(db);
                AnimalRepository animalRepo = new AnimalRepository(db);

                var owner = ownerRepo.GetById(ownerId);
                newAnimal.Owner = owner;

                var animal = animalRepo.Add(newAnimal);
                animalRepo.SaveChanges();
            }


            GetData();
        }
示例#7
0
 public Animal Post([FromBody] Animal animal)
 {
     return(db.Add(animal));
 }
示例#8
0
        /// <summary>
        /// Initialize zoo.
        /// </summary>
        /// <param name="zoo"></param>
        private static void InitializeZoo()
        {
            Console.WriteLine("Welcome to the best Zoo!");


            AnimalRepository animalRepository = new AnimalRepository();

            // Birds

            Animal parrot = new Parrot(1, "Jerome", 1);
            Animal duck   = new Duck(2, "Austin", 2);
            Animal owl    = new Owl(3, "Braxton", 1);

            animalRepository.Add(parrot);
            animalRepository.Add(duck);
            animalRepository.Add(owl);

            // Mammals

            Animal lion   = new Lion(3, "Connor", 7);
            Animal goat   = new Goat(4, "Sly", 4);
            Animal monkey = new Monkey(5, "Gorilaz", 3);

            animalRepository.Add(lion);
            animalRepository.Add(goat);
            animalRepository.Add(monkey);

            // Herbivore

            Animal deer     = new Deer(7, "Lora", 2);
            Animal muleDeer = new MuleDeer(8, "Ann", 4);
            Animal zebra    = new Zebra(9, "Jane", 9);

            animalRepository.Add(deer);
            animalRepository.Add(muleDeer);
            animalRepository.Add(zebra);

            // Keepers

            KeeperRepository keeperRepository = new KeeperRepository();

            Keeper noviceKeeper       = new Keeper(1, Level.Novice);
            Keeper intermediateKeeper = new Keeper(2, Level.Intermediate);
            Keeper advancedKeeper     = new Keeper(3, Level.Advanced);
            Keeper expertKeeper       = new Keeper(4, Level.Expert);

            keeperRepository.Add(noviceKeeper);
            keeperRepository.Add(intermediateKeeper);
            keeperRepository.Add(advancedKeeper);
            keeperRepository.Add(expertKeeper);


            // Assign animals to protect

            noviceKeeper.ProtectAnimal(parrot);
            noviceKeeper.ProtectAnimal(zebra);

            intermediateKeeper.ProtectAnimal(duck);
            intermediateKeeper.ProtectAnimal(lion);

            advancedKeeper.ProtectAnimal(muleDeer);
            advancedKeeper.ProtectAnimal(owl);

            expertKeeper.ProtectAnimal(deer);
            expertKeeper.ProtectAnimal(monkey);

            var animals = animalRepository.GetAll();
            var keepers = keeperRepository.GetAll();

            Zoo zoo = new Zoo(animals, keepers);

            for (int i = 0; i < 10; i++)
            {
                zoo.Run();
                Console.WriteLine("=========================================");
            }
        }
示例#9
0
        private async void SaveAnimal(object sender, RoutedEventArgs e)
        {
            var Name             = "";
            var ShortDescription = "";
            var Description      = "";
            var Appearance       = "";
            var Habitat          = "";
            var ImagePath        = "";
            int TypeOfAnimalId   = _typeNumber;

            if (sender is Button button)
            {
                if (button.Parent is WrapPanel wrapPanel)
                {
                    foreach (var item in wrapPanel.Children)
                    {
                        if (item is Border border && border.Child is Grid grid)
                        {
                            foreach (var itemGrid in grid.Children)
                            {
                                if (itemGrid is TextBox text)
                                {
                                    if (text.Tag.ToString() == "1")
                                    {
                                        Name = text.Text;
                                    }
                                    if (text.Tag.ToString() == "2")
                                    {
                                        ShortDescription = text.Text;
                                    }
                                    if (text.Tag.ToString() == "3")
                                    {
                                        Description = text.Text;
                                    }
                                    if (text.Tag.ToString() == "4")
                                    {
                                        Appearance = text.Text;
                                    }
                                    if (text.Tag.ToString() == "5")
                                    {
                                        Habitat = text.Text;
                                    }
                                    if (text.Tag.ToString() == "6")
                                    {
                                        ImagePath = text.Text;
                                    }
                                }
                            }
                        }
                    }
                    if (Name != "" && ShortDescription != "" && Description != "" && Appearance != "" && Habitat != "" && ImagePath != "")
                    {
                        PageNumber = 1;
                        await _repositoryAnimal.Add(new Domain.Animal()
                        {
                            Name             = Name,
                            ShortDescription = ShortDescription,
                            Description      = Description,
                            Appearance       = Appearance,
                            Habitat          = Habitat,
                            ImagePath        = ImagePath,
                            TypeOfAnimalId   = TypeOfAnimalId
                        });
                        await GetPage(wrapPanel, 0);
                    }
                }
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            Animal first = new Animal
            {
                Id          = 1,
                Name        = "Bobita",
                Description = "Cat"
            };
            Animal second = new Animal
            {
                Id          = 2,
                Name        = "Rex",
                Description = "Dog"
            };
            Animal third = new Animal
            {
                Id          = 3,
                Name        = "Kitty",
                Description = "Cat"
            };
            Animal fourth = new Animal
            {
                Id          = 4,
                Name        = "Daisy",
                Description = "Parrot"
            };
            Animal fifth = new Animal
            {
                Id          = 5,
                Name        = "Max",
                Description = "Dog"
            };


            AnimalRepository repo = new AnimalRepository();

            repo.Add(first);
            repo.Add(second);
            repo.Add(third);
            repo.Add(fourth);
            repo.Add(fifth);

            Animal firstAnimal  = repo.GetById(1);
            Animal secondAnimal = repo.GetById(2);

            IEnumerable <Animal> animalList = repo.GetAll();

            Console.WriteLine(first);
            Console.WriteLine(second);

            Console.WriteLine("Before update: ");
            foreach (var a in animalList)
            {
                Console.WriteLine(a);
            }
            Console.WriteLine("After update: ");

            repo.Update(1, "Mickey", "Mouse");

            foreach (var a in animalList)
            {
                Console.WriteLine(a);
            }
            Console.WriteLine("After removing nr. 4 : ");

            repo.Delete(4);

            foreach (var a in animalList)
            {
                Console.WriteLine(a);
            }

            Tiger tiger = new Tiger();
        }