예제 #1
0
        public IHttpActionResult PostClientPets(int clientId, PetBundle petToAdd)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                ClientService.AddClientPet(clientId, petToAdd);
                JsonMessager message = new JsonMessager("Mascota agregada con exito.");
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, message)));
            }
            catch (InsufficientDataException ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
            }
            catch (UserNotFoundException ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
            }
            catch (WrongDataTypeException ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
            }
            catch (PetAlreadyAddedException ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
            }
        }
예제 #2
0
 public void validateHasAllFields(PetBundle petData)
 {
     if (petData.Name == null)
     {
         throw new InsufficientDataException("Debe proporcionar un nombre para su mascota.");
     }
 }
예제 #3
0
        public void ValidateAddClientPet_3()
        {
            IClientService service = new ClientService(new UnitOfWork());

            ClientDTO clientToAdd = new ClientDTO();

            clientToAdd.Email            = "*****@*****.**";
            clientToAdd.Password         = "******";
            clientToAdd.RepeatedPassword = "******";

            int newClientId = service.RegisterNewClient(clientToAdd);

            PetBundle petData = new PetBundle();

            petData.Name           = "Rulito";
            petData.Age            = 10;
            petData.Gender         = "Masculino";
            petData.HasVaccination = true;
            petData.Weight         = 50;
            petData.PetType        = "Perro";
            petData.Information    = "Perro bueno";
            petData.FriendlyPet    = true;

            service.AddClientPet(newClientId, petData);

            try
            {
                service.AddClientPet(newClientId, petData);
            }
            catch (Exception)
            {
                Assert.Fail();
            }
            service.DeleteClient(newClientId);
        }
예제 #4
0
 public IHttpActionResult PutClientPet(int clientId, int petId, PetBundle newPetInfo)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         ClientService.UpdatePetInfo(clientId, petId, newPetInfo);
         JsonMessager message = new JsonMessager("Mascota actualizada correctamente.");
         return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, message)));
     }
     catch (UserNotFoundException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
     catch (WrongDataTypeException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
     catch (PetAlreadyAddedException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
     catch (InsufficientDataException ex)
     {
         return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)));
     }
 }
예제 #5
0
        public void validatePetNotAlreadyAdded(int clientId, PetBundle petData)
        {
            Pet pet = unitOfWork.PetRepository.Get(p => p.ClientId == clientId && p.Name == petData.Name).FirstOrDefault();

            if (pet != null)
            {
                throw new PetAlreadyAddedException("El usuario ya tiene una mascota llamada " + petData.Name);
            }
        }
예제 #6
0
        public void validateCorrectTypeFields(PetBundle petData)
        {
            bool wrongName = petData.Name.Length < 3;

            if (wrongName)
            {
                throw new WrongDataTypeException("El nombre de la mascota debe ser mayor a 3 caracteres.");
            }
        }
예제 #7
0
        public void ValidateAddClientPet_1()
        {
            IClientService service = new ClientService(new UnitOfWork());

            PetBundle petData = new PetBundle();

            petData.Name = "Rulito";
            service.AddClientPet(90, petData);
        }
예제 #8
0
        private Pet convertDTOPet(PetBundle petData)
        {
            Pet pet = new Pet(petData.Name, petData.PetType, petData.Gender, petData.Information, petData.Age, petData.Weight, petData.FriendlyPet,
                              petData.HasVaccination);

            if (petData.PetImage != null)
            {
                pet.PetImage = ImageSaver.GetIntance().getUrlOfImage(petData.PetImage, Guid.NewGuid().ToString(), "p");
            }
            return(pet);
        }
예제 #9
0
        public void AddClientPet(int clientId, PetBundle petData)
        {
            validatePetData(clientId, petData);
            Pet petToAdd = convertDTOPet(petData);

            Client clientToAddPet = unitOfWork.ClientRepository.GetByID(clientId);

            validator.validateUserExists(clientToAddPet);


            clientToAddPet.PersonalPets.Add(petToAdd);
            unitOfWork.Save();
        }
