예제 #1
0
        public IActionResult TopContent()
        {
            DashboardViewModel dashboardViewModel = _cookieHelper.ToDashboardViewModel();

            if (dashboardViewModel == null)
            {
                return(PartialView("_EmptyContentPartial"));
            }

            return(PartialView("_TopContentPartial", dashboardViewModel));
        }
예제 #2
0
        public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_AssertToValueWasNotCalledOnContentHelperWithCookieValue()
        {
            ICookieHelper sut = CreateSut(hasHttpContext: false);

            sut.ToDashboardViewModel();

            _contentHelperMock.Verify(m => m.ToValue(It.IsAny <string>()), Times.Never);
        }
예제 #3
0
        public void ToDashboardViewModel_WhenCalled_AssertHttpContextWasCalledOnHttpContextAccessor()
        {
            ICookieHelper sut = CreateSut();

            sut.ToDashboardViewModel();

            _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once);
        }
예제 #4
0
        public void ToDashboardViewModel_WhenCalledAndHttpContextWasNotReturned_ReturnsNull()
        {
            ICookieHelper sut = CreateSut(hasHttpContext: false);

            DashboardViewModel result = sut.ToDashboardViewModel();

            Assert.IsNull(result);
        }
예제 #5
0
        public void ToDashboardViewModel_WhenHttpContextWasReturnedButHttpRequestWasNotReturned_ReturnsNull()
        {
            HttpContext   httpContext = BuildHttpContext(false);
            ICookieHelper sut         = CreateSut(httpContext: httpContext);

            DashboardViewModel result = sut.ToDashboardViewModel();

            Assert.IsNull(result);
        }
예제 #6
0
        public void ToDashboardViewModel_WhenHttpContextWasReturned_AssertRequestWasCalledOnReturnedHttpContext()
        {
            Mock <HttpContext> httpContextMock = BuildHttpContextMock();
            ICookieHelper      sut             = CreateSut(httpContext: httpContextMock.Object);

            sut.ToDashboardViewModel();

            httpContextMock.Verify(m => m.Request, Times.Once);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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);
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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);
        }