Esempio n. 1
0
        public void CreateReserveTestOk()
        {
            var reserveManagementMock = new Mock <IReserveManagement>(MockBehavior.Strict);

            reserveManagementMock.Setup(m => m.Create(It.IsAny <Reserve>(), It.IsAny <Guid>())).Returns(reserveOfLodging);
            ReserveController reserveController = new ReserveController(reserveManagementMock.Object);

            ReserveModelForRequest reserveModelForRequest = new ReserveModelForRequest()
            {
                Name                 = "Joaquin",
                LastName             = "Lamela",
                Email                = "*****@*****.**",
                CheckIn              = new DateTime(2020, 10, 05),
                CheckOut             = new DateTime(2020, 10, 07),
                QuantityOfAdult      = 1,
                QuantityOfBaby       = 1,
                QuantityOfChild      = 1,
                QuantityOfRetired    = 2,
                IdOfLodgingToReserve = lodgingForReserve.Id
            };

            var result        = reserveController.Post(reserveModelForRequest);
            var createdResult = result as CreatedAtRouteResult;
            var model         = createdResult.Value as ReserveModelForResponse;

            reserveManagementMock.VerifyAll();

            Assert.AreEqual(ReserveModelForResponse.ToModel(reserveOfLodging), model);
        }
Esempio n. 2
0
        public void GetExistingReserveByIdOkTest()
        {
            var reserveManagementMock = new Mock <IReserveManagement>(MockBehavior.Strict);

            reserveManagementMock.Setup(m => m.GetById(It.IsAny <Guid>())).Returns(reserveOfLodging);
            ReserveController reserveController = new ReserveController(reserveManagementMock.Object);

            var result        = reserveController.Get(reserveOfLodging.Id);
            var createdResult = result as OkObjectResult;
            var model         = createdResult.Value as ReserveModelForResponse;

            reserveManagementMock.VerifyAll();
            Assert.AreEqual(ReserveModelForResponse.ToModel(reserveOfLodging), model);
        }
 public IActionResult Get(Guid id)
 {
     try
     {
         Reserve reserve = reserveManagement.GetById(id);
         return(Ok(ReserveModelForResponse.ToModel(reserve)));
     }
     catch (ClientBusinessLogicException e)
     {
         return(NotFound(e.Message));
     }
     catch (ServerBusinessLogicException e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
 public IActionResult Put(Guid idForUpdateReserve, [FromBody] ReserveModelForRequestUpdate aReserveModelForUpdate)
 {
     try
     {
         Reserve reserve = reserveManagement.Update(idForUpdateReserve, ReserveModelForRequestUpdate.ToEntity(aReserveModelForUpdate));
         return(CreatedAtRoute("reserve", new { id = reserve.Id }, ReserveModelForResponse.ToModel(reserve)));
     }
     catch (DomainBusinessLogicException e)
     {
         return(BadRequest(e.Message));
     }
     catch (ClientBusinessLogicException e)
     {
         return(NotFound(e.Message));
     }
     catch (ServerBusinessLogicException e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
 public IActionResult Post([FromBody] ReserveModelForRequest aReserveModel)
 {
     try
     {
         Reserve reserve = reserveManagement.Create(ReserveModelForRequest.ToEntity(aReserveModel), aReserveModel.IdOfLodgingToReserve);
         return(CreatedAtRoute("reserve", new { id = reserve.Id }, ReserveModelForResponse.ToModel(reserve)));
     }
     catch (DomainBusinessLogicException e)
     {
         return(BadRequest(e.Message));
     }
     catch (ClientBusinessLogicException e)
     {
         return(NotFound(e.Message));
     }
     catch (ServerBusinessLogicException e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
Esempio n. 6
0
        public void UpdateReserveTestOk()
        {
            var reserveManagementMock = new Mock <IReserveManagement>(MockBehavior.Strict);

            reserveManagementMock.Setup(m => m.Update(It.IsAny <Guid>(), It.IsAny <Reserve>())).Returns(reserveOfLodging);
            ReserveController reserveController = new ReserveController(reserveManagementMock.Object);

            ReserveModelForRequestUpdate reserveModelForRequestUpdate = new ReserveModelForRequestUpdate()
            {
                Id             = reserveOfLodging.Id,
                Description    = "Su reserva ha sido aceptada correctamente, por favor verifique el nuevo estado",
                StateOfReserve = Reserve.ReserveState.Aceptada
            };

            var result        = reserveController.Put(reserveOfLodging.Id, reserveModelForRequestUpdate);
            var createdResult = result as CreatedAtRouteResult;
            var model         = createdResult.Value as ReserveModelForResponse;

            reserveManagementMock.VerifyAll();

            Reserve reserveToCompare = new Reserve()
            {
                Id                   = reserveOfLodging.Id,
                Name                 = "Joaquin",
                LastName             = "Lamela",
                Email                = "*****@*****.**",
                DescriptionForGuest  = "Su reserva ha sido aceptada correctamente, por favor verifique el nuevo estado",
                PhoneNumberOfContact = 29082733,
                CheckIn              = new DateTime(2020, 10, 05),
                CheckOut             = new DateTime(2020, 10, 07),
                QuantityOfAdult      = 1,
                QuantityOfBaby       = 1,
                QuantityOfChild      = 1,
                QuantityOfRetired    = 2,
                LodgingOfReserve     = lodgingForReserve,
                StateOfReserve       = Reserve.ReserveState.Aceptada,
                TotalPrice           = 660
            };

            Assert.AreEqual(ReserveModelForResponse.ToModel(reserveToCompare), model);
        }