예제 #10
0
        public void UpdatePetInfo(int clientId, int petId, PetBundle newPetInfo)
        {
            if (ExistsClient(clientId))
            {
                validatePetToUpdate(clientId, newPetInfo, petId);
                Pet pet = unitOfWork.PetRepository.Get(p => p.ClientId == clientId && p.PetId == petId).FirstOrDefault();


                Pet newPet = convertDTOPet(newPetInfo);

                UpdatePet(pet, newPet, newPetInfo.PetImage);
                unitOfWork.PetRepository.Update(pet);
                unitOfWork.Save();
            }
            else
            {
                throw new UserNotFoundException("No existe el usuario");
            }
        }
예제 #11
0
        public void ValidateAddClientPet_2()
        {
            IClientService service = new ClientService(new UnitOfWork());

            PetBundle petData = new PetBundle();

            petData.Age            = 10;
            petData.Gender         = "Masculino";
            petData.HasVaccination = true;
            petData.Weight         = 50;
            petData.PetType        = "Perro";
            petData.Information    = "Perro bueno";
            petData.FriendlyPet    = true;
            try
            {
                service.AddClientPet(2, petData);
            }
            catch (InsufficientDataException ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InsufficientDataException));
            }
        }
예제 #12
0
 private void validatePetData(int clientId, PetBundle petData)
 {
     petValidator.validateHasAllFields(petData);
     petValidator.validateCorrectTypeFields(petData);
     petValidator.validatePetNotAlreadyAdded(clientId, petData);
 }
예제 #13
0
 private void validatePetToUpdate(int clientId, PetBundle pet, int petId)
 {
     petValidator.validateHasAllFields(pet);
     petValidator.validateCorrectTypeFields(pet);
     petValidator.validatePetNotAlreadyAddedWhenUpdate(clientId, pet, petId);
 }
예제 #14
0
        public void ValidateRegisterBooking_1()
        {
            IClientService  clientService  = new ClientService(new UnitOfWork());
            IWorkerService  workerService  = new WorkerService(new UnitOfWork());
            IBookingService bookingService = new BookingService(new UnitOfWork());

            ClientDTO clientToAdd = new ClientDTO();

            clientToAdd.Email            = "*****@*****.**";
            clientToAdd.Password         = "******";
            clientToAdd.RepeatedPassword = "******";

            int newClientId = clientService.RegisterNewClient(clientToAdd);

            PetBundle petData = new PetBundle();

            petData.Name           = "Rulito";
            petData.Age            = 10;
            petData.Gender         = "Masculino";
            petData.HasVaccination = true;
            petData.Weight         = 50;
            petData.PetType        = "Perro";
            petData.Information    = "Perro bueno";
            petData.FriendlyPet    = true;

            clientService.AddClientPet(newClientId, petData);

            WorkerDTO workerToAdd = new WorkerDTO();

            workerToAdd.Email            = "*****@*****.**";
            workerToAdd.Password         = "******";
            workerToAdd.RepeatedPassword = "******";
            workerToAdd.IsWalker         = true;
            workerToAdd.Disponibility    = new List <DayOfWeek>()
            {
                0
            };
            workerToAdd.Latitude  = "validLength";
            workerToAdd.Longitude = "validLength";

            int newWorkerId = workerService.RegisterNewWorker(workerToAdd);

            BookingPaymentDTO bookingToAdd = new BookingPaymentDTO();

            bookingToAdd.ClientId         = newClientId;
            bookingToAdd.WorkerId         = newWorkerId;
            bookingToAdd.StartDate        = DateTime.Now;
            bookingToAdd.FinishDate       = DateTime.Now;
            bookingToAdd.IsWalker         = true;
            bookingToAdd.CreditCardNumber = "1112222444555557";
            bookingToAdd.CCV = 222;
            bookingToAdd.CreditCardExpirationMonth = 5;
            bookingToAdd.CreditCardExpirationYear  = 2022;
            bookingToAdd.Amount = 200;

            int newBookingId = bookingService.RegisterNewBooking(bookingToAdd);

            bookingService.DeleteBooking(newBookingId);
            clientService.DeleteClient(newClientId);
            workerService.DeleteWorker(newWorkerId);

            Assert.IsInstanceOfType(newBookingId, typeof(int));
        }