public async Task HydrateGhUserReposDisplayVm_IfNoReposAfterFilter_ShouldGetSimplyInitdRetClass()
        {
            // Arrange
            mockGHReposSvc.Setup(o => o.GetGitHubReposAsync(
                                     It.IsAny <HttpClient>(),
                                     It.IsAny <string>())).ReturnsAsync(() => new List <GhUserRepo>
            {
                new GhUserRepo {
                    name = "test1", @private = true
                },
                new GhUserRepo {
                    name = "test2", @private = true
                }
            });

            apiCallServices = new GitHubApiCallServices(
                mockHttpClientProvider.Object,
                mockHCAuthConfigr.Object,
                mockGHReposSvc.Object,
                mockGHPRsSvc.Object,
                mockCredentialsReader.Object);

            var ghUserReposSvcs = new GhUserReposServices(apiCallServices);

            // Act
            GhUserReposDisplayVm callResult =
                await ghUserReposSvcs.HydrateGhUserReposDisplayVmAsync("username");

            Assert.IsInstanceOfType(callResult, typeof(GhUserReposDisplayVm));
            Assert.AreEqual("username", callResult.GitHubUsername);
            Assert.IsNotNull(callResult.Repositories);
            Assert.IsInstanceOfType(callResult.Repositories, typeof(List <RepoListItem>));
            Assert.AreEqual(0, callResult.Repositories.Count);
        }
        public async Task HydrateGhUserReposDisplayVm_InclPrivateRepos_ShouldPass()
        {
            // Arrange
            var ghUserReposSvcs = new GhUserReposServices(apiCallServices);

            // Act
            GhUserReposDisplayVm callResult =
                await ghUserReposSvcs.HydrateGhUserReposDisplayVmAsync("username", true);

            // if 'returnPrivateRepos' is true, I should get 3 back
            Assert.AreEqual(3, callResult.Repositories.Count);
        }
        public async Task HydrateGhUserReposDisplayVm_MockRepoCallReturnsOne_ShouldGetHydratedViewModel()
        {
            // Arrange
            var ghUserReposSvcs = new GhUserReposServices(apiCallServices);

            // Act
            GhUserReposDisplayVm callResult =
                await ghUserReposSvcs.HydrateGhUserReposDisplayVmAsync("cmdrbeavis");

            // Assert
            Assert.IsInstanceOfType(callResult, typeof(GhUserReposDisplayVm));
            Assert.AreEqual("cmdrbeavis", callResult.GitHubUsername);
            Assert.IsNotNull(callResult.Repositories);
            Assert.IsInstanceOfType(callResult.Repositories, typeof(List <RepoListItem>));
            Assert.AreEqual(2, callResult.Repositories.Count);
            Assert.IsTrue(callResult.Repositories[0].name.Contains("test1"));
            Assert.IsTrue(callResult.Repositories[1].name.Contains("test3"));
        }
Esempio n. 4
0
        /// <summary>
        /// Hydrates the GitHub user repositories/PR count display ViewModel.
        /// </summary>
        /// <param name="ghUsername">
        /// The GitHub username.
        /// </param>
        /// <param name="returnPrivateRepos">
        /// if set to <c>true</c> [include private repos in returned set],
        /// else don't.
        /// </param>
        /// <returns>
        /// An instance of the <see cref="GhUserReposDisplayVm"/> class,
        /// hydrated with the appropriate data.
        /// </returns>
        public async Task <GhUserReposDisplayVm> HydrateGhUserReposDisplayVmAsync(
            string ghUsername,
            bool returnPrivateRepos = false)
        {
            if (string.IsNullOrWhiteSpace(ghUsername))
            {
                throw new ArgumentNullException(nameof(ghUsername));
            }

            var result = new GhUserReposDisplayVm
            {
                Repositories   = new List <RepoListItem>(),
                GitHubUsername = ghUsername
            };

            // get the public repositories for the specified user
            List <GhUserRepo> ghReposData =
                await _ghApiCallServices.GetPublicGhUserReposByUsername(ghUsername);

            // filter private repos per returnPrivateRepos value.
            var filteredRepos = returnPrivateRepos ? ghReposData : ghReposData.Where(x => !x.@private).ToList();

            if (filteredRepos.Count <= 0)
            {
                return(result);                         // EXIT point
            }

            foreach (var ghUserRepo in filteredRepos)
            {
                var newRecord = new RepoListItem();

                newRecord.name          = $"<a href=\"{ghUserRepo.html_url}\" target=\"_blank\">{ghUserRepo.name}</a>";
                newRecord.num_pull_reqs =
                    await _ghApiCallServices.GetOpenPRsByGhUserRepo(ghUsername, ghUserRepo.name);

                result.Repositories.Add(newRecord);
            }

            // do the sort on number of PRs
            result.Repositories =
                result.Repositories.OrderByDescending(x => x.num_pull_reqs).ToList();

            return(result);
        }