Ejemplo n.º 1
0
        private async Task <IActionResult> AcquireRedditAuthorizationTokenAsync(DashboardSettingsViewModel dashboardSettingsViewModel)
        {
            if (dashboardSettingsViewModel == null)
            {
                throw new ArgumentNullException(nameof(dashboardSettingsViewModel));
            }

            string dashboardSettingsViewModelAsBase64 = _contentHelper.ToBase64String(dashboardSettingsViewModel);
            Uri    redirectUrl = new Uri(_contentHelper.AbsoluteUrl("RedditCallback", "Home"));

            Uri acquireRedditAuthorizationTokenUrl = await _redditAccessTokenProviderFactory.AcquireRedditAuthorizationTokenAsync(dashboardSettingsViewModelAsBase64, redirectUrl);

            return(Redirect(acquireRedditAuthorizationTokenUrl.AbsoluteUri));
        }
Ejemplo n.º 2
0
        public void AbsoluteUrl_WhenCalledWithValuesAndHttpContextWasNotReturend_ReturnsNull()
        {
            IContentHelper sut = CreateSut(false);

            string result = sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"), new { id = Guid.NewGuid() });

            Assert.IsNull(result);
        }
Ejemplo n.º 3
0
        public void AbsoluteUrl_WhenCalledWithValues_AssertHttpContextWacCalledOnHttpContextAccessor()
        {
            IContentHelper sut = CreateSut();

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"), new { id = Guid.NewGuid() });

            _httpContextAccessorMock.Verify(m => m.HttpContext, Times.Once);
        }
Ejemplo n.º 4
0
        public void AbsoluteUrl_WhenCalledWithValuesAndHttpContextWasNotReturend_AssertActionWasNotCalledOnUrlHelper()
        {
            IContentHelper sut = CreateSut(false);

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"), new { id = Guid.NewGuid() });

            _urlHelperMock.Verify(m => m.Action(It.IsAny <UrlActionContext>()), Times.Never);
        }
Ejemplo n.º 5
0
        public void AbsoluteUrl_WhenCalledWithValuesAndHttpContextWasReturend_AssertRequestWasCalledOnReturnedHttpContext()
        {
            Mock <HttpContext> httpContextMock = BuildHttpContextMock();
            IContentHelper     sut             = CreateSut(httpContext: httpContextMock.Object);

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"), new { id = Guid.NewGuid() });

            httpContextMock.Verify(m => m.Request, Times.Once);
        }
Ejemplo n.º 6
0
        public void AbsoluteUrl_WhenCalledWithoutValuesAndHttpRequestWasNotReturend_ReturnsNull()
        {
            HttpContext    httpContext = BuildHttpContext(false);
            IContentHelper sut         = CreateSut(httpContext: httpContext);

            string result = sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"));

            Assert.IsNull(result);
        }
Ejemplo n.º 7
0
        public void AbsoluteUrl_WhenCalledWithoutValuesAndHttpRequestWasReturend_AssertPathBaseWasCalledOnReturnedHttpRequest()
        {
            Mock <HttpRequest> httpRequestMock = BuildHttpRequestMock();
            HttpContext        httpContext     = BuildHttpContext(httpRequest: httpRequestMock.Object);
            IContentHelper     sut             = CreateSut(httpContext: httpContext);

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"));

            httpRequestMock.Verify(m => m.PathBase, Times.Once);
        }
Ejemplo n.º 8
0
        public void AbsoluteUrl_WhenCalledWithoutValuesAndHttpRequestWasReturend_AssertActionWasCalledOnUrlHelper()
        {
            IContentHelper sut = CreateSut();

            string action     = Guid.NewGuid().ToString("D");
            string controller = Guid.NewGuid().ToString("D");

            sut.AbsoluteUrl(action, controller);

            _urlHelperMock.Verify(m => m.Action(It.Is <UrlActionContext>(value => value != null && string.CompareOrdinal(value.Controller, controller) == 0 && string.CompareOrdinal(value.Action, action) == 0 && value.Values == null)), Times.Once);
        }
Ejemplo n.º 9
0
        public static string GetSettingsUrl(this DashboardSettingsViewModel dashboardSettingsViewModel, IContentHelper contentHelper)
        {
            if (dashboardSettingsViewModel == null)
            {
                throw new ArgumentNullException(nameof(dashboardSettingsViewModel));
            }
            if (contentHelper == null)
            {
                throw new ArgumentNullException(nameof(contentHelper));
            }

            return(contentHelper.AbsoluteUrl("Settings", "Home"));
        }
Ejemplo n.º 10
0
        public static string GetBuildUrl(this DashboardSettingsViewModel dashboardSettingsViewModel, IContentHelper contentHelper)
        {
            if (dashboardSettingsViewModel == null)
            {
                throw new ArgumentNullException(nameof(dashboardSettingsViewModel));
            }
            if (contentHelper == null)
            {
                throw new ArgumentNullException(nameof(contentHelper));
            }

            return(contentHelper.AbsoluteUrl("Build", "Home", new { DashboardSettings = contentHelper.ToBase64String(dashboardSettingsViewModel) }));
        }
Ejemplo n.º 11
0
        public void AbsoluteUrl_WhenCalledWithoutAndHttpRequestWasReturend_ReturnsAbsoluteUrl()
        {
            const string   scheme      = "http";
            const string   host        = "localhost";
            string         pathBase    = $"/{Guid.NewGuid().ToString("D")}";
            HttpRequest    httpRequest = BuildHttpRequest(scheme, host, pathBase);
            HttpContext    httpContext = BuildHttpContext(httpRequest: httpRequest);
            IContentHelper sut         = CreateSut(httpContext: httpContext);

            string action     = Guid.NewGuid().ToString("D");
            string controller = Guid.NewGuid().ToString("D");
            string result     = sut.AbsoluteUrl(action, controller);

            Assert.IsNotNull(result);
            Assert.AreEqual(result, $"{scheme}://{host}{pathBase}/{controller}/{action}");
        }
Ejemplo n.º 12
0
        public void AbsoluteUrl_WhenCalledWithoutValuesAndControllerIsWhiteSpaces_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), "  ");
        }
Ejemplo n.º 13
0
        public void AbsoluteUrl_WhenCalledWithoutValuesAndActionIsEmpty_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.AbsoluteUrl(string.Empty, Guid.NewGuid().ToString("D"));
        }
Ejemplo n.º 14
0
        public void AbsoluteUrl_WhenCalledWithValuesAndValuesIsNull_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D"), null);
        }
Ejemplo n.º 15
0
        public void AbsoluteUrl_WhenCalledWithValuesAndControllerIsEmpty_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.AbsoluteUrl(Guid.NewGuid().ToString("D"), string.Empty, new { id = Guid.NewGuid() });
        }
Ejemplo n.º 16
0
        public void AbsoluteUrl_WhenCalledWithValuesAndActionIsWhiteSpaces_ThrowsArgumentNullException()
        {
            IContentHelper sut = CreateSut();

            sut.AbsoluteUrl("  ", Guid.NewGuid().ToString("D"), new { id = Guid.NewGuid() });
        }