コード例 #1
0
        public void ToDashboardSettingsViewModel_WhenHttpContextWasNotReturned_ReturnsNull()
        {
            ICookieHelper sut = CreateSut(hasHttpContext: false);

            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel();

            Assert.IsNull(result);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public void ToDashboardSettingsViewModel_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor()
        {
            ICookieHelper sut = CreateSut();

            sut.ToDashboardSettingsViewModel();

            _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once);
        }
コード例 #4
0
        public void ToDashboardSettingsViewModel_WhenHttpContextWasNotReturned_AssertToDashboardSettingsViewModelWasNotCalledOnContentHelper()
        {
            ICookieHelper sut = CreateSut(hasHttpContext: false);

            sut.ToDashboardSettingsViewModel();

            _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.IsAny <string>()), Times.Never);
        }
コード例 #5
0
        public void ToDashboardSettingsViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_ReturnsNull()
        {
            HttpContext   httpContext = BuildHttpContext(false);
            ICookieHelper sut         = CreateSut(httpContext: httpContext);

            DashboardSettingsViewModel result = sut.ToDashboardSettingsViewModel();

            Assert.IsNull(result);
        }
コード例 #6
0
        public void ToDashboardSettingsViewModel_WhenHttpContextWasReturned_AssertRequestWasCalledOnReturnedHttpContext()
        {
            Mock <HttpContext> httpContextMock = BuildHttpContextMock();
            ICookieHelper      sut             = CreateSut(httpContext: httpContextMock.Object);

            sut.ToDashboardSettingsViewModel();

            httpContextMock.Verify(m => m.Request, Times.Once);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }