Beispiel #1
0
        public async Task BuildAsync_WhenCalled_AssertReadAsyncWasCalledOnHttpHelperForEachLatestInformationWithImageInDashboard()
        {
            List <INews>       newsCollection       = CreateNewsCollection(_random.Next(50, 75)).ToList();
            List <IRedditLink> redditLinkCollection = CreateRedditLinkCollection(_random.Next(50, 75)).ToList();
            IDashboard         dashboard            = CreateDashboard(newsCollection: newsCollection, redditLinkCollection: redditLinkCollection);

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            DashboardViewModel dashboardViewModel = await sut.BuildAsync(dashboard);

            int numberOfInformationWithImage = Math.Min(dashboardViewModel.Informations.Count(information => string.IsNullOrWhiteSpace(information.ImageUrl) == false), 7);

            if (numberOfInformationWithImage > 0)
            {
                _httpHelperMock.Verify(m => m.ReadAsync(It.IsAny <Uri>()), Times.Exactly(numberOfInformationWithImage));
            }
            else
            {
                _httpHelperMock.Verify(m => m.ReadAsync(It.IsAny <Uri>()), Times.Never);
            }

            foreach (ImageViewModel <InformationViewModel> latestInformationWithImage in dashboardViewModel.LatestInformationsWithImage)
            {
                _httpHelperMock.Verify(m => m.ReadAsync(It.Is <Uri>(value => string.Compare(latestInformationWithImage.ViewModel.ImageUrl, value.AbsoluteUri, false) == 0)), Times.Once);
            }
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        public async Task BuildAsync_WhenCalledAndRedditLinkToInformationViewModelBuilderThrowsAggregateException_AddsExceptionToSystemViewModelsInDashboardViewModel()
        {
            IEnumerable <INews>            newsCollection            = CreateNewsCollection(0);
            IEnumerable <ISystemError>     systemErrorCollection     = CreateSystemErrorCollection(0);
            IEnumerable <IRedditSubreddit> redditSubredditCollection = CreateRedditSubredditCollection(0);
            IEnumerable <IRedditLink>      redditLinkCollection      = CreateRedditLinkCollection(1);
            IDashboard dashboard = CreateDashboard(newsCollection: newsCollection, systemErrorCollection: systemErrorCollection, 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);
        }
Beispiel #4
0
        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           displayNamePrefixed     = Guid.NewGuid().ToString("D");
            string           publicDescriptionAsText = _random.Next(1, 100) > 50 ? Guid.NewGuid().ToString() : null;
            long             subscribers             = _random.Next(2500, 5000);
            Uri              url             = _random.Next(1, 100) > 50 ? new Uri($"http://locahost/{Guid.NewGuid().ToString("D")}") : null;
            Uri              bannerImageUrl  = _random.Next(1, 100) > 50 ? new Uri($"http://locahost/{Guid.NewGuid().ToString("D")}.png") : null;
            Uri              headerImageUrl  = _random.Next(1, 100) > 50 ? new Uri($"http://locahost/{Guid.NewGuid().ToString("D")}.png") : null;
            IRedditSubreddit redditSubreddit = CreateRedditSubreddit(identifier, createdTime, displayNamePrefixed, publicDescriptionAsText, subscribers, url, bannerImageUrl, headerImageUrl);

            IViewModelBuilder <ObjectViewModel <IRedditSubreddit>, IRedditSubreddit> sut = CreateSut();

            ObjectViewModel <IRedditSubreddit> result = await sut.BuildAsync(redditSubreddit);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.ObjectIdentifier);
            Assert.AreEqual(identifier, result.ObjectIdentifier);
            Assert.IsNotNull(result.Object);
            Assert.AreEqual(redditSubreddit, result.Object);
            Assert.AreEqual(createdTime, result.Timestamp);
            Assert.IsNotNull(result.Html);
            Assert.AreEqual(GetExpectedHtml(displayNamePrefixed, publicDescriptionAsText, subscribers, url, bannerImageUrl ?? headerImageUrl), result.Html);
        }
Beispiel #5
0
        public async Task BuildAsync_WhenCalled_AssertInformationWasCalledOnNews()
        {
            Mock <INews> newsMock = CreateNewsMock();

            IViewModelBuilder <InformationViewModel, INews> sut = CreateSut();

            await sut.BuildAsync(newsMock.Object);

            newsMock.Verify(m => m.Information, Times.Once);
        }
