public IActionResult Post([FromBody] SearchOfLodgingModelForRequest model) { try { List <Lodging> lodgingsForTouristSpotSearched = lodgingManagement.GetAvailableLodgingsByTouristSpot(model.TouristSpotIdSearch); model.VerifyFormat(); LodgingForSearchModel lodgingForSearchModel = new LodgingForSearchModel() { CheckIn = model.CheckIn, CheckOut = model.CheckOut, QuantityOfGuest = new int[4] { model.QuantityOfAdult, model.QuantityOfChilds, model.QuantityOfBabies, model.QuantityOfRetireds } }; return(Ok(lodgingForSearchModel.ToModel(lodgingsForTouristSpotSearched))); } catch (SearchException e) { return(BadRequest(e.Message)); } catch (ClientBusinessLogicException e) { return(NotFound(e.Message)); } catch (ServerBusinessLogicException e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
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); }