public void ToDashboardSettingsViewModel_WhenHttpContextWasNotReturned_ReturnsNull() { ICookieHelper sut = CreateSut(hasHttpContext: false); DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(); Assert.IsNull(result); }
public IActionResult Index() { DashboardSettingsViewModel defaultDashboardSettingsViewModel = new DashboardSettingsViewModel { NumberOfNews = 100, UseReddit = false, AllowNsfwContent = false, IncludeNsfwContent = false, OnlyNsfwContent = false, RedditAccessToken = null, ExportData = false }; DashboardSettingsViewModel dashboardSettingsViewModel = _cookieHelper.ToDashboardSettingsViewModel(); return(View("Index", dashboardSettingsViewModel ?? defaultDashboardSettingsViewModel)); }
public void ToDashboardSettingsViewModel_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor() { ICookieHelper sut = CreateSut(); sut.ToDashboardSettingsViewModel(); _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once); }
public void ToDashboardSettingsViewModel_WhenHttpContextWasNotReturned_AssertToDashboardSettingsViewModelWasNotCalledOnContentHelper() { ICookieHelper sut = CreateSut(hasHttpContext: false); sut.ToDashboardSettingsViewModel(); _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.IsAny <string>()), Times.Never); }
public void ToDashboardSettingsViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_ReturnsNull() { HttpContext httpContext = BuildHttpContext(false); ICookieHelper sut = CreateSut(httpContext: httpContext); DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(); Assert.IsNull(result); }
public void ToDashboardSettingsViewModel_WhenHttpContextWasReturned_AssertRequestWasCalledOnReturnedHttpContext() { Mock <HttpContext> httpContextMock = BuildHttpContextMock(); ICookieHelper sut = CreateSut(httpContext: httpContextMock.Object); sut.ToDashboardSettingsViewModel(); httpContextMock.Verify(m => m.Request, Times.Once); }
public void ToDashboardSettingsViewModel_WhenHttpRequestWasReturnedButRequestCookieCollectionWasNotReturned_AssertToDashboardSettingsViewModelWasNotCalledOnContentHelper() { HttpRequest httpRequest = BuildHttpRequest(hasRequestCookieCollection: false); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardSettingsViewModel(); _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.IsAny <string>()), Times.Never); }
public void ToDashboardSettingsViewModel_WhenCookieValueCannotBeConvertedToDashboardSettingsViewModel_ReturnsNull() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(false, httpContext: httpContext); DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(); Assert.IsNull(result); }
public void ToDashboardSettingsViewModel_WhenRequestCookieCollectiontContainingCookieNameForDashboardSettingsViewModelWasReturned_AssertItemWasCalledOnReturnedRequestCookieCollectionWithCookieNameForDashboardSettingsViewModel() { Mock <IRequestCookieCollection> requestCookieCollectionMock = BuildRequestCookieCollectionMock(BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollectionMock.Object); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardSettingsViewModel(); requestCookieCollectionMock.Verify(m => m[It.Is <string>(value => string.CompareOrdinal(value, DashboardSettingsViewModel.CookieName) == 0)], Times.Once); }
public void ToDashboardSettingsViewModel_WhenRequestCookieCollectiontWasReturnedButDoNotContainCookieNameForDashboardSettingsViewModel_ReturnsNull() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(); Assert.IsNull(result); }
public void ToDashboardSettingsViewModel_WhenRequestCookieCollectiontWasReturnedButDoNotContainCookieNameForDashboardSettingsViewModel_AssertToDashboardSettingsViewModelWasNotCalledOnContentHelper() { IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardSettingsViewModel(); _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.IsAny <string>()), Times.Never); }
public void ToDashboardSettingsViewModel_WhenCookieValueCanBeConvertedToDashboardSettingsViewModel_ReturnsDashboardSettingsViewModel() { DashboardSettingsViewModel dashboardSettingsViewModelInCookie = BuildDashboardSettingsViewModel(_random); IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(BuildBase64String()); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(dashboardSettingsViewModelInCookie: dashboardSettingsViewModelInCookie, httpContext: httpContext); DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel(); Assert.AreEqual(result, dashboardSettingsViewModelInCookie); }
public void ToDashboardSettingsViewModel_WhenCookieValueWasReturned_AssertToDashboardSettingsViewModelWasCalledOnContentHelper() { string cookieValue = BuildBase64String(); IRequestCookieCollection requestCookieCollection = BuildRequestCookieCollection(cookieValue); HttpRequest httpRequest = BuildHttpRequest(requestCookieCollection: requestCookieCollection); HttpContext httpContext = BuildHttpContext(httpRequest: httpRequest); ICookieHelper sut = CreateSut(httpContext: httpContext); sut.ToDashboardSettingsViewModel(); _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.Is <string>(value => string.CompareOrdinal(value, cookieValue) == 0)), Times.Once); }