public void UpdateLodgingTestOk() { Lodging lodgingUpdated = new Lodging() { Id = lodgingModelForRequest.Id, Name = "Hotel Enjoy Conrad", Images = new List <LodgingPicture> { lodgingPicture }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, TouristSpot = touristSpotAdded }; LodgingModelForRequest lodgingModelForRequestToUpdate = new LodgingModelForRequest() { Id = lodgingModelForRequest.Id, Name = "Hotel Enjoy Conrad", Images = new List <string> { image.Path }, }; var lodgingManagementMock = new Mock <ILodgingManagement>(MockBehavior.Strict); lodgingManagementMock.Setup(m => m.UpdateLodging(It.IsAny <Guid>(), It.IsAny <Lodging>())).Returns(lodgingUpdated); LodgingController lodgingController = new LodgingController(lodgingManagementMock.Object); var result = lodgingController.Put(lodgingModelForRequestToUpdate.Id, lodgingModelForRequestToUpdate); var createdResult = result as CreatedAtRouteResult; var model = createdResult.Value as LodgingModelForResponse; lodgingManagementMock.VerifyAll(); LodgingModelForResponse lodgingModelForResponse = new LodgingModelForResponse() { Id = lodgingModelForRequest.Id, Name = "Hotel Enjoy Conrad", ImagesPath = new List <string> { image.Path }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, LodgingTouristSpotModel = TouristSpotModelForLodgingResponseModel.ToModel(touristSpotAdded), }; Assert.AreEqual(lodgingModelForResponse, model); }
public IActionResult Get(Guid id) { try { Lodging lodging = lodgingManagement.GetLodgingById(id); return(Ok(LodgingModelForResponse.ToModel(lodging))); } catch (ClientBusinessLogicException e) { return(NotFound(e.Message)); } catch (ServerBusinessLogicException e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult Get() { try { List <Lodging> allLodgings = lodgingManagement.GetAllLoadings(); return(Ok(LodgingModelForResponse.ToModel(allLodgings))); } catch (ClientBusinessLogicException e) { return(NotFound(e.Message)); } catch (ServerBusinessLogicException e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult Put(Guid id, [FromBody] LodgingModelForRequest lodgingModel) { try { Lodging lodging = lodgingManagement.UpdateLodging(id, LodgingModelForRequest.ToEntity(lodgingModel)); return(CreatedAtRoute("lodging", new { id = lodging.Id }, LodgingModelForResponse.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)); } }
public void SetUp() { image = new Picture() { Id = Guid.NewGuid(), Path = "c:/MiDirectorio/Imagenes/Paisaje.png" }; lodgingPicture = new LodgingPicture() { Picture = image, PictureId = image.Id }; lodgingTouristSpotModel = new TouristSpotModelForLodgingResponseModel() { Id = Guid.NewGuid(), Name = "Punta del Este", }; reviewModelForResponse = new ReviewModelForResponse() { Description = "Muy buena", Id = Guid.NewGuid(), LastNameOfWhoComments = "Her", NameOfWhoComments = "Agustin", Score = 3 }; lodgingModelForSearchResponse = new LodgingModelForResponse() { Id = Guid.NewGuid(), Name = "Hotel las cumbres", ImagesPath = new List <string> { image.Path }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, LodgingTouristSpotModel = lodgingTouristSpotModel, ReviewsAverageScore = 4.3, ReviewsForLodging = new List <ReviewModelForResponse>() { reviewModelForResponse } }; review = new Review() { Description = "Muy buena", Id = Guid.NewGuid(), LastNameOfWhoComments = "Her", NameOfWhoComments = "Agustin", Score = 3 }; lodgingModelForResponse = new LodgingModelForResponse() { Id = Guid.NewGuid(), Name = "Hotel las cumbres", ImagesPath = new List <string> { image.Path }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, LodgingTouristSpotModel = lodgingTouristSpotModel, ReviewsAverageScore = 4.3, ReviewsForLodging = new List <ReviewModelForResponse> { reviewModelForResponse } }; lodgingModelForRequest = new LodgingModelForRequest() { Id = Guid.NewGuid(), Name = "Hotel las cumbres", Images = new List <string> { image.Path }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, TouristSpotId = lodgingTouristSpotModel.Id }; regionForTouristSpot = new Region() { Id = Guid.NewGuid(), Name = Region.RegionName.Región_Centro_Sur, }; category = new Category() { Id = Guid.NewGuid(), Name = "Playa" }; touristSpotAdded = new TouristSpot() { Id = Guid.NewGuid(), Name = "Punta del Este", Image = image, Description = "Un lugar increible", Region = regionForTouristSpot, ListOfCategories = new List <CategoryTouristSpot>() { new CategoryTouristSpot() { Category = category } } }; lodgingOfficial = new Lodging() { Id = lodgingModelForRequest.Id, Name = "Hotel las cumbres", Images = new List <LodgingPicture>() { lodgingPicture }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, TouristSpot = touristSpotAdded }; lodgingForGet = new Lodging() { Id = lodgingModelForSearchResponse.Id, Name = "Hotel las cumbres", Images = new List <LodgingPicture>() { lodgingPicture }, Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 150, TouristSpot = touristSpotAdded, ReviewsAverageScore = 4.3, Reviews = new List <Review> { review } }; }