Ejemplo n.º 1
0
        public void CanIMakeANewRepository()
        {
            myContext = new Mock <ZooContext>();
            ZooRepository repo = new ZooRepository(myContext.Object);

            Assert.IsNotNull(repo);
        }
Ejemplo n.º 2
0
        public void Constructor_InvalidData_ThrowsExpectedException()
        {
            //give Simba a weight which is a string
            var document = new XDocument(
                new XElement("Zoo",
                             new XElement("Lions",
                                          new XElement("Lion",
                                                       new XAttribute("name", "Simba"),
                                                       new XAttribute("kg", "xyz")
                                                       )
                                          ),
                             new XElement("Tigers",
                                          new XElement("Tiger",
                                                       new XAttribute("name", "Dante"),
                                                       new XAttribute("kg", 150)
                                                       )
                                          )
                             )
                );
            var mockFileReader = new Mock <IXmlDocumentReader>();

            mockFileReader.Setup(m => m.GetXDocument(It.IsAny <string>())).Returns(document);
            Exception expectedException = null;

            try
            {
                var zooRepository = new ZooRepository(@"c:\temp\RateRepository.txt", mockFileReader.Object);
            }
            catch (Exception e)
            {
                expectedException = e;
            }
            Assert.IsNotNull(expectedException);
            Assert.AreEqual("Could not map element with attributes name=\"Simba\"kg=\"xyz\"", expectedException.Message);
        }
Ejemplo n.º 3
0
        public void GetAnimals_ValidData_ContainsExpectedAnimals()
        {
            var document = new XDocument(
                new XElement("Zoo",
                             new XElement("Lions",
                                          new XElement("Lion",
                                                       new XAttribute("name", "Simba"),
                                                       new XAttribute("kg", 160)
                                                       )
                                          ),
                             new XElement("Tigers",
                                          new XElement("Tiger",
                                                       new XAttribute("name", "Dante"),
                                                       new XAttribute("kg", 150)
                                                       )
                                          )
                             )
                );
            var mockFileReader = new Mock <IXmlDocumentReader>();

            mockFileReader.Setup(m => m.GetXDocument(It.IsAny <string>())).Returns(document);
            var zooRepository = new ZooRepository(@"c:\temp\RateRepository.txt", mockFileReader.Object);

            var animalsList = zooRepository.GetAnimals().ToList();

            var animal1 = animalsList.ElementAt(0);

            Assert.AreEqual("Simba", animal1.Name);
            Assert.AreEqual(160, animal1.Weight);

            var animal2 = animalsList.ElementAt(1);

            Assert.AreEqual("Dante", animal2.Name);
            Assert.AreEqual(150, animal2.Weight);
        }
 public void Initialize()
 {
     mock_context        = new Mock <ZooContext>();
     mock_animal_table   = new Mock <DbSet <Animal> >();
     mock_habitat_table  = new Mock <DbSet <Habitat> >();
     mock_employee_table = new Mock <DbSet <Employee> >();
     habitatList         = new List <Habitat>();
     animalList          = new List <Animal>();
     employeeList        = new List <Employee>();
     repo = new ZooRepository(mock_context.Object);
 }
Ejemplo n.º 5
0
        public void CanIGetMyAnimals()
        {
            //Create your Mock DbSets that will be used for testing.
            Mock <DbSet <Animal> > mockAnimals;

            //Create a list for your DbSet that will be used for testing.
            List <Animal> AnimalList = new List <Animal>()
            {
                new Animal {
                    Name = "Rex", BirthDate = new DateTime(2020, 10, 2)
                }
            };

            myContext = new Mock <ZooContext>();
            ZooRepository repo = new ZooRepository(myContext.Object);

            mockAnimals = new Mock <DbSet <Animal> >();
            ConnectingToDatabase();

            List <Animal> myanimals = repo.GetAnimals();

            Assert.AreEqual(myanimals.Count, 1);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            //Animal animal = new Bear("LION");
            //Console.WriteLine(animal.GetType().Name);


            IRepository repository = new ZooRepository();
            Person      zooWorker  = new ZooWorker();

            var showAnimalsCommand = new ShowAllCommand(repository);
            var insertCommand      = new InsertCommand(repository);
            var feedCommand        = new FeedCommand(repository);
            var healCommand        = new HealCommand(repository);
            var deleteCommand      = new DeleteCommand(repository);

            //repository.ShowAnimalsGroupedByKind();
            //repository.ShowAnimalsByState(State.Full);

            Console.BufferHeight = 200;

            TimerCallback destFunc = new TimerCallback(repository.ChangeRandomAnimalState);
            Timer         changeRandomAnimalStateFiveSec = new Timer(destFunc, null, 5000, 5000);

            while (repository.IsAnythingAlive())
            {
                Console.WriteLine("Name\t\tHP\tMaxHP\tState\n");

                Console.WriteLine("Показать всех животных, сгруппированных по виду животного");
                repository.ShowAnimalsGroupedByKind();

                Console.WriteLine("Показать животных по состоянию - в параметрах передать Состояние");
                repository.ShowAnimalsByState(State.Full);

                Console.WriteLine("Показать всех тигров, которые больны");
                repository.ShowTigersWhichAreSick();

                Console.WriteLine("Показать слона с определенной кличкой, которая задается в параметре");
                repository.ShowElephantWithSpecifiedName("Слониха");

                Console.WriteLine("Показать список всех кличек животных, которые голодны");
                repository.ShowAnimalsNamesWhichAreHungry();

                Console.WriteLine("Показать самых здоровых животных каждого вида (по одному на каждый вид)");
                repository.ShowTheHealthestAnimalEachKinds();

                Console.WriteLine("Показать количество мертвых животных каждого вида");
                repository.ShowCountDeadAnimalsEachKinds();

                Console.WriteLine("Показать всех волков и медведей, у которых здоровье выше 3");
                repository.ShowAllWolfAndBearsWhichHealthAboveThree();

                Console.WriteLine("Показать животное с максимальным здоровьем и животное с минимальным здоровьем (описать одним выражением)");
                repository.ShowAnimalWithMaxHealthAndAnimalWithMinHealth();

                Console.WriteLine("Показать средней количество здоровья у животных в зоопарке");
                repository.ShowAverageHealthAllAnimals();

                zooWorker.Command = showAnimalsCommand;
                zooWorker.Run();

                showCommands();

                int commandNumber;
                int.TryParse(Console.ReadLine().Trim(), out commandNumber);

                zooWorker.Command = null;

                switch (commandNumber)
                {
                case 0:
                    Console.WriteLine("Unknown command");
                    break;

                case 1:
                    zooWorker.Command = insertCommand;
                    break;

                case 2:
                    zooWorker.Command = feedCommand;
                    break;

                case 3:
                    zooWorker.Command = healCommand;
                    break;

                case 4:
                    zooWorker.Command = deleteCommand;
                    break;

                case 5:
                    break;

                default:
                    Console.WriteLine("Unknown command");
                    break;
                }

                zooWorker.Run();

                Console.WriteLine("Press any button for continue...");
                Console.ReadLine();

                Console.Clear();
            }

            zooWorker.Command = showAnimalsCommand;
            zooWorker.Run();
            Console.WriteLine("All animals died. :((99((9((");
        }
 public void Teardown()
 {
     repo = null;
 }