Esempio n. 1
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithUseOfRedditAndWithoutRedditAccessToken_AssertToBase64StringWasCalledOnContentHelperWithDashboardSettingsViewModel()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut();

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: true, redditAccessToken: null);

            await sut.Commit(dashboardSettingsViewModel);

            _contentHelperMock.Verify(m => m.ToBase64String(It.Is <DashboardSettingsViewModel>(value => value == dashboardSettingsViewModel)), Times.Once);
        }
Esempio n. 2
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithoutUseOfReddit_AssertAcquireRedditAuthorizationTokenAsyncWasNotCalledOnRedditAccessTokenProviderFactory()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut();

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: false);

            await sut.Commit(dashboardSettingsViewModel);

            _redditAccessTokenProviderFactoryMock.Verify(m => m.AcquireRedditAuthorizationTokenAsync(It.IsAny <string>(), It.IsAny <Uri>()), Times.Never);
        }
Esempio n. 3
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithoutUseOfReddit_AssertAbsoluteUrlWasNotCalledOnContentHelper()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut();

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: false);

            await sut.Commit(dashboardSettingsViewModel);

            _contentHelperMock.Verify(m => m.AbsoluteUrl(It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
Esempio n. 4
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithUseOfRedditAndWithoutRedditAccessToken_AssertAbsoluteUrlWasCalledOnContentHelper()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut();

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: true, redditAccessToken: null);

            await sut.Commit(dashboardSettingsViewModel);

            _contentHelperMock.Verify(m => m.AbsoluteUrl(
                                          It.Is <string>(value => string.CompareOrdinal(value, "RedditCallback") == 0),
                                          It.Is <string>(value => string.CompareOrdinal(value, "Home") == 0)),
                                      Times.Once);
        }
Esempio n. 5
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithUseOfRedditAndWithoutRedditAccessToken_AssertAcquireRedditAuthorizationTokenAsyncWasCalledOnRedditAccessTokenProviderFactory()
        {
            string dashboardSettingsViewModelAsBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("D")));

            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboardSettingsViewModelAsBase64: dashboardSettingsViewModelAsBase64);

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: true, redditAccessToken: null);

            await sut.Commit(dashboardSettingsViewModel);

            _redditAccessTokenProviderFactoryMock.Verify(m => m.AcquireRedditAuthorizationTokenAsync(
                                                             It.Is <string>(value => string.CompareOrdinal(value, dashboardSettingsViewModelAsBase64) == 0),
                                                             It.Is <Uri>(value => value != null && string.CompareOrdinal(value.AbsoluteUri, $"http://localhost/Home/RedditCallback") == 0)),
                                                         Times.Once);
        }
Esempio n. 6
0
        public async Task Commit_WhenCalledWithInvalidDashboardSettingsViewModel_ReturnsRedirectToActionResult()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(false);

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random);

            IActionResult result = await sut.Commit(dashboardSettingsViewModel);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));

            RedirectToActionResult redirectToActionResult = (RedirectToActionResult)result;

            Assert.IsNotNull(redirectToActionResult);
            Assert.IsNotNull(redirectToActionResult.ActionName);
            Assert.AreEqual("Index", redirectToActionResult.ActionName);
            Assert.IsNotNull(redirectToActionResult.ControllerName);
            Assert.AreEqual("HomeController", redirectToActionResult.ControllerName);
        }
Esempio n. 7
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithoutUseOfReddit_ReturnsViewResultWithDashboardSettingsViewModel()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut();

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: false);

            IActionResult result = await sut.Commit(dashboardSettingsViewModel);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(ViewResult));

            ViewResult viewResult = (ViewResult)result;

            Assert.IsNotNull(viewResult);
            Assert.IsNotNull(viewResult.ViewName);
            Assert.AreEqual("Index", viewResult.ViewName);
            Assert.IsNotNull(viewResult.Model);
            Assert.AreEqual(dashboardSettingsViewModel, viewResult.Model);
        }
Esempio n. 8
0
        public async Task Commit_WhenDashboardSettingsViewModelIsWithUseOfRedditAndWithoutRedditAccessToken_ReturnsRedirectResultToUrlFromAcquireRedditAuthorizationTokenAsyncOnRedditAccessTokenProviderFactory()
        {
            Uri acquireRedditAuthorizationTokenUri = new Uri($"http://localhost/{Guid.NewGuid().ToString("D")}/{Guid.NewGuid().ToString("D")}");

            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(acquireRedditAuthorizationTokenUri: acquireRedditAuthorizationTokenUri);

            DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, useReddit: true, redditAccessToken: null);

            IActionResult result = await sut.Commit(dashboardSettingsViewModel);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectResult));

            RedirectResult redirectResult = (RedirectResult)result;

            Assert.IsNotNull(redirectResult);
            Assert.IsNotNull(redirectResult.Url);
            Assert.AreEqual(redirectResult.Url, acquireRedditAuthorizationTokenUri.AbsoluteUri);
        }
Esempio n. 9
0
        public async Task Commit_WhenDashboardSettingsViewModelIsNull_ThrowsArgumentNullExcpetion()
        {
            OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut();

            await sut.Commit(null);
        }