public void TestPostTouristSpotReturnsValidModel() { var touristSpot = TouristSpotModel.ToEntity(); touristSpot.Region = new Region { Id = touristSpot.RegionId.Value }; touristSpot.TouristSpotCategories = new List <TouristSpotCategory>() { new TouristSpotCategory() { CategoryId = Category.Id, Category = Category, TouristSpot = touristSpot, TouristSpotId = touristSpot.Id } }; var touristSpotLogicMock = new Mock <ITouristSpotLogic>(MockBehavior.Strict); touristSpotLogicMock.Setup(m => m.Create(TouristSpotModel.ToEntity())).Returns(touristSpot); var touristSpotController = new TouristSpotController(touristSpotLogicMock.Object); var result = touristSpotController.Post(TouristSpotModel) as CreatedResult; var content = result.Value as TouristSpotBasicInfoModel; touristSpotLogicMock.VerifyAll(); Assert.IsTrue(content.Equals(new TouristSpotBasicInfoModel(touristSpot))); }
public IActionResult Post([FromForm] TouristSpotModel touristSpotModel) { IActionResult result; if (touristSpotModel.HasErrors()) { result = BadRequest(new ErrorModel(touristSpotModel.Errors())); } else { var touristSpot = TouristSpotLogic.Create(touristSpotModel.ToEntity()); result = Created("GetTouristSpot", new TouristSpotBasicInfoModel(touristSpot)); } return(result); }
public void ToEntityCreatesTouristSpotWithSameName() { var touristSpot = TouristSpotModel.ToEntity(); Assert.AreEqual(TouristSpotModel.Name, touristSpot.Name); }