public async Task GetPublishedContentOfTreePicker_should_return_descendant_content() { RawContentResponse cacheOut = MockRawContentResponse1; var mockHttpResponse = new { origin = It.IsAny <int>(), descendants = new[] { MockRawContentResponse1.Id }, publishedOnly = true, descendantCount = 1 }; mockHttpMessageHandler .When("*") .Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(mockHttpResponse)); mockCache.Object.Add(MockRawContentResponse1.Id.ToString(), MockRawContentResponse1); mockCache.Setup(c => c.TryGet(It.IsAny <string>(), out cacheOut)).Returns(true); var request = GetNewRequest(); IDictionary <string, RawContentResponse> response = await request.GetPublishedContentOfTreePickerAsync(It.IsAny <int>(), It.IsAny <string>()); response.ShouldNotBeNull(); response.Count.ShouldBe(1); response.ShouldContainKey("Content response 1"); response["Content response 1"].ShouldBeOfType <RawContentResponse>(); }
public void referencing_RenderedContentHtmlString_with_empty_RenderedContent_should_return_an_empty_HtmlString() { var contentResponse = new RawContentResponse { RenderedContent = string.Empty }; contentResponse.RenderedContentHtmlString.ShouldNotBeNull(); contentResponse.RenderedContentHtmlString.ShouldBeAssignableTo <HtmlString>(); contentResponse.RenderedContentHtmlString.ToHtmlString().ShouldBe(new HtmlString(string.Empty).ToHtmlString()); }
public void requests_look_in_the_cache_first() { // arrange RawContentResponse cacheOut = new RawContentResponse { Name = "Content name", RenderedContent = "<p>some content html</p>" }; int contentId = It.IsAny <int>(); var req = GetNewRequest(); mockCache.Setup(c => c.TryGet(It.IsAny <string>(), out cacheOut)).Returns(true).Verifiable(); // act var htmlString = req.GetPublishedContent(contentId); // assert mockCache.Verify(c => c.TryGet(It.IsAny <string>(), out cacheOut), Times.Once); mockHttpMessageHandler.VerifyNoOutstandingRequest(); htmlString.ShouldNotBeNull(); htmlString.ToString().ShouldBe(cacheOut.RenderedContent); }
public void if_the_request_isnt_cached_it_will_go_to_the_server() { // arrange RawContentResponse cacheOut = new RawContentResponse { RenderedContent = "<p>some content html</p>" }; string goalContent = "<p>some content html</p>"; object response = new { renderedContent = HttpUtility.HtmlEncode(goalContent) }; int contentId = It.IsAny <int>(); var req = GetNewRequest(); mockCache.Setup(c => c.TryGet(It.IsAny <string>(), out cacheOut)).Returns(false); mockHttpMessageHandler .When("*") .Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(response)); // act var htmlString = req.GetContentRegardlessOfPublishedStatus(contentId); // assert htmlString.ShouldNotBeNull(); htmlString.ToString().ShouldBe(goalContent); }