public async Task BuildAsync_WhenCalledAndRedditAuthenticatedUserToObjectViewModelBuilderThrowsAggregateException_AddsExceptionToSystemViewModelsInDashboardViewModel() { IEnumerable <INews> newsCollection = CreateNewsCollection(0); IEnumerable <ISystemError> systemErrorCollection = CreateSystemErrorCollection(0); IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(); IEnumerable <IRedditSubreddit> redditSubredditCollection = CreateRedditSubredditCollection(0); IEnumerable <IRedditLink> redditLinkCollection = CreateRedditLinkCollection(0); IDashboard dashboard = CreateDashboard(newsCollection: newsCollection, systemErrorCollection: systemErrorCollection, redditAuthenticatedUser: redditAuthenticatedUser, redditSubredditCollection: redditSubredditCollection, redditLinkCollection: redditLinkCollection); string aggregateExceptionMessage = Guid.NewGuid().ToString(); IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut(aggregateExceptionMessage: aggregateExceptionMessage); DashboardViewModel result = await sut.BuildAsync(dashboard); Assert.IsNotNull(result); Assert.IsNotNull(result.Informations); Assert.AreEqual(0, result.Informations.Count()); Assert.IsNotNull(result.LatestInformationsWithImage); Assert.AreEqual(0, result.LatestInformationsWithImage.Count()); Assert.IsNotNull(result.SystemErrors); Assert.AreEqual(1, result.SystemErrors.Count()); Assert.IsNull(result.Settings); Assert.IsNull(result.RedditAuthenticatedUser); Assert.IsNotNull(result.RedditSubreddits); Assert.AreEqual(0, result.RedditSubreddits.Count()); SystemErrorViewModel systemErrorViewModel = result.SystemErrors.First(); Assert.IsNotNull(systemErrorViewModel); Assert.IsNotNull(systemErrorViewModel.SystemErrorIdentifier); Assert.IsTrue(systemErrorViewModel.Timestamp >= DateTime.Now.AddSeconds(-3) && systemErrorViewModel.Timestamp <= DateTime.Now); Assert.IsNotNull(systemErrorViewModel.Message); Assert.AreEqual($"HtmlHelper.ConvertNewLines:{aggregateExceptionMessage}", systemErrorViewModel.Message); Assert.IsNotNull(systemErrorViewModel.Details); }
public async Task BuildAsync_WhenCalled_ReturnsInitializedDashboardViewModel() { List <INews> newsCollection = CreateNewsCollection(_random.Next(50, 75)).ToList(); List <ISystemError> systemErrorCollection = CreateSystemErrorCollection(_random.Next(10, 15)).ToList(); IDashboardSettings dashboardSettings = CreateDashboardSettings(); IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(); List <IRedditSubreddit> redditSubredditCollection = CreateRedditSubredditCollection(_random.Next(10, 25)).ToList(); List <IRedditLink> redditLinkCollection = CreateRedditLinkCollection(_random.Next(50, 75)).ToList(); IDashboard dashboard = CreateDashboard(newsCollection: newsCollection, systemErrorCollection: systemErrorCollection, dashboardSettings: dashboardSettings, redditAuthenticatedUser: redditAuthenticatedUser, redditSubredditCollection: redditSubredditCollection, redditLinkCollection: redditLinkCollection); DashboardSettingsViewModel dashboardSettingsViewModel = CreateDashboardSettingsViewModel(); ObjectViewModel <IRedditAuthenticatedUser> objectViewModelForRedditAuthenticatedUser = CreateObjectViewModel <IRedditAuthenticatedUser>(redditAuthenticatedUser, DateTime.Now.AddDays(_random.Next(1, 365) * -1).AddMinutes(_random.Next(-120, 120))); IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut(dashboardSettingsViewModel: dashboardSettingsViewModel, objectViewModelForRedditAuthenticatedUser: objectViewModelForRedditAuthenticatedUser); DashboardViewModel result = await sut.BuildAsync(dashboard); Assert.IsNotNull(result); Assert.IsNotNull(result.Informations); Assert.AreEqual(newsCollection.Count + redditLinkCollection.Count, result.Informations.Count()); Assert.IsNotNull(result.LatestInformationsWithImage); Assert.AreEqual(Math.Min(result.Informations.Count(information => string.IsNullOrWhiteSpace(information.ImageUrl) == false), 7), result.LatestInformationsWithImage.Count()); Assert.IsNotNull(result.SystemErrors); Assert.AreEqual(systemErrorCollection.Count, result.SystemErrors.Count()); Assert.IsNotNull(result.Settings); Assert.AreEqual(dashboardSettingsViewModel, result.Settings); Assert.IsNotNull(result.RedditAuthenticatedUser); Assert.AreEqual(objectViewModelForRedditAuthenticatedUser, result.RedditAuthenticatedUser); Assert.IsNotNull(result.RedditSubreddits); Assert.AreEqual(redditSubredditCollection.Count, result.RedditSubreddits.Count()); }
public void AllowNsfwContent_WhenRedditAuthenticatedUserIsNull_ReturnsFalse() { const IRedditAuthenticatedUser redditAuthenticatedUser = null; IDashboardRules sut = CreateSut(redditAuthenticatedUser); Assert.IsFalse(sut.AllowNsfwContent); }
public void Replace_WhenCalledWithRedditAuthenticatedUserEqualToNull_ThrowsArgumentNullExcpetion() { const IRedditAuthenticatedUser redditAuthenticatedUser = null; IDashboard sut = CreateSut(); sut.Replace(redditAuthenticatedUser); }
public void Replace(IRedditAuthenticatedUser redditAuthenticatedUser) { if (redditAuthenticatedUser == null) { throw new ArgumentNullException(nameof(redditAuthenticatedUser)); } _redditAuthenticatedUser = redditAuthenticatedUser; }
public void AllowNsfwContent_WhenRedditAuthenticatedUserIsOver18_ReturnsTrue() { const bool over18 = true; IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(over18: over18); IDashboardRules sut = CreateSut(redditAuthenticatedUser); Assert.IsTrue(sut.AllowNsfwContent); }
public async Task ExportAsync_WhenCalled_AssertHandleAsyncWasNotCalledOnExceptionHandler() { IModelExporter <DashboardItemExportModel, IRedditAuthenticatedUser> sut = CreateSut(); IRedditAuthenticatedUser redditAuthenticatedUser = BuildRedditAuthenticatedUser(); DashboardItemExportModel result = await sut.ExportAsync(redditAuthenticatedUser); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <AggregateException>()), Times.Never); _exceptionHandlerMock.Verify(m => m.HandleAsync(It.IsAny <Exception>()), Times.Never); }
public async Task ExportAsync_WhenCalled_ReturnsDashboardItemExportModelWithoutImageUrl() { IModelExporter <DashboardItemExportModel, IRedditAuthenticatedUser> sut = CreateSut(); IRedditAuthenticatedUser redditAuthenticatedUser = BuildRedditAuthenticatedUser(); DashboardItemExportModel result = await sut.ExportAsync(redditAuthenticatedUser); Assert.IsNotNull(result); Assert.IsNull(result.ImageUrl); }
public async Task ExportAsync_WhenDashboardHasRedditAuthenticatedUser_AssertExportAsyncWasCalledOnRedditAuthenticatedUserModelExporter() { IModelExporter <DashboardExportModel, IDashboard> sut = CreateSut(); IRedditAuthenticatedUser redditAuthenticatedUser = BuildRedditAuthenticatedUser(); IDashboard dashboard = BuildDashboard(redditAuthenticatedUser: redditAuthenticatedUser); await sut.ExportAsync(dashboard); _redditAuthenticatedUserModelExporterMock.Verify(m => m.ExportAsync(It.Is <IRedditAuthenticatedUser>(value => value == redditAuthenticatedUser)), Times.Once); }
public async Task BuildAsync_WhenCalled_AssertBuildAsyncWasCalledOnRedditAuthenticatedUserToObjectViewModelBuilderWithRedditAuthenticatedUserInDashboard() { IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(); IDashboard dashboard = CreateDashboard(redditAuthenticatedUser: redditAuthenticatedUser); IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut(); await sut.BuildAsync(dashboard); _redditAuthenticatedUserToObjectViewModelBuilderMock.Verify(m => m.BuildAsync(It.Is <IRedditAuthenticatedUser>(value => value == redditAuthenticatedUser)), Times.Once); }
public async Task ExportAsync_WhenCalled_ReturnsDashboardItemExportModelWithInformationFromRedditAuthenticatedUser() { IModelExporter <DashboardItemExportModel, IRedditAuthenticatedUser> sut = CreateSut(); string userName = Guid.NewGuid().ToString("D"); IRedditAuthenticatedUser redditAuthenticatedUser = BuildRedditAuthenticatedUser(userName: userName); DashboardItemExportModel result = await sut.ExportAsync(redditAuthenticatedUser); Assert.IsNotNull(result); Assert.AreEqual(userName, result.Information); }
public async Task ExportAsync_WhenCalled_ReturnsDashboardItemExportModelWithTimestampFromRedditAuthenticatedUser() { IModelExporter <DashboardItemExportModel, IRedditAuthenticatedUser> sut = CreateSut(); DateTime createdTime = DateTime.Now.AddSeconds(_random.Next(300, 3600) * -1); IRedditAuthenticatedUser redditAuthenticatedUser = BuildRedditAuthenticatedUser(createdTime: createdTime); DashboardItemExportModel result = await sut.ExportAsync(redditAuthenticatedUser); Assert.IsNotNull(result); Assert.AreEqual(createdTime, result.Timestamp); }
public async Task BuildAsync_WhenCalled_AssertRedditAuthenticatedUserWasCalledOnDashboardOnce() { IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(); Mock <IDashboard> dashboardMock = CreateDashboardMock(redditAuthenticatedUser: redditAuthenticatedUser); IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut(); await sut.BuildAsync(dashboardMock.Object); dashboardMock.Verify(m => m.RedditAuthenticatedUser, Times.Once); }
public async Task GetAuthenticatedUserAsync_WhenCalledAndRedditRateLimitHasExceeded_ReturnsNull() { IRedditAccessToken redditAccessToken = CreateRedditAccessToken(); const bool willExceedRateLimit = true; IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit); IRedditAuthenticatedUser getAuthenticatedUser = await sut.GetAuthenticatedUserAsync(redditAccessToken); Assert.IsNull(getAuthenticatedUser); }
public async Task GetAuthenticatedUserAsync_WhenCalledAndRedditRateLimitHasNotExceededAndExceptionOccurs_ReturnsNull() { IRedditAccessToken redditAccessToken = CreateRedditAccessToken(); const bool willExceedRateLimit = false; Exception exception = new Exception(); IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit, exception: exception); IRedditAuthenticatedUser getAuthenticatedUser = await sut.GetAuthenticatedUserAsync(redditAccessToken); Assert.IsNull(getAuthenticatedUser); }
private Task <DashboardItemExportModel>[] CreateExportTasks(IRedditAuthenticatedUser redditAuthenticatedUser) { if (redditAuthenticatedUser == null) { return(new Task <DashboardItemExportModel> [0]); } return(new Task <DashboardItemExportModel>[1] { _redditAuthenticatedUserModelExporter.ExportAsync(redditAuthenticatedUser) }); }
public async Task GetAuthenticatedUserAsync_WhenCalledAndRedditRateLimitHasNotExceeded_ReturnsRedditAuthenticatedUserFromRedditRepository() { IRedditAccessToken redditAccessToken = CreateRedditAccessToken(); const bool willExceedRateLimit = false; IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(); IRedditResponse <IRedditAuthenticatedUser> redditResponse = CreateRedditResponse(redditAuthenticatedUser: redditAuthenticatedUser); IRedditLogic sut = CreateSut(willExceedRateLimit: willExceedRateLimit, redditResponse: redditResponse); IRedditAuthenticatedUser getAuthenticatedUser = await sut.GetAuthenticatedUserAsync(redditAccessToken); Assert.AreEqual(redditAuthenticatedUser, getAuthenticatedUser); }
public async Task BuildAsync(IDashboardSettings dashboardSettings, IDashboard dashboard) { if (dashboardSettings == null) { throw new ArgumentNullException(nameof(dashboardSettings)); } if (dashboard == null) { throw new ArgumentNullException(nameof(dashboard)); } try { IRedditAccessToken accessToken = dashboardSettings.RedditAccessToken; if (DateTime.Now > accessToken.Expires) { accessToken = await _redditLogic.RenewAccessTokenAsync(accessToken); if (accessToken == null) { return; } dashboardSettings.RedditAccessToken = accessToken; } IRedditAuthenticatedUser authenticatedUser = await _redditLogic.GetAuthenticatedUserAsync(accessToken); if (authenticatedUser == null) { return; } dashboard.Replace(authenticatedUser); bool over18 = authenticatedUser.Over18; bool includeNsfwContent = dashboardSettings.IncludeNsfwContent; bool onlyNsfwContent = dashboardSettings.OnlyNsfwContent; IEnumerable <IRedditSubreddit> subreddits = await GetSubredditsAsync(accessToken, over18, includeNsfwContent, onlyNsfwContent); dashboard.Replace(subreddits); IEnumerable <IRedditLink> links = await GetLinksAsync(accessToken, subreddits, over18, includeNsfwContent, onlyNsfwContent); dashboard.Replace(links); } catch (Exception ex) { await _exceptionHandler.HandleAsync(ex); } }
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 BuildAsync_WhenCalledWithRedditAuthenticatedUserWithoutUnreadMail_ReturnsInitializedObjectViewModelWithCorrectHtml() { string userName = Guid.NewGuid().ToString("D"); int commentKarma = GetKarmaValue(); int linkKarma = GetKarmaValue(); const bool hasUnreadMail = false; IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(userName: userName, commentKarma: commentKarma, linkKarma: linkKarma, hasUnreadMail: hasUnreadMail); IViewModelBuilder <ObjectViewModel <IRedditAuthenticatedUser>, IRedditAuthenticatedUser> sut = CreateSut(); ObjectViewModel <IRedditAuthenticatedUser> result = await sut.BuildAsync(redditAuthenticatedUser); Assert.IsNotNull(result); Assert.IsNotNull(result.Html); Assert.AreEqual(GetExpectedHtml(userName, commentKarma, linkKarma, hasUnreadMail), result.Html); }
public async Task BuildAsync_WhenCalled_AssertToCookieWasCalledOnCookieHelperWithDashboardViewModel() { List <INews> newsCollection = CreateNewsCollection(_random.Next(50, 75)).ToList(); List <ISystemError> systemErrorCollection = CreateSystemErrorCollection(_random.Next(10, 15)).ToList(); IDashboardSettings dashboardSettings = CreateDashboardSettings(); IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(); List <IRedditSubreddit> redditSubredditCollection = CreateRedditSubredditCollection(_random.Next(10, 25)).ToList(); List <IRedditLink> redditLinkCollection = CreateRedditLinkCollection(_random.Next(50, 75)).ToList(); IDashboard dashboard = CreateDashboard(newsCollection: newsCollection, systemErrorCollection: systemErrorCollection, dashboardSettings: dashboardSettings, redditAuthenticatedUser: redditAuthenticatedUser, redditSubredditCollection: redditSubredditCollection, redditLinkCollection: redditLinkCollection); DashboardSettingsViewModel dashboardSettingsViewModel = CreateDashboardSettingsViewModel(); ObjectViewModel <IRedditAuthenticatedUser> objectViewModelForRedditAuthenticatedUser = CreateObjectViewModel <IRedditAuthenticatedUser>(redditAuthenticatedUser, DateTime.Now.AddDays(_random.Next(1, 365) * -1).AddMinutes(_random.Next(-120, 120))); IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut(dashboardSettingsViewModel: dashboardSettingsViewModel, objectViewModelForRedditAuthenticatedUser: objectViewModelForRedditAuthenticatedUser); DashboardViewModel result = await sut.BuildAsync(dashboard); _cookieHelperMock.Verify(m => m.ToCookie(It.Is <DashboardViewModel>(value => value == result)), Times.Once); }
public async Task BuildAsync_WhenCalled_ReturnsInitializedObjectViewModel() { string identifier = Guid.NewGuid().ToString("D"); DateTime createdTime = DateTime.Now.AddDays(_random.Next(1, 365) * -1).AddMinutes(_random.Next(-120, 120)); string userName = Guid.NewGuid().ToString("D"); int commentKarma = GetKarmaValue(); int linkKarma = GetKarmaValue(); bool hasUnreadMail = _random.Next(1, 100) > 50; IRedditAuthenticatedUser redditAuthenticatedUser = CreateRedditAuthenticatedUser(identifier, createdTime, userName, commentKarma, linkKarma, hasUnreadMail); IViewModelBuilder <ObjectViewModel <IRedditAuthenticatedUser>, IRedditAuthenticatedUser> sut = CreateSut(); ObjectViewModel <IRedditAuthenticatedUser> result = await sut.BuildAsync(redditAuthenticatedUser); Assert.IsNotNull(result); Assert.IsNotNull(result.ObjectIdentifier); Assert.AreEqual(identifier, result.ObjectIdentifier); Assert.IsNotNull(result.Object); Assert.AreEqual(redditAuthenticatedUser, result.Object); Assert.AreEqual(createdTime, result.Timestamp); Assert.IsNotNull(result.Html); Assert.AreEqual(GetExpectedHtml(userName, commentKarma, linkKarma, hasUnreadMail), result.Html); }
private Mock <IDashboard> CreateDashboardMock(IEnumerable <INews> newsCollection = null, IEnumerable <ISystemError> systemErrorCollection = null, IDashboardSettings dashboardSettings = null, IRedditAuthenticatedUser redditAuthenticatedUser = null, IEnumerable <IRedditSubreddit> redditSubredditCollection = null, IEnumerable <IRedditLink> redditLinkCollection = null, IDashboardRules dashboardRules = null) { Mock <IDashboard> dashboardMock = new Mock <IDashboard>(); dashboardMock.Setup(m => m.News) .Returns(newsCollection ?? CreateNewsCollection(_random.Next(50, 100))); dashboardMock.Setup(m => m.SystemErrors) .Returns(systemErrorCollection ?? CreateSystemErrorCollection(_random.Next(5, 10))); dashboardMock.Setup(m => m.Settings) .Returns(dashboardSettings); dashboardMock.Setup(m => m.RedditAuthenticatedUser) .Returns(redditAuthenticatedUser); dashboardMock.Setup(m => m.RedditSubreddits) .Returns(redditSubredditCollection ?? CreateRedditSubredditCollection(_random.Next(10, 25))); dashboardMock.Setup(m => m.RedditLinks) .Returns(redditLinkCollection ?? CreateRedditLinkCollection(_random.Next(50, 100))); dashboardMock.Setup(m => m.Rules) .Returns(dashboardRules ?? CreateDashboardRules()); return(dashboardMock); }
private IDashboard CreateDashboard(IEnumerable <INews> newsCollection = null, IEnumerable <ISystemError> systemErrorCollection = null, IDashboardSettings dashboardSettings = null, IRedditAuthenticatedUser redditAuthenticatedUser = null, IEnumerable <IRedditSubreddit> redditSubredditCollection = null, IEnumerable <IRedditLink> redditLinkCollection = null, IDashboardRules dashboardRules = null) { return(CreateDashboardMock(newsCollection, systemErrorCollection, dashboardSettings, redditAuthenticatedUser, redditSubredditCollection, redditLinkCollection, dashboardRules).Object); }
private IDashboardRules CreateSut(IRedditAuthenticatedUser redditAuthenticatedUser) { return(new OSDevGrp.MyDashboard.Core.Models.DashboardRules(redditAuthenticatedUser)); }
private Mock <IRedditResponse <IRedditAuthenticatedUser> > CreateRedditResponseMock(int?rateLimitUsed = null, int?rateLimitRemaining = null, DateTime?rateLimitResetTime = null, DateTime?receivedTime = null, IRedditAuthenticatedUser redditAuthenticatedUser = null) { Mock <IRedditResponse <IRedditAuthenticatedUser> > redditResponseMock = new Mock <IRedditResponse <IRedditAuthenticatedUser> >(); redditResponseMock.Setup(m => m.RateLimitUsed) .Returns(rateLimitUsed ?? _random.Next(1, 60)); redditResponseMock.Setup(m => m.RateLimitRemaining) .Returns(rateLimitRemaining ?? _random.Next(1, 60)); redditResponseMock.Setup(m => m.RateLimitResetTime) .Returns(rateLimitResetTime ?? DateTime.Now.AddSeconds(_random.Next(30, 60))); redditResponseMock.Setup(m => m.ReceivedTime) .Returns(receivedTime ?? DateTime.Now.AddSeconds(_random.Next(1, 10) * -1)); redditResponseMock.Setup(m => m.Data) .Returns(redditAuthenticatedUser ?? CreateRedditAuthenticatedUser()); return(redditResponseMock); }
private IRedditResponse <IRedditAuthenticatedUser> CreateRedditResponse(int?rateLimitUsed = null, int?rateLimitRemaining = null, DateTime?rateLimitResetTime = null, DateTime?receivedTime = null, IRedditAuthenticatedUser redditAuthenticatedUser = null) { return(CreateRedditResponseMock(rateLimitUsed, rateLimitRemaining, rateLimitResetTime, receivedTime, redditAuthenticatedUser).Object); }
private IDashboard BuildDashboard(bool hasNews = true, IEnumerable <INews> newsCollection = null, bool hasRedditAuthenticatedUser = true, IRedditAuthenticatedUser redditAuthenticatedUser = null, bool hasRedditSubreddits = true, IEnumerable <IRedditSubreddit> redditSubredditCollection = null, bool hasRedditLinks = true, IEnumerable <IRedditLink> redditLinkCollection = null) { return(BuildDashboardMock(hasNews, newsCollection, hasRedditAuthenticatedUser, redditAuthenticatedUser, hasRedditSubreddits, redditSubredditCollection, hasRedditLinks, redditLinkCollection).Object); }
public DashboardRules(IRedditAuthenticatedUser redditAuthenticatedUser) { _redditAuthenticatedUser = redditAuthenticatedUser; }
private Mock <IDashboard> BuildDashboardMock(bool hasNews = true, IEnumerable <INews> newsCollection = null, bool hasRedditAuthenticatedUser = true, IRedditAuthenticatedUser redditAuthenticatedUser = null, bool hasRedditSubreddits = true, IEnumerable <IRedditSubreddit> redditSubredditCollection = null, bool hasRedditLinks = true, IEnumerable <IRedditLink> redditLinkCollection = null) { Mock <IDashboard> dashboardMock = new Mock <IDashboard>(); dashboardMock.Setup(m => m.News) .Returns(hasNews ? newsCollection ?? BuildNewsCollection() : null); dashboardMock.Setup(m => m.RedditAuthenticatedUser) .Returns(hasRedditAuthenticatedUser ? redditAuthenticatedUser ?? BuildRedditAuthenticatedUser() : null); dashboardMock.Setup(m => m.RedditSubreddits) .Returns(hasRedditSubreddits ? redditSubredditCollection ?? BuildRedditSubredditCollection() : null); dashboardMock.Setup(m => m.RedditLinks) .Returns(hasRedditLinks ? redditLinkCollection ?? BuildRedditLinkCollection() : null); return(dashboardMock); }