public void TestAddAnimalNoType()
        {
            Animal animal = new Animal()
            {
                TypeName         = "",
                HungerPerSecond  = 0.1m,
                SadnessPerSecond = 0.1m
            };

            using (ApiContext context = new ApiContext(dbOptions)) {
                AnimalService service = new AnimalService(context);

                // Test with an empty string
                Assert.Catch <System.ArgumentException>(() => service.Add(animal));

                // Test with only whitespace
                animal.TypeName = "    ";
                Assert.Catch <System.ArgumentException>(() => service.Add(animal));

                // Test with type as null
                animal.TypeName = null;
                Assert.Catch <System.ArgumentException>(() => service.Add(animal));
            }

            // Make sure no animals are in the DB
            using (ApiContext context = new ApiContext(dbOptions)) {
                Assert.AreEqual(0, context.Animals.Count());
            }
        }
        public IHttpActionResult GetAll()
        {
            var service       = new AnimalService();
            var listOfAnimals = service.GetAllAnimals();

            return(Ok(listOfAnimals));
        }
Example #3
0
        public void GetDogsTest()
        {
            var service = new AnimalService();
            var dogs    = service.GetDogs();

            Assert.AreEqual(2, dogs.Count(), "GetDogs() returned and unexpected number of dogs");
        }
Example #4
0
        public void GetAnimalsTest()
        {
            var service = new AnimalService();
            var animals = service.GetAnimals();

            Assert.AreEqual(4, animals.Count(), "GetAnimals() returned and unexpected number of animals");
        }
Example #5
0
        public ActionResult Edit(int id, HistoryEdit model)
        {
            var animalService    = new AnimalService();
            var caretakerService = new CaretakerService();
            var animalList       = animalService.GetAnimals();
            var caretakerList    = caretakerService.GetCaretakers();

            ViewBag.AnimalID    = new SelectList(animalList, "AnimalID", "AnimalName");
            ViewBag.CaretakerID = new SelectList(caretakerList, "CaretakerID", "CaretakerName");

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.HistoryID != id)
            {
                ModelState.AddModelError("", "ID Mismatch");
                return(View(model));
            }
            var service = new HistoryService();

            if (service.UpdateHistory(model))
            {
                TempData["SaveResult"] = "Your History Entry was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your History Entry could not be updated.");
            return(View());
        }
Example #6
0
        public ActionResult Edit(int id)
        {
            var animalService    = new AnimalService();
            var caretakerService = new CaretakerService();
            var animalList       = animalService.GetAnimals();
            var caretakerList    = caretakerService.GetCaretakers();

            ViewBag.AnimalID    = new SelectList(animalList, "AnimalID", "AnimalName");
            ViewBag.CaretakerID = new SelectList(caretakerList, "CaretakerID", "CaretakerName");

            var service = new HistoryService();
            var detail  = service.GetHistoryByID(id);
            var model   =
                new HistoryEdit
            {
                HistoryID       = detail.HistoryID,
                AnimalID        = detail.AnimalID,
                CaretakerID     = detail.CaretakerID,
                AnimalName      = detail.AnimalName,
                CaretakerName   = detail.CaretakerName,
                HistoryCareType = detail.HistoryCareType,
                DateOfCareStart = detail.DateOfCareStart
            };

            return(View(model));
        }
 public CadastroAnimal()
 {
     InitializeComponent();
     ConfigurarCombobox();
     animalService = new AnimalService();
     raceService   = new RaceService();
 }
        public IHttpActionResult GetById(int id)
        {
            var service      = new AnimalService();
            var animalDetail = service.GetAnimalById(id);

            return(Ok(animalDetail));
        }
        public void TestAddAnimalDuplicate()
        {
            Animal animal = new Animal()
            {
                TypeName         = "Some new animal",
                HungerPerSecond  = 0.1m,
                SadnessPerSecond = 0.1m
            };

            using (ApiContext context = new ApiContext(dbOptions)) {
                context.Animals.Add(animal);
                context.SaveChanges();
            }

            using (ApiContext context = new ApiContext(dbOptions)) {
                AnimalService service = new AnimalService(context);

                Assert.Catch <DuplicateEntryException>(() => service.Add(animal));

                // Test with whitespace
                animal.TypeName = "   Some new animal ";
                Assert.Catch <DuplicateEntryException>(() => service.Add(animal));

                // Test with different casing
                animal.TypeName = "some New Animal";
                Assert.Catch <DuplicateEntryException>(() => service.Add(animal));
            }

            // Make sure no additional animals are in the DB
            using (ApiContext context = new ApiContext(dbOptions)) {
                Assert.AreEqual(1, context.Animals.Count());
            }
        }
        private void CreateServiceHost()
        {
            try
            {
                var         container     = new Container();
                var         handler       = container.Get <IHandlerCaller>();
                var         animalService = new AnimalService(handler);
                ServiceHost serviceHost   = new ServiceHost(animalService);


                // TODO: add some transport security for tcp.
                NetTcpBinding        binding     = new NetTcpBinding(SecurityMode.None);
                RoleInstanceEndpoint tcpEndPoint =
                    RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TCPENDPOINT"];
                string tcpEndpoint = String.Format("net.tcp://{0}/AnimalService",
                                                   tcpEndPoint.IPEndpoint);
                serviceHost.AddServiceEndpoint(typeof(IAnimalService), binding, tcpEndpoint);


                serviceHost.Open();
                Trace.TraceInformation("Service is Running");
            }
            catch (Exception eX)
            {
                Trace.TraceInformation("Service can not be started Error Message [" + eX.Message + "]");

                // Also kill the worker.
                OnStop();
            }
        }
