public void CreateLodgingTestOk()
        {
            var lodgingManagementMock = new Mock <ILodgingManagement>(MockBehavior.Strict);

            lodgingManagementMock.Setup(m => m.Create(It.IsAny <Lodging>(), It.IsAny <Guid>(), It.IsAny <List <string> >())).Returns(lodgingOfficial);
            LodgingController lodgingController = new LodgingController(lodgingManagementMock.Object);
            var result        = lodgingController.Post(lodgingModelForRequest);
            var createdResult = result as CreatedAtRouteResult;
            var model         = createdResult.Value as LodgingModelForSearchResponse;

            lodgingManagementMock.VerifyAll();
            Assert.AreEqual(LodgingModelForSearchResponse.ToModel(lodgingOfficial), model);
        }
Exemplo n.º 2
0
 public IActionResult Post([FromBody] LodgingModelForRequest lodgingModel)
 {
     try
     {
         Lodging lodging = lodgingManagement.Create(LodgingModelForRequest.ToEntity(lodgingModel), lodgingModel.TouristSpotId, lodgingModel.Images);
         return(CreatedAtRoute("lodging", new { id = lodging.Id }, LodgingModelForSearchResponse.ToModel(lodging)));
     }
     catch (DomainBusinessLogicException e)
     {
         return(BadRequest(e.Message));
     }
     catch (ClientBusinessLogicException e)
     {
         return(NotFound(e.Message));
     }
     catch (ServerBusinessLogicException e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }
Exemplo n.º 3
0
        public IEnumerable <LodgingForSearchModel> ToModel(IEnumerable <Lodging> entities)
        {
            List <Lodging> entitiesInList         = entities.ToList();
            List <LodgingForSearchModel> toReturn = new List <LodgingForSearchModel>();

            foreach (Lodging entity in entitiesInList)
            {
                int totalDays = (CheckOut - CheckIn).Days;
                LodgingForSearchModel lodging = new LodgingForSearchModel()
                {
                    CheckIn             = CheckIn,
                    CheckOut            = CheckOut,
                    QuantityOfGuest     = QuantityOfGuest,
                    Lodging             = LodgingModelForSearchResponse.ToModel(entity),
                    TotalPriceForSearch = entity.CalculateTotalPrice(totalDays, QuantityOfGuest)
                };
                toReturn.Add(lodging);
            }
            toReturn.AsEnumerable();
            return(toReturn);
        }
        public void SearchLodgingsTestOk()
        {
            List <Lodging> listOfLodgingsAvailables = new List <Lodging>()
            {
                lodgingOfCumbres, lodgingOfConrad
            };
            var lodgingManagementMock = new Mock <ILodgingManagement>(MockBehavior.Strict);

            lodgingManagementMock.Setup(m => m.GetAvailableLodgingsByTouristSpot(It.IsAny <Guid>())).Returns(listOfLodgingsAvailables);
            SearchOfLodgingController searchOfLodgingController = new SearchOfLodgingController(lodgingManagementMock.Object);
            var result        = searchOfLodgingController.Post(searchOfLodgingModel);
            var createdResult = result as OkObjectResult;
            var model         = createdResult.Value as List <LodgingForSearchModel>;

            lodgingManagementMock.VerifyAll();
            List <LodgingForSearchModel> listOfModelOfSearch = new List <LodgingForSearchModel>();

            LodgingForSearchModel lodgingModelOfCumbres = new LodgingForSearchModel()
            {
                CheckIn             = searchOfLodgingModel.CheckIn,
                CheckOut            = searchOfLodgingModel.CheckOut,
                Lodging             = LodgingModelForSearchResponse.ToModel(lodgingOfCumbres),
                TotalPriceForSearch = 700.0
            };

            LodgingForSearchModel lodgingModelOfEnjoyConrad = new LodgingForSearchModel()
            {
                CheckIn             = searchOfLodgingModel.CheckIn,
                CheckOut            = searchOfLodgingModel.CheckOut,
                Lodging             = LodgingModelForSearchResponse.ToModel(lodgingOfConrad),
                TotalPriceForSearch = 350.0
            };

            listOfModelOfSearch.Add(lodgingModelOfCumbres);
            listOfModelOfSearch.Add(lodgingModelOfEnjoyConrad);
            CollectionAssert.AreEqual(listOfModelOfSearch, model);
        }