Beispiel #6
0
        public async Task BuildAsync_WhenCalled_AssertDetailsWasCalledOnSystemError()
        {
            Mock <ISystemError> systemErrorMock = CreateSystemErrorMock();

            IViewModelBuilder <SystemErrorViewModel, ISystemError> sut = CreateSut();

            await sut.BuildAsync(systemErrorMock.Object);

            systemErrorMock.Verify(m => m.Details, Times.Once);
        }
Beispiel #7
0
        public async Task BuildAsync_WhenCalled_AssertUrlWasCalledOnRedditSubreddit()
        {
            Mock <IRedditSubreddit> redditSubredditMock = CreateRedditSubredditMock();

            IViewModelBuilder <ObjectViewModel <IRedditSubreddit>, IRedditSubreddit> sut = CreateSut();

            await sut.BuildAsync(redditSubredditMock.Object);

            redditSubredditMock.Verify(m => m.Url, Times.Once);
        }
Beispiel #8
0
        public async Task BuildAsync_WhenCalled_AssertIncludeNsfwContentWasCalledOnDashboardSettings()
        {
            Mock <IDashboardSettings> dashboardSettingsMock = CreateDashboardSettingsMock();

            IViewModelBuilder <DashboardSettingsViewModel, IDashboardSettings> sut = CreateSut();

            await sut.BuildAsync(dashboardSettingsMock.Object);

            dashboardSettingsMock.Verify(m => m.IncludeNsfwContent, Times.Once());
        }
Beispiel #9
0
        public async Task BuildAsync_WhenCalled_AssertHasUnreadMailWasCalledOnRedditAuthenticatedUser()
        {
            Mock <IRedditAuthenticatedUser> redditAuthenticatedUserMock = CreateRedditAuthenticatedUserMock();

            IViewModelBuilder <ObjectViewModel <IRedditAuthenticatedUser>, IRedditAuthenticatedUser> sut = CreateSut();

            await sut.BuildAsync(redditAuthenticatedUserMock.Object);

            redditAuthenticatedUserMock.Verify(m => m.HasUnreadMail, Times.Once);
        }
Beispiel #10
0
        public async Task BuildAsync_WhenCalled_AssertSubredditWasCalledOnRedditLink()
        {
            Mock <IRedditLink> redditLinkMock = CreateRedditLinkMock();

            IViewModelBuilder <InformationViewModel, IRedditLink> sut = CreateSut();

            await sut.BuildAsync(redditLinkMock.Object);

            redditLinkMock.Verify(m => m.Subreddit, Times.Once);
        }
Beispiel #11
0
        public async Task BuildAsync_WhenCalled_AssertSystemErrorsWasCalledOnDashboardOnce()
        {
            Mock <IDashboard> dashboardMock = CreateDashboardMock();

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            await sut.BuildAsync(dashboardMock.Object);

            dashboardMock.Verify(m => m.SystemErrors, Times.Once);
        }
Beispiel #12
0
        public async Task BuildAsync_WhenCalled_AssertRedditAccessTokenWasCalledOnDashboardSettings()
        {
            Mock <IDashboardSettings> dashboardSettingsMock = CreateDashboardSettingsMock();

            IViewModelBuilder <DashboardSettingsViewModel, IDashboardSettings> sut = CreateSut();

            await sut.BuildAsync(dashboardSettingsMock.Object);

            dashboardSettingsMock.Verify(m => m.RedditAccessToken, Times.Once());
        }
Beispiel #13
0
        public async Task BuildAsync_WhenCalled_AssertConvertNewLinesWasCalledOnHtmlHelperWithInformation()
        {
            string       information = Guid.NewGuid().ToString("D");
            ISystemError systemError = CreateSystemError(information: information);

            IViewModelBuilder <SystemErrorViewModel, ISystemError> sut = CreateSut();

            await sut.BuildAsync(systemError);

            _htmlHelperMock.Verify(m => m.ConvertNewLines(It.Is <string>(value => string.Compare(value, information, false) == 0)), Times.Once);
        }
Beispiel #14
0
        public async Task BuildAsync_WhenCalled_AssertNameWasCalledOnProvider()
        {
            Mock <INewsProvider> provider = CreateNewsProviderMock();
            INews news = CreateNews(provider: provider.Object);

            IViewModelBuilder <InformationViewModel, INews> sut = CreateSut();

            await sut.BuildAsync(news);

            provider.Verify(m => m.Name, Times.Once);
        }