Example #11
0
        public void AnimalAgeCantBeNegative()
        {
            // Arrange
            Mock <IAnimalRepository>  animalRepository  = new Mock <IAnimalRepository>();
            Mock <ILodgingRepository> lodgingRepository = new Mock <ILodgingRepository>();

            IAnimalService animalService = new AnimalService(animalRepository.Object, lodgingRepository.Object);

            Animal dog = new Animal
            {
                ID              = 1,
                Name            = "Doggo",
                Age             = -1,
                Description     = "Good boi",
                AnimalType      = AnimalType.Dog,
                Race            = "Beautiful Doggos",
                Picture         = "Goodboi.png",
                DateOfDeath     = null,
                Castrated       = true,
                ChildFriendly   = ChildFriendly.Yes,
                ReasonGivenAway = "Too good a boi",
            };

            animalRepository.Setup(e => e.FindByID(dog.ID))
            .Returns(dog);

            // Act
            var ex = Assert.Throws <InvalidOperationException>(() => animalService.Add(dog));

            // Assert
            Assert.Equal("AS_Services", ex.Source);  // Make sure the error is actually thrown in the service, not somewhere else
            Assert.Equal("Add", ex.TargetSite.Name); // Make sure the error is thrown by the Add method; not something else
            Assert.Equal("Age can't be less then 0", ex.Message);
        }
Example #12
0
        public void should_return_creature_if_just_one_in_database_and_it_have_correct_tag()
        {
            var mockEnv = new MockHostingEnvironment();

            var x = new AnimalService(mockEnv);

            var creatues = new List <Creature>
            {
                new Creature
                {
                    ImagePath    = "book.jpg",
                    CreatureTags = new List <CreatureTags>
                    {
                        new CreatureTags
                        {
                            Tag = new Tag
                            {
                                Name = "book"
                            }
                        }
                    }
                }
            };

            string matchingAnimal = x.GetAnimalUrlThatMatchesTags(new [] { "book" }, creatues);

            Assert.AreEqual("book.jpg", matchingAnimal);
        }
Example #13
0
        /// <summary>
        /// Ponto de entrada principal para o aplicativo.
        /// </summary>
        //[STAThread]
        static void Main(string[] args)
        {
            /*Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             * Application.Run(new Form1());*/

            //String path = "C:\\teste-tecnico-programador\\teste_mov_animais_1.csv";
            AnimalController animalController = new AnimalController();
            EntityContext    db            = new EntityContext();
            AnimalService    animalService = new AnimalService();

            //animalService.Salvar(animalController.ImportaArquivoCSV(path));

            animalService.GetAnimais().ForEach(p => Console.WriteLine(p.Codigo));

            /*Animal animal = new Animal();
             * animal.Codigo = 1;
             *
             * List<Animal> animais = new List<Animal>();
             * animais.Add(animal);
             *
             * animalService.Salvar(animais);*/

            //db.Animal.ToList().ForEach(p => Console.WriteLine(p.Codigo));
        }
        public void TestFindOne()
        {
            string animalType = "Some new animal";
            Animal animal     = new Animal()
            {
                TypeName         = animalType,
                HungerPerSecond  = 0.1m,
                SadnessPerSecond = 0.1m
            };

            using (ApiContext context = new ApiContext(dbOptions)) {
                context.Animals.Add(animal);
                context.Animals.Add(new Animal()
                {
                    TypeName = "Another random animal"
                });
                context.SaveChanges();
            }

            using (ApiContext context = new ApiContext(dbOptions)) {
                AnimalService service = new AnimalService(context);

                Assert.AreNotEqual(null, service.FindOne(animal.Id));
                Assert.AreEqual(animalType, service.FindOne(animal.Id).TypeName);
            }
        }
