private OSDevGrp.MyDashboard.Web.Controllers.HomeController CreateSut(bool modelIsValid = true, string dashboardSettingsViewModelAsBase64 = null, Uri acquireRedditAuthorizationTokenUri = null) { _contentHelperMock.Setup(m => m.ToBase64String(It.IsAny <DashboardSettingsViewModel>())) .Returns(dashboardSettingsViewModelAsBase64 ?? Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString("D")))); _contentHelperMock.Setup(m => m.AbsoluteUrl(It.IsAny <string>(), It.IsAny <string>())) .Returns <string, string>((action, controller) => new Uri($"http://localhost/{controller}/{action}").AbsoluteUri); _redditAccessTokenProviderFactoryMock.Setup(m => m.AcquireRedditAuthorizationTokenAsync(It.IsAny <string>(), It.IsAny <Uri>())) .Returns(Task.Run(() => acquireRedditAuthorizationTokenUri ?? new Uri($"http://localhost/{Guid.NewGuid().ToString("D")}/{Guid.NewGuid().ToString("D")}"))); OSDevGrp.MyDashboard.Web.Controllers.HomeController homeController = new OSDevGrp.MyDashboard.Web.Controllers.HomeController( _dashboardFactoryMock.Object, _dashboardViewModelBuilderMock.Object, _dashboardModelExporterMock.Object, _redditAccessTokenProviderFactoryMock.Object, _contentHelperMock.Object, _cookieHelperMock.Object); if (modelIsValid == false) { homeController.ModelState.AddModelError(Guid.NewGuid().ToString("D"), Guid.NewGuid().ToString("D")); } return(homeController); }
public void Index_WhenCookieWithDashboardSettingsWasNotFound_ReturnsViewResultWithDashboardSettingsViewModel() { OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); IActionResult result = sut.Index(); 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.IsInstanceOfType(viewResult.Model, typeof(DashboardSettingsViewModel)); DashboardSettingsViewModel dashboardSettingsViewModel = (DashboardSettingsViewModel)viewResult.Model; Assert.IsNotNull(dashboardSettingsViewModel); Assert.AreEqual(100, dashboardSettingsViewModel.NumberOfNews); Assert.IsFalse(dashboardSettingsViewModel.UseReddit); Assert.IsFalse(dashboardSettingsViewModel.AllowNsfwContent); Assert.IsNotNull(dashboardSettingsViewModel.IncludeNsfwContent); Assert.IsFalse(dashboardSettingsViewModel.IncludeNsfwContent.Value); Assert.IsFalse(dashboardSettingsViewModel.NotNullableIncludeNsfwContent); Assert.IsNotNull(dashboardSettingsViewModel.OnlyNsfwContent); Assert.IsFalse(dashboardSettingsViewModel.OnlyNsfwContent.Value); Assert.IsFalse(dashboardSettingsViewModel.NotNullableOnlyNsfwContent); Assert.IsNull(dashboardSettingsViewModel.RedditAccessToken); Assert.IsFalse(dashboardSettingsViewModel.ExportData); }
public async Task Build_WhenDashboardSettingsCannotBeConvertedToDashboardSettingsViewModel_ReturnsBadRequestResult() { OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(false); IActionResult result = await sut.Build(Guid.NewGuid().ToString("D")); Assert.IsInstanceOfType(result, typeof(BadRequestResult)); }
public void Index_WhenCalled_AssertToDashboardSettingsViewModelWasCalledOnCookieHelper() { OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); sut.Index(); _cookieHelperMock.Verify(m => m.ToDashboardSettingsViewModel(), Times.Once); }
public async Task Build_WhenDashboardSettingsCannotBeConvertedToDashboardSettingsViewModel_AssertBuildAsyncWasNotCalledOnDashboardViewModelBuilder() { OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(false); await sut.Build(Guid.NewGuid().ToString("D")); _dashboardViewModelBuilderMock.Verify(m => m.BuildAsync(It.IsAny <IDashboard>()), Times.Never); }
public async Task RedditCallback_WhenStateIsNull_ThrowsArgumentNullException() { string code = Guid.NewGuid().ToString("D"); const string state = null; OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); await sut.RedditCallback(code, state); }
public async Task Build_WhenCalled_AssertToDashboardSettingsViewModelWasCalledOnContentHelperWithDashboardSettings() { OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); string dashboardSettings = Guid.NewGuid().ToString("D"); await sut.Build(dashboardSettings); _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.Is <string>(value => string.CompareOrdinal(value, dashboardSettings) == 0)), Times.Once); }
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); }
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); }
public async Task Build_WhenDashboardSettingsCanBeConvertedToDashboardSettingsViewModel_AssertBuildAsyncWasCalledOnDashboardViewModelBuilder() { IDashboard dashboard = BuildDashboard(); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboard: dashboard); await sut.Build(Guid.NewGuid().ToString("D")); _dashboardViewModelBuilderMock.Verify(m => m.BuildAsync(It.Is <IDashboard>(value => value == dashboard)), Times.Once); }
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); }
public async Task Build_WhenDashboardSettingsCanBeConvertedToDashboardSettingsViewModel_AssertBuildAsyncWasCalledOnDashboardFactoryWithOnlyNsfwContentFromDashboardSettingsViewModel() { bool onlyNsfwContent = _random.Next(100) > 50; DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, onlyNsfwContent: onlyNsfwContent); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboardSettingsViewModel: dashboardSettingsViewModel); await sut.Build(Guid.NewGuid().ToString("D")); _dashboardFactoryMock.Verify(m => m.BuildAsync(It.Is <IDashboardSettings>(value => value != null && value.OnlyNsfwContent == onlyNsfwContent)), Times.Once); }
public async Task Build_WhenDashboardSettingsCanBeConvertedToDashboardSettingsViewModel_AssertBuildAsyncWasCalledOnDashboardFactoryWithRedditAccessTokenFromDashboardSettingsViewModel() { string redditAccessToken = BuildRedditAccessToken(_random).ToBase64(); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, redditAccessToken: redditAccessToken); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboardSettingsViewModel: dashboardSettingsViewModel); await sut.Build(Guid.NewGuid().ToString("D")); _dashboardFactoryMock.Verify(m => m.BuildAsync(It.Is <IDashboardSettings>(value => value != null && value.RedditAccessToken != null && string.CompareOrdinal(value.RedditAccessToken.ToBase64(), redditAccessToken) == 0)), Times.Once); }
public async Task Build_WhenDashboardSettingsCanBeConvertedToDashboardSettingsViewModel_AssertBuildAsyncWasCalledOnDashboardFactoryWithNumberOfNewsFromDashboardSettingsViewModel() { int numberOfNews = _random.Next(25, 50); DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, numberOfNews); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboardSettingsViewModel: dashboardSettingsViewModel); await sut.Build(Guid.NewGuid().ToString("D")); _dashboardFactoryMock.Verify(m => m.BuildAsync(It.Is <IDashboardSettings>(value => value != null && value.NumberOfNews == numberOfNews)), Times.Once); }
public async Task RedditCallback_WhenCalledWithoutErrorAndStateCannotBeConvertedToDashboardSettingsViewModel_ReturnsBadRequestResult() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(false); IActionResult result = await sut.RedditCallback(code, state); Assert.IsInstanceOfType(result, typeof(BadRequestResult)); }
public async Task RedditCallback_WhenCalledWithoutErrorAndStateCannotBeConvertedToDashboardSettingsViewModel_AssertGetRedditAccessTokenAsyncWasNotCalledOnRedditAccessTokenProviderFactory() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(false); await sut.RedditCallback(code, state); _redditAccessTokenProviderFactoryMock.Verify(m => m.GetRedditAccessTokenAsync(It.IsAny <string>(), It.IsAny <Uri>()), Times.Never); }
public async Task RedditCallback_WhenCalledWithoutError_AssertToDashboardSettingsViewModelWasCalledOnContentHelperWithState() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); await sut.RedditCallback(code, state); _contentHelperMock.Verify(m => m.ToDashboardSettingsViewModel(It.Is <string>(value => string.CompareOrdinal(value, state) == 0)), Times.Once); }
public async Task RedditCallback_WhenCalledWithoutErrorAndStateCannotBeConvertedToDashboardSettingsViewModel_AssertAbsoluteUrlWasNotCalledOnContentHelper() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(false); await sut.RedditCallback(code, state); _contentHelperMock.Verify(m => m.AbsoluteUrl(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public async Task RedditCallback_WhenCalledWithError_AssertAbsoluteUrlWasNotCalledOnContentHelper() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); string error = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); await sut.RedditCallback(code, state, error); _contentHelperMock.Verify(m => m.AbsoluteUrl(It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
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); }
public async Task RedditCallback_WhenCalledWithoutErrorAndStateCanBeConvertedToDashboardSettingsViewModel_AssertGetRedditAccessTokenAsyncWasCalledOnRedditAccessTokenProviderFactory() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); await sut.RedditCallback(code, state); _redditAccessTokenProviderFactoryMock.Verify(m => m.GetRedditAccessTokenAsync( It.Is <string>(value => string.CompareOrdinal(value, code) == 0), It.Is <Uri>(value => value != null && string.CompareOrdinal(value.AbsoluteUri, "http://localhost/Home/RedditCallback") == 0)), Times.Once); }
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); }
public async Task RedditCallback_WhenCalledWithoutErrorAndStateCanBeConvertedToDashboardSettingsViewModelAndRedditAccessTokenWasReturned_ReturnsViewResultWithDashboardSettingsViewModel() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); int numberOfNews = _random.Next(25, 50); bool useReddit = _random.Next(100) > 50; bool allowNsfwContent = _random.Next(100) > 50; bool includeNsfwContent = _random.Next(100) > 50; bool onlyNsfwContent = _random.Next(100) > 50; bool exportData = _random.Next(100) > 50; DashboardSettingsViewModel dashboardSettingsViewModel = BuildDashboardSettingsViewModel(_random, numberOfNews, useReddit, allowNsfwContent, includeNsfwContent, onlyNsfwContent, null, exportData); IRedditAccessToken redditAccessToken = BuildRedditAccessToken(_random); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboardSettingsViewModel: dashboardSettingsViewModel, redditAccessToken: redditAccessToken); IActionResult result = await sut.RedditCallback(code, state); 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.IsInstanceOfType(viewResult.Model, typeof(DashboardSettingsViewModel)); DashboardSettingsViewModel dashboardSettingsViewModelFromViewResult = (DashboardSettingsViewModel)viewResult.Model; Assert.IsNotNull(dashboardSettingsViewModelFromViewResult); Assert.AreEqual(numberOfNews, dashboardSettingsViewModelFromViewResult.NumberOfNews); Assert.AreEqual(useReddit, dashboardSettingsViewModelFromViewResult.UseReddit); Assert.AreEqual(allowNsfwContent, dashboardSettingsViewModelFromViewResult.AllowNsfwContent); Assert.IsNotNull(dashboardSettingsViewModelFromViewResult.IncludeNsfwContent); Assert.AreEqual(includeNsfwContent, dashboardSettingsViewModelFromViewResult.IncludeNsfwContent.Value); Assert.AreEqual(includeNsfwContent, dashboardSettingsViewModelFromViewResult.NotNullableIncludeNsfwContent); Assert.IsNotNull(dashboardSettingsViewModelFromViewResult.OnlyNsfwContent); Assert.AreEqual(onlyNsfwContent, dashboardSettingsViewModelFromViewResult.OnlyNsfwContent.Value); Assert.AreEqual(onlyNsfwContent, dashboardSettingsViewModelFromViewResult.NotNullableOnlyNsfwContent); Assert.IsNotNull(dashboardSettingsViewModelFromViewResult.RedditAccessToken); Assert.AreEqual(redditAccessToken.ToBase64(), dashboardSettingsViewModelFromViewResult.RedditAccessToken); Assert.AreEqual(exportData, dashboardSettingsViewModelFromViewResult.ExportData); }
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); }
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); }
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); }
public void SystemError_WhenCalled_ReturnsViewWithSystemErrorViewModel() { SystemErrorViewModel systemErrorViewModel = new SystemErrorViewModel(); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); IActionResult result = sut.SystemError(systemErrorViewModel); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ViewResult)); ViewResult viewResult = (ViewResult)result; Assert.IsNotNull(viewResult); Assert.IsNotNull(viewResult.ViewName); Assert.AreEqual("SystemError", viewResult.ViewName); Assert.IsNotNull(viewResult.Model); Assert.AreEqual(systemErrorViewModel, viewResult.Model); }
public void Index_WhenCookieWithDashboardSettingsWasFound_ReturnsViewResultWithDashboardSettingsViewModel() { int numberOfNews = _random.Next(25, 50); bool useReddit = _random.Next(100) > 50; bool allowNsfwContent = _random.Next(100) > 50; bool includeNsfwContent = _random.Next(100) > 50; bool onlyNsfwContent = _random.Next(100) > 50; string redditAccessToken = BuildRedditAccessTokenAsBase64(_random); bool exportData = _random.Next(100) > 50; DashboardSettingsViewModel dashboardSettingsViewModelInCookie = BuildDashboardSettingsViewModel(_random, numberOfNews, useReddit, allowNsfwContent, includeNsfwContent, onlyNsfwContent, redditAccessToken, exportData); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(true, dashboardSettingsViewModelInCookie); IActionResult result = sut.Index(); 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.IsInstanceOfType(viewResult.Model, typeof(DashboardSettingsViewModel)); DashboardSettingsViewModel dashboardSettingsViewModel = (DashboardSettingsViewModel)viewResult.Model; Assert.IsNotNull(dashboardSettingsViewModel); Assert.AreEqual(numberOfNews, dashboardSettingsViewModel.NumberOfNews); Assert.AreEqual(useReddit, dashboardSettingsViewModel.UseReddit); Assert.AreEqual(allowNsfwContent, dashboardSettingsViewModel.AllowNsfwContent); Assert.IsNotNull(dashboardSettingsViewModel.IncludeNsfwContent); Assert.AreEqual(includeNsfwContent, dashboardSettingsViewModel.IncludeNsfwContent.Value); Assert.AreEqual(includeNsfwContent, dashboardSettingsViewModel.NotNullableIncludeNsfwContent); Assert.IsNotNull(dashboardSettingsViewModel.OnlyNsfwContent); Assert.AreEqual(onlyNsfwContent, dashboardSettingsViewModel.OnlyNsfwContent.Value); Assert.AreEqual(onlyNsfwContent, dashboardSettingsViewModel.NotNullableOnlyNsfwContent); Assert.IsNotNull(dashboardSettingsViewModel.RedditAccessToken); Assert.AreEqual(redditAccessToken, dashboardSettingsViewModel.RedditAccessToken); Assert.AreEqual(exportData, dashboardSettingsViewModel.ExportData); }
public async Task Build_WhenDashboardSettingsCanBeConvertedToDashboardSettingsViewModel_ReturnsPartialViewResultWithBuildDashboardViewModel() { DashboardViewModel dashboardViewModel = BuildDashboardViewModel(_random); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(dashboardViewModel: dashboardViewModel); IActionResult result = await sut.Build(Guid.NewGuid().ToString("D")); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(PartialViewResult)); PartialViewResult partialViewResult = (PartialViewResult)result; Assert.IsNotNull(partialViewResult); Assert.IsNotNull(partialViewResult.ViewName); Assert.AreEqual("_MainContentPartial", partialViewResult.ViewName); Assert.IsNotNull(partialViewResult.Model); Assert.IsInstanceOfType(partialViewResult.Model, typeof(DashboardViewModel)); Assert.AreSame(dashboardViewModel, partialViewResult.Model); }
public async Task RedditCallback_WhenCalledWithError_ReturnsUnauthorizedObjectResult() { string code = Guid.NewGuid().ToString("D"); string state = Guid.NewGuid().ToString("D"); string error = Guid.NewGuid().ToString("D"); OSDevGrp.MyDashboard.Web.Controllers.HomeController sut = CreateSut(); IActionResult result = await sut.RedditCallback(code, state, error); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(UnauthorizedObjectResult)); UnauthorizedObjectResult unauthorizedObjectResult = (UnauthorizedObjectResult)result; Assert.IsNotNull(unauthorizedObjectResult); Assert.IsInstanceOfType(unauthorizedObjectResult.Value, typeof(string)); string value = (string)unauthorizedObjectResult.Value; Assert.IsNotNull(value); Assert.AreEqual($"Unable to get the access token from Reddit: {error}", value); }