Beispiel #15
0
        public async Task BuildAsync_WhenCalledWhereNewsHasAuthor_AssertNameWasCalledOnAuthor()
        {
            Mock <IAuthor> authorMock = CreateAuthorMock();
            INews          news       = CreateNews(author: authorMock.Object);

            IViewModelBuilder <InformationViewModel, INews> sut = CreateSut();

            await sut.BuildAsync(news);

            authorMock.Verify(m => m.Name, Times.Once);
        }
Beispiel #16
0
        public async Task BuildAsync_WhenCalled_AssertBuildAsyncWasCalledOnRedditLinkToInformationViewModelBuilderForEachRedditLinkInDashboard()
        {
            List <IRedditLink> redditLinkCollection = CreateRedditLinkCollection(_random.Next(50, 75)).ToList();
            IDashboard         dashboard            = CreateDashboard(redditLinkCollection: redditLinkCollection);

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            await sut.BuildAsync(dashboard);

            redditLinkCollection.ForEach(redditLink => _redditLinkToInformationViewModelBuilderMock.Verify(m => m.BuildAsync(It.Is <IRedditLink>(value => value == redditLink)), Times.Once));
        }
Beispiel #17
0
        public async Task BuildAsync_WhenCalledWithRedditLinkWhereImagesIsNull_AssertThumbnailUrlWasCalledOnRedditLink()
        {
            const IEnumerable <IRedditImage> redditImages = null;
            Mock <IRedditLink> redditLinkMock             = CreateRedditLinkMock(redditImages: redditImages);

            IViewModelBuilder <InformationViewModel, IRedditLink> sut = CreateSut();

            await sut.BuildAsync(redditLinkMock.Object);

            redditLinkMock.Verify(m => m.ThumbnailUrl, Times.Once);
        }
Beispiel #18
0
        public async Task BuildAsync_WhenCalledWhereRedditAccessTokenIsNotNull_AssertToBase64WasCalledOnRedditAccessToken()
        {
            Mock <IRedditAccessToken> redditAccessTokenMock = CreateRedditAccessTokenMock();
            IDashboardSettings        dashboardSettings     = CreateDashboardSettings(redditAccessToken: redditAccessTokenMock.Object);

            IViewModelBuilder <DashboardSettingsViewModel, IDashboardSettings> sut = CreateSut();

            await sut.BuildAsync(dashboardSettings);

            redditAccessTokenMock.Verify(m => m.ToBase64(), Times.Once());
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        public async Task BuildAsync_WhenCalled_AssertBuildAsyncWasCalledOnNewsToInformationViewModelBuilderForEachNewsInDashboard()
        {
            List <INews> newsCollection = CreateNewsCollection(_random.Next(50, 75)).ToList();
            IDashboard   dashboard      = CreateDashboard(newsCollection: newsCollection);

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            await sut.BuildAsync(dashboard);

            newsCollection.ForEach(news => _newsToInformationViewModelBuilderMock.Verify(m => m.BuildAsync(It.Is <INews>(value => value == news)), Times.Once));
        }
Beispiel #21
0
        public async Task BuildAsync_WhenCalled_AssertConvertWasCalledOnHtmlHelperWithInformation()
        {
            string information = Guid.NewGuid().ToString("D");
            INews  news        = CreateNews(information: information);

            IViewModelBuilder <InformationViewModel, INews> sut = CreateSut();

            await sut.BuildAsync(news);

            _htmlHelperMock.Verify(m => m.Convert(It.Is <string>(value => value == information), It.Is <bool>(value => value == false), It.Is <bool>(value => value == true)), Times.Once);
        }
Beispiel #22
0
        public async Task BuildAsync_WhenCalledWhereRedditSubredditDoesNotHaveBannerImageUrl_AssertHeaderImageUrlWasCalledOnRedditSubreddit()
        {
            const Uri bannerImageUrl = null;
            Mock <IRedditSubreddit> redditSubredditMock = CreateRedditSubredditMock(bannerImageUrl: bannerImageUrl);

            IViewModelBuilder <ObjectViewModel <IRedditSubreddit>, IRedditSubreddit> sut = CreateSut();

            await sut.BuildAsync(redditSubredditMock.Object);

            redditSubredditMock.Verify(m => m.HeaderImageUrl, Times.Once);
        }
Beispiel #23
0
        public async Task BuildAsync_WhenCalledWhereRedditSubredditHasBannerImageUrl_AssertHeaderImageUrlWasNotCalledOnRedditSubreddit()
        {
            Uri bannerImageUrl = new Uri($"http://locahost/{Guid.NewGuid().ToString("D")}.png");
            Mock <IRedditSubreddit> redditSubredditMock = CreateRedditSubredditMock(bannerImageUrl: bannerImageUrl);

            IViewModelBuilder <ObjectViewModel <IRedditSubreddit>, IRedditSubreddit> sut = CreateSut();

            await sut.BuildAsync(redditSubredditMock.Object);

            redditSubredditMock.Verify(m => m.HeaderImageUrl, Times.Never);
        }
Beispiel #24
0
        public async Task BuildAsync_WhenCalledWithRedditLinkWhereImagesIsNotEmpty_AssertThumbnailUrlWasNotCalledOnRedditLink()
        {
            IEnumerable <IRedditImage> redditImages   = CreateRedditImageCollection();
            Mock <IRedditLink>         redditLinkMock = CreateRedditLinkMock(redditImages: redditImages);

            IViewModelBuilder <InformationViewModel, IRedditLink> sut = CreateSut();

            await sut.BuildAsync(redditLinkMock.Object);

            redditLinkMock.Verify(m => m.ThumbnailUrl, Times.Never);
        }
Beispiel #25
0
        public async Task BuildAsync_WhenCalled_AssertSettingsWasCalledOnDashboardOnce()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();
            Mock <IDashboard>  dashboardMock     = CreateDashboardMock(dashboardSettings: dashboardSettings);

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            await sut.BuildAsync(dashboardMock.Object);

            dashboardMock.Verify(m => m.Settings, Times.Once);
        }
