public IActionResult CreateAccommodation(AccommodationModelIn newAccommodation) { var accommodation = newAccommodation.FromModelInToAccommodation(); var response = this.accommodationLogic.AddAccommodation(accommodation); return(Ok(new AccommodationModelOut(response, (0, new List <Review>())))); }
public void ImportTest() { List <string> names = new List <string>() { "Test" }; List <TypeParameter> listParameters = new List <TypeParameter>() { new TypeParameter() { Name = "Path", Type = "string" } }; ImporterModel importerModel = new ImporterModel() { Name = "Test", Parameters = new List <ValueParameter>() { new ValueParameter() { Name = "Path", Value = "Path test" } } }; Accommodation accommodation = new Accommodation() { Name = "Accommodation name", Address = "Accommodation address", ContactNumber = "Accommodation contactNumber", Full = false, Images = new List <AccommodationImage>() { new AccommodationImage() { Image = "AccommodationImage image" } }, Information = "Accommodation information", PricePerNight = 1 }; AccommodationModelOut accommodationModelOut = new AccommodationModelOut(accommodation, (0, new List <Review>())); var mockImporter = new Mock <IImporterLogic>(MockBehavior.Strict); mockImporter.Setup(p => p.Import(It.IsAny <ImporterModel>())).Returns(accommodationModelOut); var controller = new ImportController(mockImporter.Object); controller.Post(importerModel); mockImporter.VerifyAll(); }
public IActionResult Get(int id) { Accommodation accommodation = this.accommodationLogic.GetById(id); var response = new AccommodationModelOut(accommodation, this.accommodationLogic.GetReviewsByAccommodation(id)); return(Ok(response)); }
public IActionResult Get() { var queryString = HttpUtility.ParseQueryString(this.HttpContext.Request.QueryString.Value); if (queryString.Count == 0) { List <AccommodationQueryOut> accommodations = this.accommodationLogic.GetAll(); List <AccommodationModelOut> accommodationsToReturn = new List <AccommodationModelOut>(); foreach (var item in accommodations) { AccommodationModelOut a = new AccommodationModelOut(item); accommodationsToReturn.Add(a); } return(Ok(accommodationsToReturn)); } else { try { AccommodationModelIn accommodationModelIn = new AccommodationModelIn { TouristSpotName = queryString.Get("touristSpotName"), CheckIn = new DateTime( Int32.Parse(queryString.Get("checkInYear")), Int32.Parse(queryString.Get("checkInMonth")), Int32.Parse(queryString.Get("checkInDay")) ), CheckOut = new DateTime( Int32.Parse(queryString.Get("checkOutYear")), Int32.Parse(queryString.Get("checkOutMonth")), Int32.Parse(queryString.Get("checkOutDay")) ), TotalGuests = Int32.Parse(queryString.Get("totalGuests")), Babies = Int32.Parse(queryString.Get("babies")), Kids = Int32.Parse(queryString.Get("kids")), Adults = Int32.Parse(queryString.Get("adults")), Retirees = Int32.Parse(queryString.Get("retirees")) }; int tot = accommodationModelIn.Babies + accommodationModelIn.Kids + accommodationModelIn.Adults + accommodationModelIn.Retirees; if (accommodationModelIn.TotalGuests != tot) { return(BadRequest("Wrong input: the number of hosts is incorrect.")); } AccommodationQueryIn accommodationQueryIn = new AccommodationQueryIn(accommodationModelIn); List <AccommodationQueryOut> accommodations = this.accommodationLogic.GetByTouristSpot(accommodationQueryIn); List <AccommodationModelOut> accommodationsToReturn = new List <AccommodationModelOut>(); foreach (var item in accommodations) { AccommodationModelOut a = new AccommodationModelOut(item); accommodationsToReturn.Add(a); } return(Ok(accommodationsToReturn)); } catch (Exception e) { return(BadRequest("Wrong input: incorrect query string")); } } }
public void ImportTestWithNewTouristicSpot() { ImporterModel importerModel = new ImporterModel() { Name = "Test", Parameters = new List <ValueParameter>() { new ValueParameter() { Name = "Path", Value = "Path test" } } }; Region region = new Region() { Id = 1, Name = "Region name" }; Category category = new Category() { Id = 1, Name = "Category name" }; TouristicSpot touristicSpot = new TouristicSpot() { Name = "TouristicSpot name", Description = "TouristicSpot description", Image = "TouristicSpot image", RegionId = 1, Categories = new List <CategoryTouristicSpot>() { new CategoryTouristicSpot() { CategoryId = 1 } } }; Accommodation accommodation = new Accommodation() { Name = "Accommodation name", Address = "Accommodation address", ContactNumber = "Accommodation contactNumber", Full = false, Images = new List <AccommodationImage>() { new AccommodationImage() { Image = "AccommodationImage image" } }, Information = "Accommodation information", PricePerNight = 1 }; AccommodationModelOut accommodationModelOut = new AccommodationModelOut(accommodation, (0, new List <Review>())); var mockAccommodation = new Mock <IAccommodationRepository>(MockBehavior.Strict); mockAccommodation.Setup(p => p.GetByName(It.IsAny <string>())).Returns <Accommodation>(null); mockAccommodation.Setup(p => p.AddAndSave(It.IsAny <Accommodation>())).Returns(accommodation); var mockTouristicSpot = new Mock <ITouristicSpotRepository>(MockBehavior.Strict); mockTouristicSpot.SetupSequence(p => p.GetByName(It.IsAny <string>())).Returns((TouristicSpot)null).Returns(touristicSpot); mockTouristicSpot.Setup(p => p.AddAndSave(It.IsAny <TouristicSpot>())).Returns(touristicSpot); var mockRegion = new Mock <IRepository <Region> >(MockBehavior.Strict); mockRegion.Setup(p => p.GetById(It.IsAny <int>())).Returns(region); var mockCategory = new Mock <IRepository <Category> >(MockBehavior.Strict); mockCategory.Setup(p => p.GetById(It.IsAny <int>())).Returns(category); var logic = new ImporterLogic(mockAccommodation.Object, mockTouristicSpot.Object, mockRegion.Object, mockCategory.Object); var result = logic.Import(importerModel); mockAccommodation.VerifyAll(); mockCategory.VerifyAll(); mockTouristicSpot.VerifyAll(); mockRegion.VerifyAll(); Assert.AreEqual(accommodationModelOut, result); }
public AccommodationModelOut Import(ImporterModel import) { var implementation = ObtainImplementation(import.Name); var parse = new AccommodationParse(); try { parse = implementation.Import(import.Parameters); } catch { throw new ImportParseException(); } CheckTouristicSpot(parse.TouristicSpot); CheckRegion(parse.TouristicSpot.RegionId); CheckCategories(parse.TouristicSpot.Categories); CheckAccommodation(parse.Name); var touristicSpot = touristicSpotRepository.GetByName(parse.TouristicSpot.Name); if (touristicSpot == null) { List <CategoryTouristicSpot> categoryTouristicSpots = new List <CategoryTouristicSpot>(); foreach (int category in parse.TouristicSpot.Categories) { categoryTouristicSpots.Add(new CategoryTouristicSpot() { CategoryId = category }); } touristicSpot = new TouristicSpot() { Categories = categoryTouristicSpots, Description = parse.TouristicSpot.Description, Image = parse.TouristicSpot.Image, Name = parse.TouristicSpot.Name, RegionId = parse.TouristicSpot.RegionId }; touristicSpotRepository.AddAndSave(touristicSpot); touristicSpot = touristicSpotRepository.GetByName(parse.TouristicSpot.Name); } List <AccommodationImage> accommodationImages = new List <AccommodationImage>(); foreach (AccommodationImageParse accommodationImage in parse.Images) { accommodationImages.Add(new AccommodationImage() { Image = accommodationImage.Image }); } Accommodation accommodation = this.accommodationRepository.AddAndSave(new Accommodation() { Address = parse.Address, ContactNumber = parse.ContactNumber, Full = parse.Full, Information = parse.Information, Name = parse.Name, PricePerNight = parse.PricePerNight, Images = accommodationImages, Spot = touristicSpot }); return(new AccommodationModelOut(accommodation, (0, new List <Review>()))); }