コード例 #1
0
        public void GetStarsTitleText_InvalidRefreshState(RefreshState refreshState, double totalStars)
        {
            //Arrange

            //Act

            //Assert
            Assert.Throws <NotSupportedException>(() => EmptyDataViewService.GetStarsTitleText(refreshState, totalStars));
        }
コード例 #2
0
        public void GetStarsTitleText_ValidRefreshState(RefreshState refreshState, double totalStars, string expectedResult)
        {
            //Arrange
            string actualResult;

            //Act
            actualResult = EmptyDataViewService.GetStarsTitleText(refreshState, totalStars);

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
コード例 #3
0
        public async Task FetchDataCommandTest_AuthenticatedUser(bool shouldIncludeViewsClonesData)
        {
            //Arrange
            Repository repository;

            double dailyViewsClonesMinValue_Initial, dailyViewsClonesMinValue_Final;
            double dailyViewsClonesMaxValue_Initial, dailyViewsClonesMaxValue_Final;

            double minDailyStarsValue_Initial, minDailyStarsValue_Final;
            double maxDailyStarsValue_Initial, maxDailyStarsValue_Final;

            string viewsClonesEmptyDataViewTitleText_Initial, viewsClonesEmptyDataViewTitleText_Final;
            string starsEmptyDataViewTitleText_Initial, starsEmptyDataViewTitleText_Final;

            bool isViewsClonesChartVisible_Initial, isViewsClonesChartVisible_DuringFetchDataCommand, isViewsClonesChartVisible_Final;
            bool isStarsChartVisible_Initial, isStarsChartVisible_DuringFetchDataCommand, isStarsChartVisible_Final;

            bool isFetchingData_Initial, isFetchingData_DuringFetchDataCommand, isFetchingData_Final;

            bool isViewsClonesEmptyDataViewVisible_Initial, isViewsClonesEmptyDataViewVisible_DuringFetchDataCommand, isViewsClonesEmptyDataViewVisible_Final;
            bool isStarsEmptyDataViewVisible_Initial, isStarsEmptyDataViewVisible_DuringFetchDataCommand, isStarsEmptyDataViewVisible_Final;

            DateTime minViewsClonesDate_Initial, minViewsClonesDate_Final;
            DateTime maxViewsClonesDate_Initial, maxViewsClonesDate_Final;

            DateTime minDailyStarsDate_Initial, minDailyStarsDate_Final;
            DateTime maxDailyStarsDate_Initial, maxDailyStarsDate_Final;

            IReadOnlyList <DailyStarsModel>  dailyStarsList_Initial, dailyStarsList_Final;
            IReadOnlyList <DailyViewsModel>  dailyViewsList_Initial, dailyViewsList_Final;
            IReadOnlyList <DailyClonesModel> dailyClonesList_Initial, dailyClonesList_Final;

            var trendsViewModel = ServiceCollection.ServiceProvider.GetRequiredService <TrendsViewModel>();

            var gitHubUserService            = ServiceCollection.ServiceProvider.GetRequiredService <GitHubUserService>();
            var gitHubGraphQLApiService      = ServiceCollection.ServiceProvider.GetRequiredService <GitHubGraphQLApiService>();
            var gitHubApiRepositoriesService = ServiceCollection.ServiceProvider.GetRequiredService <GitHubApiRepositoriesService>();


            await AuthenticateUser(gitHubUserService, gitHubGraphQLApiService).ConfigureAwait(false);

            repository = await gitHubGraphQLApiService.GetRepository(GitHubConstants.GitTrendsRepoOwner, GitHubConstants.GitTrendsRepoName, CancellationToken.None);

            if (shouldIncludeViewsClonesData)
            {
                await foreach (var completedReposiory in gitHubApiRepositoriesService.UpdateRepositoriesWithViewsClonesAndStarsData(new[] { repository }, CancellationToken.None).ConfigureAwait(false))
                {
                    repository = completedReposiory;
                }
            }

            //Act
            isFetchingData_Initial                    = trendsViewModel.IsFetchingData;
            dailyStarsList_Initial                    = trendsViewModel.DailyStarsList;
            dailyViewsList_Initial                    = trendsViewModel.DailyViewsList;
            dailyClonesList_Initial                   = trendsViewModel.DailyClonesList;
            maxDailyStarsDate_Initial                 = trendsViewModel.MaxDailyStarsDate;
            minDailyStarsDate_Initial                 = trendsViewModel.MinDailyStarsDate;
            minDailyStarsValue_Initial                = trendsViewModel.MinDailyStarsValue;
            maxDailyStarsValue_Initial                = trendsViewModel.MaxDailyStarsValue;
            minViewsClonesDate_Initial                = trendsViewModel.MinViewsClonesDate;
            maxViewsClonesDate_Initial                = trendsViewModel.MaxViewsClonesDate;
            isStarsChartVisible_Initial               = trendsViewModel.IsStarsChartVisible;
            dailyViewsClonesMinValue_Initial          = trendsViewModel.DailyViewsClonesMinValue;
            dailyViewsClonesMaxValue_Initial          = trendsViewModel.DailyViewsClonesMaxValue;
            isViewsClonesChartVisible_Initial         = trendsViewModel.IsViewsClonesChartVisible;
            starsEmptyDataViewTitleText_Initial       = trendsViewModel.StarsEmptyDataViewTitleText;
            isStarsEmptyDataViewVisible_Initial       = trendsViewModel.IsStarsEmptyDataViewVisible;
            viewsClonesEmptyDataViewTitleText_Initial = trendsViewModel.ViewsClonesEmptyDataViewTitleText;
            isViewsClonesEmptyDataViewVisible_Initial = trendsViewModel.IsViewsClonesEmptyDataViewVisible;

            var fetchDataCommandTask = trendsViewModel.FetchDataCommand.ExecuteAsync((repository, CancellationToken.None));

            isFetchingData_DuringFetchDataCommand                    = trendsViewModel.IsFetchingData;
            isStarsChartVisible_DuringFetchDataCommand               = trendsViewModel.IsStarsChartVisible;
            isViewsClonesChartVisible_DuringFetchDataCommand         = trendsViewModel.IsViewsClonesChartVisible;
            isStarsEmptyDataViewVisible_DuringFetchDataCommand       = trendsViewModel.IsStarsEmptyDataViewVisible;
            isViewsClonesEmptyDataViewVisible_DuringFetchDataCommand = trendsViewModel.IsViewsClonesEmptyDataViewVisible;

            await fetchDataCommandTask.ConfigureAwait(false);

            isFetchingData_Final                    = trendsViewModel.IsFetchingData;
            dailyStarsList_Final                    = trendsViewModel.DailyStarsList;
            dailyViewsList_Final                    = trendsViewModel.DailyViewsList;
            dailyClonesList_Final                   = trendsViewModel.DailyClonesList;
            maxDailyStarsDate_Final                 = trendsViewModel.MaxDailyStarsDate;
            minDailyStarsDate_Final                 = trendsViewModel.MinDailyStarsDate;
            minDailyStarsValue_Final                = trendsViewModel.MinDailyStarsValue;
            maxDailyStarsValue_Final                = trendsViewModel.MaxDailyStarsValue;
            isStarsChartVisible_Final               = trendsViewModel.IsStarsChartVisible;
            minViewsClonesDate_Final                = trendsViewModel.MinViewsClonesDate;
            maxViewsClonesDate_Final                = trendsViewModel.MaxViewsClonesDate;
            dailyViewsClonesMinValue_Final          = trendsViewModel.DailyViewsClonesMinValue;
            dailyViewsClonesMaxValue_Final          = trendsViewModel.DailyViewsClonesMaxValue;
            isViewsClonesChartVisible_Final         = trendsViewModel.IsViewsClonesChartVisible;
            starsEmptyDataViewTitleText_Final       = trendsViewModel.StarsEmptyDataViewTitleText;
            isStarsEmptyDataViewVisible_Final       = trendsViewModel.IsStarsEmptyDataViewVisible;
            viewsClonesEmptyDataViewTitleText_Final = trendsViewModel.ViewsClonesEmptyDataViewTitleText;
            isViewsClonesEmptyDataViewVisible_Final = trendsViewModel.IsViewsClonesEmptyDataViewVisible;

            //Assert
            Assert.IsEmpty(dailyViewsList_Initial);
            Assert.IsEmpty(dailyClonesList_Initial);
            Assert.IsEmpty(dailyStarsList_Initial);

            Assert.IsNotEmpty(dailyViewsList_Final);
            Assert.IsNotEmpty(dailyClonesList_Final);
            Assert.IsNotEmpty(dailyStarsList_Final);

            Assert.IsTrue(isFetchingData_Initial);
            Assert.IsTrue(isFetchingData_DuringFetchDataCommand);
            Assert.IsFalse(isFetchingData_Final);

            Assert.IsFalse(isViewsClonesEmptyDataViewVisible_Initial);
            Assert.IsFalse(isViewsClonesEmptyDataViewVisible_DuringFetchDataCommand);
            Assert.IsFalse(isViewsClonesEmptyDataViewVisible_Final);

            Assert.IsFalse(isStarsEmptyDataViewVisible_Initial);
            Assert.IsFalse(isStarsEmptyDataViewVisible_DuringFetchDataCommand);
            Assert.IsFalse(isStarsEmptyDataViewVisible_Final);

            Assert.IsFalse(isViewsClonesChartVisible_Initial);
            Assert.IsFalse(isViewsClonesChartVisible_DuringFetchDataCommand);
            Assert.True(isViewsClonesChartVisible_Final);

            Assert.IsFalse(isStarsChartVisible_Initial);
            Assert.IsFalse(isStarsChartVisible_DuringFetchDataCommand);
            Assert.True(isStarsChartVisible_Final);

            Assert.AreEqual(TrendsViewModel.MinimumChartHeight, dailyViewsClonesMaxValue_Initial);
            Assert.GreaterOrEqual(dailyViewsClonesMaxValue_Final, dailyViewsClonesMaxValue_Initial);

            Assert.AreEqual(TrendsViewModel.MinimumChartHeight, maxDailyStarsValue_Initial);
            Assert.GreaterOrEqual(maxDailyStarsValue_Final, maxDailyStarsValue_Initial);

            Assert.AreEqual(0, dailyViewsClonesMinValue_Initial);
            Assert.AreEqual(dailyViewsClonesMinValue_Final, dailyViewsClonesMinValue_Initial);

            Assert.AreEqual(0, minDailyStarsValue_Initial);
            Assert.AreEqual(minDailyStarsValue_Final, minDailyStarsValue_Initial);

            Assert.AreEqual(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromDays(13)).Date, minViewsClonesDate_Initial.Date);
            Assert.LessOrEqual(minViewsClonesDate_Final.Date, minViewsClonesDate_Initial.Date);

            Assert.AreEqual(DateTimeOffset.UtcNow.Date, maxViewsClonesDate_Initial.Date);
            Assert.LessOrEqual(maxViewsClonesDate_Final.Date, maxViewsClonesDate_Initial.Date);

            Assert.LessOrEqual(minDailyStarsDate_Final.Date, minDailyStarsDate_Initial.Date);
            Assert.LessOrEqual(maxDailyStarsDate_Final.Date, maxDailyStarsDate_Initial.Date);

            Assert.AreEqual(EmptyDataViewService.GetViewsClonesTitleText(RefreshState.Uninitialized), viewsClonesEmptyDataViewTitleText_Initial);
            Assert.AreEqual(EmptyDataViewService.GetViewsClonesTitleText(RefreshState.Succeeded), viewsClonesEmptyDataViewTitleText_Final);

            Assert.AreEqual(EmptyDataViewService.GetStarsTitleText(RefreshState.Uninitialized, trendsViewModel.TotalStars), starsEmptyDataViewTitleText_Initial);
            Assert.AreEqual(EmptyDataViewService.GetStarsTitleText(RefreshState.Succeeded, trendsViewModel.TotalStars), starsEmptyDataViewTitleText_Final);
        }