Beispiel #26
0
        public async Task BuildAsync_WhenCalled_AssertBuildAsyncWasCalledOnSystemErrorViewModelBuilderForEachSystemErrorInDashboard()
        {
            List <ISystemError> systemErrorCollection = CreateSystemErrorCollection(_random.Next(50, 75)).ToList();
            IDashboard          dashboard             = CreateDashboard(systemErrorCollection: systemErrorCollection);

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            await sut.BuildAsync(dashboard);

            systemErrorCollection.ForEach(systemError => _systemErrorViewModelBuilderMock.Verify(m => m.BuildAsync(It.Is <ISystemError>(value => value == systemError)), Times.Once));
        }
Beispiel #27
0
        public async Task BuildAsync_WhenCalled_AssertBuildAsyncWasCalledOnDashboardSettingsViewModelBuilderWithSettingsInDashboard()
        {
            IDashboardSettings dashboardSettings = CreateDashboardSettings();
            IDashboard         dashboard         = CreateDashboard(dashboardSettings: dashboardSettings);

            IViewModelBuilder <DashboardViewModel, IDashboard> sut = CreateSut();

            await sut.BuildAsync(dashboard);

            _dashboardSettingsViewModelBuilderMock.Verify(m => m.BuildAsync(It.Is <IDashboardSettings>(value => value == dashboardSettings)), Times.Once);
        }
Beispiel #28
0
        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);
        }
Beispiel #29
0
        public async Task BuildAsync_WhenCalled_AssertLinkKarmaWasCalledOnRedditAuthenticatedUser()
        {
            int linkKarma = GetKarmaValue();
            Mock <IRedditAuthenticatedUser> redditAuthenticatedUserMock = CreateRedditAuthenticatedUserMock(linkKarma: linkKarma);

            IViewModelBuilder <ObjectViewModel <IRedditAuthenticatedUser>, IRedditAuthenticatedUser> sut = CreateSut();

            await sut.BuildAsync(redditAuthenticatedUserMock.Object);

            redditAuthenticatedUserMock.Verify(m => m.LinkKarma, Times.Once);
        }
Beispiel #30
0
        public async Task BuildAsync_WhenCalledWithRedditLinkWithRedditSubreddit_AssertDisplayNamePrefixedWasCalledOnRedditSubreddit()
        {
            Mock <IRedditSubreddit> redditSubredditMock = CreateRedditSubredditMock(Guid.NewGuid().ToString("D"));
            IRedditLink             redditLink          = CreateRedditLink(redditSubreddit: redditSubredditMock.Object);

            IViewModelBuilder <InformationViewModel, IRedditLink> sut = CreateSut();

            await sut.BuildAsync(redditLink);

            redditSubredditMock.Verify(m => m.DisplayNamePrefixed, Times.Once);
        }