public void OnGetSingleTest() { var singleRequest = new AdventureReview { Id = "legit id" }; var reviewList = new List<AdventureReview> { singleRequest }; var expectedSingleReviewResponse = new AdventureReviewGetResponse(singleRequest) { AdventureReviews = reviewList }; var mock = new Mock<IAdventureReviewRepository>(); mock.Setup(a => a.GetAdventureReviewById(singleRequest.Id)).Returns(singleRequest); mock.Setup(a => a.GetAdventureReviews()).Returns(reviewList); var target = new AdventureReviewService { AdventureReviewRepository = mock.Object }; var actual = target.OnGet(singleRequest) as AdventureReviewGetResponse; Assert.AreEqual(expectedSingleReviewResponse, actual); }
public void OnGetSingleDataCardTest() { const string adventureid = "adventureId"; var adventureReview = new AdventureReview { Id = adventureid }; var getSingleDataCardRequest = new AdventureDataCard { Id = "dataCardId" }; var singleDataCard = new AdventureDataCard { Id = "dataCardId", AdventureReview = adventureReview }; var singleDataCardList = new List<AdventureDataCard> { getSingleDataCardRequest }; var expectedSingleDataCardResponse = new AdventureDataCardGetResponse(getSingleDataCardRequest) {DataCards = singleDataCardList}; var mock = new Mock<IAdventureDataCardRepository>(); mock.Setup(a => a.GetAdventureDataCardById(getSingleDataCardRequest.Id)).Returns(singleDataCard); var target = new AdventureDataCardService { AdventureDataCardRepository = mock.Object }; var actual = target.OnGet(getSingleDataCardRequest) as AdventureDataCardGetResponse; Assert.AreEqual(expectedSingleDataCardResponse, actual); }
public void OnGetReviewDataCardsTest() { const string adventureid = "adventureId"; var adventureReview = new AdventureReview { Id = adventureid }; var getReviewDataCardsRequest = new AdventureDataCard { AdventureReview = adventureReview }; var reviewDataCardList = new List<AdventureDataCard> { new AdventureDataCard {Id = "dataCardOne", AdventureReview = adventureReview}, new AdventureDataCard {Id = "dataCardTwo", AdventureReview = adventureReview}, new AdventureDataCard {Id = "dataCardThree", AdventureReview = adventureReview} }; var expectedReviewDataCardsResponse = new AdventureDataCardGetResponse(getReviewDataCardsRequest) { DataCards = reviewDataCardList }; var mock = new Mock<IAdventureDataCardRepository>(); mock.Setup(a => a.GetAdventureDataCardsByReviewId(getReviewDataCardsRequest.AdventureReview.Id)).Returns( reviewDataCardList); var target = new AdventureDataCardService { AdventureDataCardRepository = mock.Object }; var actual = target.OnGet(getReviewDataCardsRequest) as AdventureDataCardGetResponse; Assert.AreEqual(expectedReviewDataCardsResponse, actual); }
public bool Validate(AdventureReview item, IList<ValidationResult> validationErrorResults) { if (null == validationErrorResults) validationErrorResults = new List<ValidationResult>(); if (null == item) validationErrorResults.Add(new ValidationResult("A non-null object is required.", new[] { "AdventureReview" })); else { if (string.IsNullOrEmpty(item.AdventureName)) validationErrorResults.Add(new ValidationResult("A Name is required", new[] { "AdventureReviewName" })); if (null == item.AdventureType || string.IsNullOrEmpty(item.AdventureType.Id)) validationErrorResults.Add(new ValidationResult("A Adventure Type is required", new[] { "AdventureReviewAdventureType" })); using (var locationBusiness = new LocationBusiness()) { if (null == item.AdventureLocation) validationErrorResults.Add(new ValidationResult("A Location is required", new[] { "AdventureReviewLocation" })); else if (!locationBusiness.Validate(item.AdventureLocation, validationErrorResults)) { validationErrorResults.Add(new ValidationResult("A Valid Location is required", new[] { "AdventureReviewLocation" })); } } if (null == item.AdventureDuration || item.AdventureDuration <= new TimeSpan()) validationErrorResults.Add(new ValidationResult("A Duration Time span is required", new[] { "AdventureReviewDuriation" })); if (null == item.AdventureDate) { validationErrorResults.Add(new ValidationResult("A Adventure Date is required", new[] { "AdventureReviewAdventureDate" })); } } return validationErrorResults.Count == 0; }
public ActionResult Edit(AdventureReview adventurereview) { if (ModelState.IsValid) { return RedirectToAction("Index"); } return View(adventurereview); }
public AdventureReview SaveAdventureReview(AdventureReview adventureReview) { var saveAdventureReview = _client.Post<AdventureReview>("/Adventure/Reviews/", adventureReview); return saveAdventureReview; }
public void OnPostNewTest() { var adventureReview = new AdventureReview { Id = "adventureId", AdventureName = "Adventure" }; var newDataCardRequest = new AdventureDataCard { AdventureReview = adventureReview, Title = "title", Body = "body" }; var savedNewDataCard = new AdventureDataCard { Id = "savedId", AdventureReview = adventureReview, Title = "title", Body = "body" }; var expectedNewDataCardResponse = new AdventureDataCardSaveResponse(newDataCardRequest) { DataCard = savedNewDataCard }; var mock = new Mock<IAdventureDataCardRepository>(); mock.Setup(a => a.SaveAdventureDataCard(newDataCardRequest)).Returns(savedNewDataCard); var target = new AdventureDataCardService { AdventureDataCardRepository = mock.Object }; var actual = target.OnPost(newDataCardRequest) as AdventureDataCardSaveResponse; Assert.AreEqual(expectedNewDataCardResponse, actual); }
public AdventureReview SaveAdventureReview(AdventureReview adventureReview) { return string.IsNullOrEmpty(adventureReview.Id) ? AdventureReviewRepository.Add(adventureReview) : // Add new one & AdventureReviewRepository.Update(adventureReview); // update existing one }
public AdventureReview SaveAdventureReview(AdventureReview adventureReview) { var response = Client.Post<AdventureReviewSaveResponse>("/Adventure/Reviews/", adventureReview); return response.AdventureReview; }
public void OnPostNewTest() { const string adventurename = "AdventureName"; var adventureDate = DateTime.Now; var adventureDuration = new TimeSpan(0, 0, 1); var adventureType = new AdventureType { Id = "typeId", Name = "AdventureType" }; var adventureLocation = new AdventureLocation(new GeoPoint { Lat = 0, Lon = 0 }, "AdventureLocation"); var newReviewRequest = new AdventureReview { AdventureName = adventurename, AdventureDate = adventureDate, AdventureDuration = adventureDuration, AdventureType = adventureType, AdventureLocation = adventureLocation }; var newReviewRequestOutput = new AdventureReview { Id = "newId", AdventureName = adventurename, AdventureDate = adventureDate, AdventureDuration = adventureDuration, AdventureType = adventureType, AdventureLocation = adventureLocation }; var expectedNewReviewResponse = new AdventureReviewSaveResponse(newReviewRequest) { AdventureReview = newReviewRequestOutput }; var mock = new Mock<IAdventureReviewRepository>(); mock.Setup(a => a.SaveAdventureReview(newReviewRequest)).Returns(expectedNewReviewResponse.AdventureReview); var target = new AdventureReviewService { AdventureReviewRepository = mock.Object }; // new review var actual = target.OnPost(newReviewRequest) as AdventureReviewSaveResponse; Assert.AreEqual(expectedNewReviewResponse, actual); }