public async Task PagesControlerHelpersTestsGetRedirectedContentPageAsyncReturnsSuccess() { // Arrange var expectedResult = A.Dummy <ContentPageModel>(); const string location = "a-location"; const string article = "an-article"; var helper = new PagesControlerHelpers(fakeContentPageService); A.CallTo(() => fakeContentPageService.GetByRedirectLocationAsync(A <string> .Ignored)).Returns(expectedResult); // Act var result = await helper.GetRedirectedContentPageAsync(location, article).ConfigureAwait(false); // Assert A.CallTo(() => fakeContentPageService.GetByRedirectLocationAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(expectedResult, result); }
public async Task <ContentPageModel?> GetRedirectedContentPageAsync(string?location, string?article) { var redirectLocation = $"/{location}"; if (!string.IsNullOrWhiteSpace(article)) { redirectLocation += $"/{article}"; } if (!memoryCache.TryGetValue(redirectLocation, out ContentPageModel? content)) { content = await contentPageService.GetByRedirectLocationAsync(redirectLocation); memoryCache.Set(redirectLocation, content, TimeSpan.FromSeconds(CacheDurationInSeconds)); } return(content); }