Example #15
0
        static void Main(string[] args)
        {
            // Require the console Arguments
            var            arguments     = new Arguments(args);
            var            animals       = new List <Animal>();
            IAnimalService animalService = new AnimalService(animals, arguments);
            // var resultList = animalService.GetAll();
            var resultList = animalService.Search();

            Console.WriteLine($"Search Results:");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine($"_________________________________________________");
            Console.WriteLine($"|   Type    |   Name    |   Gender  |   Date    |");
            Console.WriteLine($"-------------------------------------------------");
            foreach (var item in resultList)
            {
                Console.WriteLine($"|   {item.AnimalType}    |   {item.Name}    |   {item.Gender}  |   {item.TimeStamp.ToLongDateString()}    |");
            }
            Console.WriteLine($"_________________________________________________");

            Console.WriteLine();
            Console.WriteLine("Solved By: Luis Delfin BriceƱo Gordy");
            Console.WriteLine("email: [email protected]");
            Console.WriteLine("Thank you !");

            Console.WriteLine();

            Console.WriteLine("Press Enter To Exit. ");
            Console.ReadLine();
        }
Example #16
0
        public async Task AllAsyncShouldReturnCorrectAnimalsByPages()
        {
            var db = DbInfrastructure.GetDatabase();

            for (var i = 0; i < 50; i++)
            {
                await db.AddAsync(new Animal
                {
                    Name = $"Some random name {i}"
                });
            }

            await db.SaveChangesAsync();

            var animalService = new AnimalService(db);

            for (var i = 0; i < 10; i++)
            {
                var animals = await animalService.AllAsync(i + 1);

                animals
                .Should()
                .HaveCount(WebConstants.AnimalsPerPage);

                animals
                .Should()
                .BeInAscendingOrder(a => a.AnimalClass);
            }

            var animalsFromNonExistingPage = await animalService.AllAsync(11);

            animalsFromNonExistingPage.Should().HaveCount(0);
        }
        public void CartManagement_ExistingAnimalsInCartRemoveAnimal_AnAnimalIsRemoved()
        {
            // Arrange
            var existingAnimalOneId             = 1;
            var existingAnimalTwoId             = 2;
            var existingAnimalOneQuantityAmount = 1;
            var existingAnimalTwoQuantityAmount = 1;
            var animalIdToRemove       = 2;
            var animalQuantityToRemove = -1;

            var memoryCache   = new MemoryCache(new MemoryCacheOptions());
            var animalService = new AnimalService();
            var cartService   = new CartService(memoryCache, animalService);

            cartService.SetAnimalQuantity("TEST_CART", existingAnimalOneId, existingAnimalOneQuantityAmount);
            cartService.SetAnimalQuantity("TEST_CART", existingAnimalTwoId, existingAnimalTwoQuantityAmount);

            // Act
            var updatedCart = cartService.SetAnimalQuantity("TEST_CART", animalIdToRemove, animalQuantityToRemove);

            // Assert
            Assert.Equal("TEST_CART", updatedCart.Id);
            Assert.Equal(0, updatedCart.CartContents.First(x => x.Id == animalIdToRemove).Quantity);
            Assert.Equal(0, updatedCart.CartContents.First(x => x.Id == existingAnimalTwoId).Quantity);
            Assert.Equal(1, updatedCart.CartContents.First(x => x.Id == existingAnimalOneId).Quantity);
        }
Example #18
0
        public async Task ByIdAsyncShouldReturnAnimalById()
        {
            var db = DbInfrastructure.GetDatabase();

            const string Name = "Animal Name";

            await db.AddAsync(new Animal
            {
                Name = Name
            });

            for (var i = 0; i < 50; i++)
            {
                await db.AddAsync(new Animal
                {
                    Name = $"Name {i}"
                });
            }

            await db.SaveChangesAsync();

            var animalService = new AnimalService(db);

            const int Id = 1;

            var animal = await animalService.ByIdAsync(Id);

            animal.Should().NotBeNull();

            animal.Name.Should().Be(Name);
        }
Example #19
0
        // GET: Details
        public ActionResult Details(int id)
        {
            var service = new AnimalService();
            var model   = service.GetAnimalByID(id);

            return(View(model));
        }
Example #20
0
        // GET: Animal
        public ActionResult Index()
        {
            var service = new AnimalService();
            var model   = service.GetAnimals();

            return(View(model));
        }
