public void GetRepositoryTitleDescriptionTest_InvalidRefreshState(RefreshState refreshState, bool isRepositoryListEmpty)
        {
            //Arrange

            //Act

            //Assert
            Assert.Throws <NotSupportedException>(() => EmptyDataViewService.GetRepositoryDescriptionText(refreshState, isRepositoryListEmpty));
        }
        protected async Task ExecutePullToRefreshCommandTestAbuseLimit()
        {
            //Arrange
            PullToRefreshFailedEventArgs pullToRefreshFailedEventArgs;
            IReadOnlyList <Repository>   visibleRepositoryList_Initial, visibleRepositoryList_Final;

            int gitHubApiAbuseLimitCount_Initial, gitHubApiAbuseLimitCount_Final;

            string emptyDataViewTitle_Initial, emptyDataViewTitle_Final;
            string emptyDataViewDescription_Initial, emptyDataViewDescription_Final;

            var gitHubUserService       = ServiceCollection.ServiceProvider.GetRequiredService <GitHubUserService>();
            var repositoryViewModel     = ServiceCollection.ServiceProvider.GetRequiredService <RepositoryViewModel>();
            var gitHubGraphQLApiService = ServiceCollection.ServiceProvider.GetRequiredService <GitHubGraphQLApiService>();

            var pullToRefreshFailedTCS = new TaskCompletionSource <PullToRefreshFailedEventArgs>();

            RepositoryViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;

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

            gitHubApiAbuseLimitCount_Initial = gitHubUserService.GitHubApiAbuseLimitCount;

            emptyDataViewTitle_Initial       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Initial    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Initial = repositoryViewModel.EmptyDataViewDescription;

            await repositoryViewModel.PullToRefreshCommand.ExecuteAsync().ConfigureAwait(false);

            emptyDataViewTitle_Final       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Final    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Final = repositoryViewModel.EmptyDataViewDescription;

            pullToRefreshFailedEventArgs = await pullToRefreshFailedTCS.Task.ConfigureAwait(false);

            gitHubApiAbuseLimitCount_Final = gitHubUserService.GitHubApiAbuseLimitCount;

            //Assert
            Assert.IsEmpty(visibleRepositoryList_Initial);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Uninitialized, true), emptyDataViewTitle_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.AbuseLimit, !visibleRepositoryList_Final.Any()), emptyDataViewTitle_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Uninitialized, true), emptyDataViewDescription_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.AbuseLimit, !visibleRepositoryList_Final.Any()), emptyDataViewDescription_Final);

            Assert.IsInstanceOf <AbuseLimitPullToRefreshEventArgs>(pullToRefreshFailedEventArgs);
            Assert.AreEqual(0, gitHubApiAbuseLimitCount_Initial);
            Assert.Greater(gitHubApiAbuseLimitCount_Final, 0);

            void HandlePullToRefreshFailed(object?sender, PullToRefreshFailedEventArgs e)
            {
                RepositoryViewModel.PullToRefreshFailed -= HandlePullToRefreshFailed;
                pullToRefreshFailedTCS.SetResult(e);
            }
        }
        public async Task PullToRefreshCommandTest_Authenticated()
        {
            //Arrange
            DateTimeOffset             beforePullToRefresh, afterPullToRefresh;
            IReadOnlyList <Repository> visibleRepositoryList_Initial, visibleRepositoryList_Final;

            string emptyDataViewTitle_Initial, emptyDataViewTitle_Final;
            string emptyDataViewDescription_Initial, emptyDataViewDescription_Final;

            var gitHubUserService       = ServiceCollection.ServiceProvider.GetRequiredService <GitHubUserService>();
            var repositoryViewModel     = ServiceCollection.ServiceProvider.GetRequiredService <RepositoryViewModel>();
            var gitHubGraphQLApiService = ServiceCollection.ServiceProvider.GetRequiredService <GitHubGraphQLApiService>();

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

            beforePullToRefresh              = DateTimeOffset.UtcNow;
            emptyDataViewTitle_Initial       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Initial    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Initial = repositoryViewModel.EmptyDataViewDescription;

            await repositoryViewModel.PullToRefreshCommand.ExecuteAsync().ConfigureAwait(false);

            afterPullToRefresh             = DateTimeOffset.UtcNow;
            emptyDataViewTitle_Final       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Final    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Final = repositoryViewModel.EmptyDataViewDescription;

            //Assert
            Assert.IsEmpty(visibleRepositoryList_Initial);
            Assert.IsNotEmpty(visibleRepositoryList_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Uninitialized, true), emptyDataViewTitle_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Succeeded, false), emptyDataViewTitle_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Uninitialized, true), emptyDataViewDescription_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Succeeded, false), emptyDataViewDescription_Final);

            Assert.IsTrue(visibleRepositoryList_Final.Any(x => x.OwnerLogin is GitHubConstants.GitTrendsRepoOwner && x.Name is GitHubConstants.GitTrendsRepoName));

            foreach (var repository in visibleRepositoryList_Final)
            {
                Assert.IsNotNull(repository.DailyClonesList);
                Assert.IsNotNull(repository.DailyViewsList);
                Assert.IsNotNull(repository.StarCount);
                Assert.IsNotNull(repository.StarredAt);
                Assert.IsNotNull(repository.TotalClones);
                Assert.IsNotNull(repository.TotalUniqueClones);
                Assert.IsNotNull(repository.TotalUniqueViews);
                Assert.IsNotNull(repository.TotalViews);

                Assert.Less(beforePullToRefresh, repository.DataDownloadedAt);
                Assert.Greater(afterPullToRefresh, repository.DataDownloadedAt);
            }
        }
        public void GetRepositoryDescriptionText_ValidRefreshState(RefreshState refreshState, bool isRepositoryListEmpty, string expectedResult)
        {
            //Arrange
            string actualResult;

            //Act
            actualResult = EmptyDataViewService.GetRepositoryDescriptionText(refreshState, isRepositoryListEmpty);

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
예제 #5
0
        public async Task PullToRefreshCommandTest_Unauthenticated()
        {
            //Arrange
            IReadOnlyList <Repository> visibleRepositoryList_Initial, visibleRepositoryList_Final;
            string emptyDataViewTitle_Initial, emptyDataViewTitle_Final;
            string emptyDataViewDescription_Initial, emptyDataViewDescription_Final;

            var repositoryViewModel = ServiceCollection.ServiceProvider.GetRequiredService <RepositoryViewModel>();

            bool didPullToRefreshFailedFire = false;
            var  pullToRefreshFailedTCS     = new TaskCompletionSource <PullToRefreshFailedEventArgs>();

            RepositoryViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;

            //Act
            emptyDataViewTitle_Initial       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Initial    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Initial = repositoryViewModel.EmptyDataViewDescription;

            var pullToRefreshCommandTask = repositoryViewModel.PullToRefreshCommand.ExecuteAsync();

            await pullToRefreshCommandTask.ConfigureAwait(false);

            var pullToRefreshFailedEventArgs = await pullToRefreshFailedTCS.Task.ConfigureAwait(false);

            emptyDataViewTitle_Final       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Final    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Final = repositoryViewModel.EmptyDataViewDescription;

            //Assert
            Assert.IsTrue(didPullToRefreshFailedFire);
            Assert.IsInstanceOf(typeof(LoginExpiredPullToRefreshEventArgs), pullToRefreshFailedEventArgs);

            Assert.IsEmpty(visibleRepositoryList_Initial);
            Assert.IsEmpty(visibleRepositoryList_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Uninitialized, true), emptyDataViewTitle_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.LoginExpired, true), emptyDataViewTitle_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Uninitialized, true), emptyDataViewDescription_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.LoginExpired, true), emptyDataViewDescription_Final);

            void HandlePullToRefreshFailed(object?sender, PullToRefreshFailedEventArgs e)
            {
                RepositoryViewModel.PullToRefreshFailed -= HandlePullToRefreshFailed;

                didPullToRefreshFailedFire = true;
                pullToRefreshFailedTCS.SetResult(e);
            }
        }
