public IActionResult TopContent() { DashboardViewModel dashboardViewModel = _cookieHelper.ToDashboardViewModel(); if (dashboardViewModel == null) { return(PartialView("_EmptyContentPartial")); } return(PartialView("_TopContentPartial", dashboardViewModel)); }
public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_AssertToValueWasNotCalledOnContentHelperWithCookieValue() { ICookieHelper sut = CreateSut(hasHttpContext: false); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never); }
public void ToDashboardViewModel_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor() { ICookieHelper sut = CreateSut(); sut.ToDashboardViewModel(); _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once); }
public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_ReturnsNull() { ICookieHelper sut = CreateSut(hasHttpContext: false); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_ReturnsNull() { HttpContext httpContext = BuildHttpContext(false); ICookieHelper sut = CreateSut(httpContext: httpContext); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenHttpContextWasReturned_AssertRequestWasCalledOnReturnedHttpContext() { Mock <HttpContext> httpContextMock = BuildHttpContextMock(); ICookieHelper sut = CreateSut(httpContext: httpContextMock.Object); sut.ToDashboardViewModel(); httpContextMock.Verify(m => m.Request, Times.Once); }
public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_AssertToDashboardViewModelWasNotCalledOnContentHelperWithByteArray() { HttpContext httpContext = BuildHttpContext(false); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToDashboardViewModel(It.IsAny <byte[]>()), Times.Never); }
public void ToDashboardViewModel_WhenHttpRequestWasReturnedButRequestCookieCollectionWasNotReturned_AssertToValueWasNotCalledOnContentHelperWithCookieValue() { HttpRequest httpRequest = BuildHttpRequest(hasRequestCookieCollection: false); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never); }
public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_AssertTryGetValueWasNotCalledOnMemoryCache() { ICookieHelper sut = CreateSut(hasHttpContext: false); sut.ToDashboardViewModel(); object outValue; _memoryCacheMock.Verify(m => m.TryGetValue(It.IsAny <object>(), out outValue), Times.Never); }
public void ToDashboardViewModel_WhenMemoryCacheValueCannotBeConvertedToDashboardViewModel_ReturnsNull() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(dashboardCookieValue: BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(false, httpContext: httpContext, memoryCacheValue: Convert.FromBase64String(BuildBase64String())); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenCookieValueCanBeConvertedToNonExistingMemoryCacheKey_ReturnsNull() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(dashboardCookieValue: BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext, hasMemoryCacheValue: false); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenCookieValueCanBeConvertedToNonExistingMemoryCacheKey_AssertToDashboardViewModelWasNotCalledOnContentHelperWithByteArray() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(dashboardCookieValue: BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext, hasMemoryCacheValue: false); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToDashboardViewModel(It.IsAny <byte[]>()), Times.Never); }
public void ToDashboardViewModel_WhenRequestCookieCollectiontContainingCookieNameForCookieNameForDashboardViewModelWasReturned_AssertItemWasCalledOnReturnedRequestCookieCollectionWithCookieNameForDashboardViewModel() { Mock <IRequestCookieCollection> requestCookieCollectionMock = BuildRequestCookieCollectionMock(dashboardCookieValue: BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollectionMock.Object); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); requestCookieCollectionMock.Verify(m => m[It.Is <string>(value => string.CompareOrdinal(value, DashboardViewModel.CookieName) == 0)], Times.Once); }
public void ToDashboardViewModel_WhenRequestCookieCollectiontWasReturnedButDoNotContainCookieNameForDashboardViewModel_ReturnsNull() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); DashboardViewModel result = sut.ToDashboardViewModel(); Assert.IsNull(result); }
public void ToDashboardViewModel_WhenRequestCookieCollectiontWasReturnedButDoNotContainCookieNameForDashboardViewModel_AssertToValueWasNotCalledOnContentHelperWithCookieValue() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never); }
public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_AssertTryGetValueWasNotCalledOnMemoryCache() { HttpContext httpContext = BuildHttpContext(false); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); object outValue; _memoryCacheMock.Verify(m => m.TryGetValue(It.IsAny <object>(), out outValue), Times.Never); }
public void ToDashboardViewModel_WhenCookieValueWasReturned_AssertToValueWasCalledOnContentHelperWithCookieValue() { string cookieValue = BuildBase64String(); IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(dashboardCookieValue: cookieValue); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); _contentHelperMock.Verify(m => m.ToValue(It.Is <string>(value => string.CompareOrdinal(value, cookieValue) == 0)), Times.Once); }
public void ToDashboardViewModel_WhenRequestCookieCollectiontWasReturnedButDoNotContainCookieNameForDashboardViewModel_AssertTryGetValueWasNotCalledOnMemoryCache() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardViewModel(); object outValue; _memoryCacheMock.Verify(m => m.TryGetValue(It.IsAny <object>(), out outValue), Times.Never); }
public void ToDashboardViewModel_WhenCookieValueCannotBeConvertedToMemoryCacheKey_AssertTryGetValueWasNotCalledOnMemoryCache() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(dashboardCookieValue: BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(hasMemoryCacheKeyInCookie: false, httpContext: httpContext); sut.ToDashboardViewModel(); object outValue; _memoryCacheMock.Verify(m => m.TryGetValue(It.IsAny <object>(), out outValue), Times.Never); }
public void ToDashboardViewModel_WhenCookieValueCanBeConvertedToMemoryCacheKey_AssertTryGetValueWasCalledOnMemoryCache() { string memoryCacheKeyInCookie = $"{DashboardViewModel.CookieName}.{Guid.NewGuid().ToString("D")}"; IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(dashboardCookieValue: BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(memoryCacheKeyInCookie: memoryCacheKeyInCookie, httpContext: httpContext); sut.ToDashboardViewModel(); object outValue; _memoryCacheMock.Verify(m => m.TryGetValue(It.Is <object>(value => value != null && _memoryCacheKeyRegex.IsMatch((string)value)), out outValue), Times.Once); }