Example #21
0
        public async Task <IEnumerable <Animal> > GetAllAnimalsAsync(string token)
        {
            var animalRepository = new AnimalRepository(serializerService, token);
            var animalService    = new AnimalService(animalRepository);

            return(await animalService.GetAllAnimalsAsync());
        }
Example #22
0
        public void should_return_null_if_no_tags_is_supplied()
        {
            var mockEnv = new MockHostingEnvironment();

            var x = new AnimalService(mockEnv);

            var creatues = new List <Creature>
            {
                new Creature
                {
                    ImagePath    = "book.jpg",
                    CreatureTags = new List <CreatureTags>
                    {
                        new CreatureTags
                        {
                            Tag = new Tag
                            {
                                Name = "book"
                            }
                        }
                    }
                }
            };

            string matchingAnimal = x.GetAnimalUrlThatMatchesTags(new string[] { }, creatues);

            Assert.AreEqual(null, matchingAnimal);
        }
Example #23
0
        public AnimalServiceTest()
        {
            var logger = new Mock <ILogger <AnimalService> >();

            databaseServiceMock = new Mock <IDatabaseService>();
            userServiceMock     = new Mock <IUserService>();
            underTest           = new AnimalService(databaseServiceMock.Object, userServiceMock.Object, logger.Object);
        }
Example #24
0
        public ActionResult <Animal> Post([FromBody] Animal animal)
        {
            var service = new AnimalService();

            service.Store(animal);

            return(animal);
        }
Example #25
0
 public TelaAdocao()
 {
     InitializeComponent();
     ConfigurarCombobox();
     adoptionService = new AdoptionService();
     animalService   = new AnimalService();
     adopterService  = new AdopterService();
 }
Example #26
0
        public ActionResult <IEnumerable <Animal> > Get()
        {
            var service = new AnimalService();

            var animals = service.GetAll();

            return(Ok(animals));
        }
        public void AddNewAnimalTest()
        {
            AnimalService service = new AnimalService();

            animal.Setup(t => t.CreateNewAnimal(dataSet.getAnimalDataSet())).Returns(dataSet.getAnimalDataSet());
            AnimalResponse response = service.AddAnimal(dataSet.getAnimalDataSet());

            Assert.AreEqual("1", response.animal.animalId);
        }
        public void GetAllAnimalsTest()
        {
            AnimalService service = new AnimalService();

            animal.Setup(t => t.RetrieveAllAnimals()).Returns(dataSet.getAnimalListDataSet());
            AnimalResponse response = service.GetAllAnimals();

            Assert.IsTrue(response.animalList.Count > 0);
        }
        public void UpdateAnimalTest()
        {
            AnimalService service = new AnimalService();

            animal.Setup(t => t.UpdateAnimal(dataSet.getAnimalDataSet())).Returns(dataSet.getAnimalDataSet());
            AnimalResponse response = service.UpdateAnimal(dataSet.getAnimalDataSet());

            Assert.IsTrue(response.animal.animalId == 1);
        }
Example #30
0
 public AccountController(UserManager <Usuario> userManager, SignInManager <Usuario> signInManager, CidadeService cidadeService, UsuarioService usuarioService, ILogger <AccountController> logger, IEmailSender emailSender, AnimalService animalService)
 {
     UserManager     = userManager;
     SignInManager   = signInManager;
     _CidadeService  = cidadeService;
     _UsuarioService = usuarioService;
     Logger          = logger;
     _EmailSender    = emailSender;
     _AnimalService  = animalService;
 }
        public void save_animal()
        {
            var animal = new Animal
            {
                Name = "Gary",
                CommonName = CommonName.Goat
            };

            _session.Setup(m => m.Execute(It.IsAny<string>(), It.IsAny<object>())).Verifiable();

            var service = new AnimalService(_database);
            service.Save(animal);

            _session.Verify(m => m.Execute(It.IsAny<string>(), It.IsAny<object>()));
        }
        public void get_all_animals()
        {
            var entities = new List<Animal>
            {
                new Animal {Id = 1, Name = "Gertrude", CommonName = CommonName.Goat},
                new Animal {Id = 2, Name = "Leonard", CommonName = CommonName.Llama},
                new Animal {Id = 2, Name = "Duncan", CommonName = CommonName.MiniatureDonkey}
            };

            _session.Setup(m => m.Query<Animal>(It.IsAny<string>(), null)).Returns(entities);

            var service = new AnimalService(_database);
            var animals = service.GetAllAnimals();

            Assert.AreEqual(entities.Count, animals.Count());
        }