예제 #6
0
        public async Task PullToRefreshCommandTest_MaximumApiLimit()
        {
            //Arrange
            PullToRefreshFailedEventArgs pullToRefreshFailedEventArgs;
            IReadOnlyList <Repository>   visibleRepositoryList_Initial, visibleRepositoryList_Final;

            string emptyDataViewTitle_Initial, emptyDataViewTitle_Final;
            string emptyDataViewDescription_Initial, emptyDataViewDescription_Final;

            var gitHubUserService       = ServiceCollection.ServiceProvider.GetRequiredService <GitHubUserService>();
            var repositoryViewModel     = ServiceCollection.ServiceProvider.GetRequiredService <RepositoryViewModel>();
            var gitHubGraphQLApiService = ServiceCollection.ServiceProvider.GetRequiredService <GitHubGraphQLApiService>();

            var pullToRefreshFailedTCS = new TaskCompletionSource <PullToRefreshFailedEventArgs>();

            RepositoryViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;

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

            emptyDataViewTitle_Initial       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Initial    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Initial = repositoryViewModel.EmptyDataViewDescription;

            await repositoryViewModel.PullToRefreshCommand.ExecuteAsync().ConfigureAwait(false);

            emptyDataViewTitle_Final       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Final    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Final = repositoryViewModel.EmptyDataViewDescription;

            pullToRefreshFailedEventArgs = await pullToRefreshFailedTCS.Task.ConfigureAwait(false);

            //Assert
            Assert.IsEmpty(visibleRepositoryList_Initial);
            Assert.IsEmpty(visibleRepositoryList_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Uninitialized, true), emptyDataViewTitle_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.MaximumApiLimit, true), emptyDataViewTitle_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Uninitialized, true), emptyDataViewDescription_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.MaximumApiLimit, true), emptyDataViewDescription_Final);

            Assert.IsTrue(pullToRefreshFailedEventArgs is MaximimApiRequestsReachedEventArgs);

            void HandlePullToRefreshFailed(object?sender, PullToRefreshFailedEventArgs e)
            {
                ReferringSitesViewModel.PullToRefreshFailed -= HandlePullToRefreshFailed;
                pullToRefreshFailedTCS.SetResult(e);
            }
        }
        public async Task PullToRefreshCommandTest_ServerError()
        {
            //Arrange
            PullToRefreshFailedEventArgs pullToRefreshFailedEventArgs;
            IReadOnlyList <Repository>   visibleRepositoryList_Initial, visibleRepositoryList_Final;
            IReadOnlyList <Repository>   generatedRepositories = new[]
            {
                CreateRepository(),
                CreateRepository(),
                CreateRepository(),
                CreateRepository(),
                CreateRepository(),
            };

            string emptyDataViewTitle_Initial, emptyDataViewTitle_Final;
            string emptyDataViewDescription_Initial, emptyDataViewDescription_Final;

            var gitHubUserService       = ServiceCollection.ServiceProvider.GetRequiredService <GitHubUserService>();
            var repositoryDatabase      = ServiceCollection.ServiceProvider.GetRequiredService <RepositoryDatabase>();
            var repositoryViewModel     = ServiceCollection.ServiceProvider.GetRequiredService <RepositoryViewModel>();
            var gitHubGraphQLApiService = ServiceCollection.ServiceProvider.GetRequiredService <GitHubGraphQLApiService>();

            var pullToRefreshFailedTCS = new TaskCompletionSource <PullToRefreshFailedEventArgs>();

            RepositoryViewModel.PullToRefreshFailed += HandlePullToRefreshFailed;

            foreach (var repository in generatedRepositories)
            {
                await repositoryDatabase.SaveRepository(repository).ConfigureAwait(false);
            }

            generatedRepositories = await repositoryDatabase.GetRepositories().ConfigureAwait(false);

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

            emptyDataViewTitle_Initial       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Initial    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Initial = repositoryViewModel.EmptyDataViewDescription;

            await repositoryViewModel.PullToRefreshCommand.ExecuteAsync().ConfigureAwait(false);

            emptyDataViewTitle_Final       = repositoryViewModel.EmptyDataViewTitle;
            visibleRepositoryList_Final    = repositoryViewModel.VisibleRepositoryList;
            emptyDataViewDescription_Final = repositoryViewModel.EmptyDataViewDescription;

            pullToRefreshFailedEventArgs = await pullToRefreshFailedTCS.Task.ConfigureAwait(false);

            //Assert
            Assert.IsEmpty(visibleRepositoryList_Initial);
            Assert.IsNotEmpty(visibleRepositoryList_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Uninitialized, true), emptyDataViewTitle_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryTitleText(RefreshState.Error, false), emptyDataViewTitle_Final);

            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Uninitialized, true), emptyDataViewDescription_Initial);
            Assert.AreEqual(EmptyDataViewService.GetRepositoryDescriptionText(RefreshState.Error, false), emptyDataViewDescription_Final);

            Assert.IsTrue(pullToRefreshFailedEventArgs is ErrorPullToRefreshEventArgs);

            foreach (var visibleRepository in visibleRepositoryList_Final)
            {
                //Ensure visibleRepositoryList_Final matches the generatedRepositories
                var matchingRepository = generatedRepositories.Single(x => x.Url == visibleRepository.Url);

                Assert.AreEqual(visibleRepository.DailyClonesList?.Count, matchingRepository.DailyClonesList?.Count);
                Assert.AreEqual(visibleRepository.DailyViewsList?.Count, matchingRepository.DailyViewsList?.Count);
                Assert.AreEqual(visibleRepository.DataDownloadedAt, matchingRepository.DataDownloadedAt);
                Assert.AreEqual(visibleRepository.Description, matchingRepository.Description);
                Assert.AreEqual(visibleRepository.ForkCount, matchingRepository.ForkCount);
                Assert.AreEqual(visibleRepository.IsFavorite, matchingRepository.IsFavorite);
                Assert.AreEqual(visibleRepository.IsFork, matchingRepository.IsFork);
                Assert.AreEqual(visibleRepository.IssuesCount, matchingRepository.IssuesCount);
                Assert.AreEqual(visibleRepository.IsTrending, matchingRepository.IsTrending);
                Assert.AreEqual(visibleRepository.Name, matchingRepository.Name);
                Assert.AreEqual(visibleRepository.OwnerAvatarUrl, matchingRepository.OwnerAvatarUrl);
                Assert.AreEqual(visibleRepository.OwnerLogin, matchingRepository.OwnerLogin);
                Assert.AreEqual(visibleRepository.StarCount, matchingRepository.StarCount);
                Assert.AreEqual(visibleRepository.StarredAt?.Count, matchingRepository.StarredAt?.Count);
                Assert.AreEqual(visibleRepository.TotalClones, matchingRepository.TotalClones);
                Assert.AreEqual(visibleRepository.TotalUniqueClones, matchingRepository.TotalUniqueClones);
                Assert.AreEqual(visibleRepository.TotalUniqueViews, matchingRepository.TotalUniqueViews);
                Assert.AreEqual(visibleRepository.TotalViews, matchingRepository.TotalViews);
                Assert.AreEqual(visibleRepository.Url, matchingRepository.Url);
            }

            void HandlePullToRefreshFailed(object?sender, PullToRefreshFailedEventArgs e)
            {
                ReferringSitesViewModel.PullToRefreshFailed -= HandlePullToRefreshFailed;
                pullToRefreshFailedTCS.SetResult(e);
            }
        }