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 bool Validate(AdventureDataCard 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[] { "AdventureDataCard" })); } else { if (string.IsNullOrEmpty(item.Title)) validationErrorResults.Add(new ValidationResult("A Title is required", new[] { "DataCardTitle" })); if (string.IsNullOrEmpty(item.Body)) validationErrorResults.Add(new ValidationResult("A Description is required", new[] { "DataCardBody" })); } return validationErrorResults.Count == 0; }
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 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); }