public async Task ExportAsync_WhenExceptionWasThrown_ReturnsDashboardExportModelWithoutContent() { Exception exception = new Exception(); IModelExporter <DashboardExportModel, IDashboard> sut = CreateSut(exception: exception); IDashboard dashboard = BuildDashboard(); DashboardExportModel result = await sut.ExportAsync(dashboard); Assert.IsNotNull(result); Assert.IsNotNull(result.Items); Assert.AreEqual(0, result.Items.Count); }
public async Task ExportAsync_WhenCalled_ReturnsDashboardExportModelWithContent() { IModelExporter <DashboardExportModel, IDashboard> sut = CreateSut(); INews[] newsCollection = BuildNewsCollection().ToArray(); IRedditAuthenticatedUser redditAuthenticatedUser = BuildRedditAuthenticatedUser(); IRedditSubreddit[] redditSubredditCollection = BuildRedditSubredditCollection().ToArray(); IRedditLink[] redditLinkCollection = BuildRedditLinkCollection().ToArray(); IDashboard dashboard = BuildDashboard(newsCollection: newsCollection, redditAuthenticatedUser: redditAuthenticatedUser, redditSubredditCollection: redditSubredditCollection, redditLinkCollection: redditLinkCollection); DashboardExportModel result = await sut.ExportAsync(dashboard); Assert.IsNotNull(result); Assert.IsNotNull(result.Items); Assert.AreEqual(newsCollection.Length + 1 + redditSubredditCollection.Length + redditLinkCollection.Length, result.Items.Count); }
public async Task <IActionResult> Export(int numberOfNews = 100, [FromHeader] string redditAccessToken = null, bool includeNsfwContent = false, bool onlyNsfwContent = false) { if (numberOfNews < 0) { return(BadRequest($"The submitted value for '{nameof(numberOfNews)}' cannot be lower than 0.")); } if (numberOfNews > 250) { return(BadRequest($"The submitted value for '{nameof(numberOfNews)}' cannot be greater than 250.")); } IRedditAccessToken token = null; if (string.IsNullOrWhiteSpace(redditAccessToken) == false) { try { token = RedditAccessToken.Create(redditAccessToken); } catch (SerializationException) { return(BadRequest($"The submitted value for '{nameof(redditAccessToken)}' is invalid.")); } catch (FormatException) { return(BadRequest($"The submitted value for '{nameof(redditAccessToken)}' is invalid.")); } } DashboardSettingsViewModel dashboardSettingsViewModel = new DashboardSettingsViewModel { NumberOfNews = numberOfNews, UseReddit = token != null, AllowNsfwContent = token != null ? includeNsfwContent || onlyNsfwContent : false, IncludeNsfwContent = token != null ? includeNsfwContent : false, NotNullableIncludeNsfwContent = token != null ? includeNsfwContent : false, OnlyNsfwContent = token != null ? onlyNsfwContent : false, NotNullableOnlyNsfwContent = token != null ? onlyNsfwContent : false, RedditAccessToken = token?.ToBase64(), ExportData = true }; IDashboard dashboard = await _dashboardFactory.BuildAsync(dashboardSettingsViewModel.ToDashboardSettings()); DashboardExportModel dashboardExportModel = await _dashboardModelExporter.ExportAsync(dashboard); return(Ok(dashboardExportModel)); }
public async Task Export_WhenRedditAccessTokenIsWhiteSpaces_ReturnsOkObjectResult() { DashboardExportModel dashboardExportModel = BuildDashboardExportModel(); Web.Controllers.HomeController sut = CreateSut(dashboardExportModel: dashboardExportModel); IActionResult result = await sut.Export(redditAccessToken : " ", includeNsfwContent : _random.Next(100) > 50, onlyNsfwContent : _random.Next(100) > 50); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okObjectResult = result as OkObjectResult; Assert.IsNotNull(okObjectResult); Assert.IsNotNull(okObjectResult.Value); Assert.AreEqual(dashboardExportModel, okObjectResult.Value); }
public async Task Export_WhenCalledWithoutNumberOfNews_ReturnsOkObjectResult() { DashboardExportModel dashboardExportModel = BuildDashboardExportModel(); Web.Controllers.HomeController sut = CreateSut(dashboardExportModel: dashboardExportModel); IActionResult result = await sut.Export(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okObjectResult = result as OkObjectResult; Assert.IsNotNull(okObjectResult); Assert.IsNotNull(okObjectResult.Value); Assert.AreEqual(dashboardExportModel, okObjectResult.Value); }
public async Task Export_WhenRedditAccessTokenCanBeDeserializedAndOnlyNsfwContentIsSet_ReturnsOkObjectResult() { DashboardExportModel dashboardExportModel = BuildDashboardExportModel(); Web.Controllers.HomeController sut = CreateSut(dashboardExportModel: dashboardExportModel); string redditAccessToken = BuildRedditAccessTokenAsBase64(_random); IActionResult result = await sut.Export(redditAccessToken : redditAccessToken, onlyNsfwContent : true); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okObjectResult = result as OkObjectResult; Assert.IsNotNull(okObjectResult); Assert.IsNotNull(okObjectResult.Value); Assert.AreEqual(dashboardExportModel, okObjectResult.Value); }
private Web.Controllers.HomeController CreateSut(IDashboard dashboard = null, DashboardExportModel dashboardExportModel = null) { _dashboardFactoryMock.Setup(m => m.BuildAsync(It.IsAny <IDashboardSettings>())) .Returns(Task.FromResult(dashboard ?? BuildDashboard())); _dashboardModelExporterMock.Setup(m => m.ExportAsync(It.IsAny <IDashboard>())) .Returns(Task.FromResult(dashboardExportModel ?? BuildDashboardExportModel())); return(new Web.Controllers.HomeController( _dashboardFactoryMock.Object, _dashboardViewModelBuilderMock.Object, _dashboardModelExporterMock.Object, _redditAccessTokenProviderFactoryMock.Object, _contentHelperMock.Object, _cookieHelperMock.Object)); }