public void TestInitialize() { Category = new Category() { Id = 1, Name = "Category1" }; var fileMock = new Mock <IFormFile>(); TouristSpotModel = new TouristSpotModel() { Name = "name", Description = "description", Image = fileMock.Object, Categories = new List <int> { Category.Id }, RegionId = 1 }; TouristSpotSearchModel = new TouristSpotSearchModel() { Region = 1, Categories = new[] { Category.Id } }; TouristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); }
public void SearchTouristSpotsReturnsTouristSpots() { var touristSpotSearchModel = new TouristSpotSearchModel { Region = 1, Categories = new[] { 1 } }; RegionsMock.Setup(m => m.Get(touristSpotSearchModel.Region)).Returns(TouristSpot.Region); var touristSpots = new List <TouristSpot> { TouristSpot }; TouristSpotsMock.Setup(m => m.Search((int)touristSpotSearchModel.Region, It.IsAny <List <int> >(), touristSpotSearchModel.Page, touristSpotSearchModel.ResultsPerPage)).Returns(touristSpots); var touristSpotLogic = CreateTouristSpotLogic(); var result = touristSpotLogic.Search(touristSpotSearchModel); TouristSpotsMock.VerifyAll(); RegionsMock.VerifyAll(); Assert.IsTrue(result.SequenceEqual(touristSpots)); }
public void TestInitialize() { TouristSpotSearchModel = new TouristSpotSearchModel() { Region = 5, Categories = new[] { 3 } }; }
public IEnumerable <TouristSpot> Search(TouristSpotSearchModel touristSpotSearchModel) { var storedRegion = RegionRepository.Get(touristSpotSearchModel.Region); if (storedRegion == null) { throw new NotFoundException("Region"); } return(TouristSpotRepository.Search((int)touristSpotSearchModel.Region, touristSpotSearchModel.Categories.ToList(), touristSpotSearchModel.Page, touristSpotSearchModel.ResultsPerPage)); }
public void SearchTouristSpotThrowsExceptionIfRegionIsNull() { TouristSpot.Region = null; RegionsMock.Setup(m => m.Get(1)).Returns(TouristSpot.Region); var touristSpotLogic = CreateTouristSpotLogic(); var touristSpotSearchModel = new TouristSpotSearchModel { Region = 1, Categories = new[] { 1 } }; touristSpotLogic.Search(touristSpotSearchModel); }
public IActionResult Get([FromQuery] TouristSpotSearchModel touristSpotSearchModel) { IActionResult result; if (touristSpotSearchModel.HasErrors()) { result = BadRequest(new ErrorModel(touristSpotSearchModel.Errors())); } else { result = Ok(TouristSpotLogic.Search(touristSpotSearchModel) .Select(x => new TouristSpotBasicInfoModel(x)).ToList()); } return(result); }