Example #1
0
        /// <summary>
        ///     This method is responsible for retrieving a public project from a uri, from the Github API.
        /// </summary>
        /// <param name="sourceUri">The source uri which will be used to retrieve the correct project.</param>
        /// <returns>This method returns a public project from the specified source uri.</returns>
        public async Task <Project> GetPublicProjectFromUri(Uri sourceUri)
        {
            GithubDataSourceResourceResult githubDataSource = await FetchPublicRepository(sourceUri);

            Project p = mapper.Map <GithubDataSourceResourceResult, Project>(githubDataSource);
            List <GithubDataSourceContributorResourceResult> contributors =
                await FetchContributorsFromRepository(githubDataSource.Owner.Login, githubDataSource.Name);

            p.Collaborators = new List <Collaborator>(contributors.Select(c => new Collaborator {
                FullName = c.Login
            }));
            p.Description = await FetchReadme(githubDataSource.Owner.Login, githubDataSource.Name) ?? p.Description;

            return(p);
        }
        public async Task FetchPublicGithubProjectById_GoodFlow(
            [GithubDataSourceResourceResultDataSource] GithubDataSourceResourceResult resourceResult)
        {
            // Arrange
            MockRestClient(resourceResult, HttpStatusCode.OK);
            DataSourceAdaptee = new GithubDataSourceAdaptee(ConfigurationMock, ClientFactoryMock.Object, Mapper);

            // Act
            Action act = () => DataSourceAdaptee.FetchPublicGithubProjectById(It.IsAny <string>());
            GithubDataSourceResourceResult retrievedResourceResult = await DataSourceAdaptee.FetchPublicGithubProjectById(It.IsAny <string>());

            // Assert
            act.Should().NotThrow();
            retrievedResourceResult.Should().BeEquivalentTo(resourceResult);
        }
        public async Task FetchPublicRepository_GoodFlow(
            [GithubDataSourceResourceResultDataSource] GithubDataSourceResourceResult resourceResult)
        {
            // Arrange
            MockRestClient(resourceResult, HttpStatusCode.OK);
            DataSourceAdaptee = new GithubDataSourceAdaptee(ConfigurationMock, ClientFactoryMock.Object, Mapper);

            // Act
            Uri    testUri = new Uri("https://google.nl/test");
            Action act     = () => DataSourceAdaptee.FetchPublicRepository(testUri);
            GithubDataSourceResourceResult retrievedResourceResult = await DataSourceAdaptee.FetchPublicRepository(testUri);

            // Assert
            act.Should().NotThrow();
            retrievedResourceResult.Should().BeEquivalentTo(resourceResult);
        }
Example #4
0
        /// <summary>
        ///     This method is responsible for retrieving a public project from the user, by id from the Github API.
        /// </summary>
        /// <param name="identifier">The identifier which will be used to retrieve the correct project.</param>
        /// <returns>This method returns a public project with the specified identifier.</returns>
        public async Task <Project> GetPublicProjectById(string identifier)
        {
            GithubDataSourceResourceResult projectResourceResult = await FetchPublicGithubProjectById(identifier);

            Project p = mapper.Map <GithubDataSourceResourceResult, Project>(projectResourceResult);

            p.Description = await FetchReadme(projectResourceResult.Owner.Login, projectResourceResult.Name) ??
                            p.Description;

            List <GithubDataSourceContributorResourceResult> contributors =
                await FetchContributorsFromRepository(projectResourceResult.Owner.Login, projectResourceResult.Name);

            p.Collaborators = new List <Collaborator>(contributors.Select(c => new Collaborator {
                FullName = c.Login
            }));
            return(p);
        }
Example #5
0
        /// <summary>
        ///     This method is responsible for retrieving the content from a public repositories from an identifier.
        /// </summary>
        /// <param name="identifier">The identifier which is used to retrieve the correct project.</param>
        /// <returns>This method returns a github data source resource result.</returns>
        /// <exception cref="ExternalException">
        ///     This method could throw an external exception whenever the status code is not
        ///     successful.
        /// </exception>
        public async Task <GithubDataSourceResourceResult> FetchPublicGithubProjectById(string identifier)
        {
            IRestClient   client   = restClientFactory.Create(new Uri(BaseUrl));
            IRestRequest  request  = new RestRequest($"repositories/{identifier}", Method.GET);
            IRestResponse response = await client.ExecuteAsync(request);

            if (string.IsNullOrEmpty(response.Content))
            {
                return(null);
            }
            if (!response.IsSuccessful)
            {
                throw new ExternalException(response.ErrorMessage);
            }
            GithubDataSourceResourceResult resourceResult =
                JsonConvert.DeserializeObject <GithubDataSourceResourceResult>(response.Content);

            return(resourceResult);
        }
Example #6
0
        /// <summary>
        ///     This method is responsible for retrieving a project from the user, via the access token, by id from the Github API.
        /// </summary>
        /// <param name="accessToken">The access token which will be used to retrieve the correct project from the user.</param>
        /// <param name="projectId">The identifier of the project that will be used to search the correct project.</param>
        /// <returns>This method returns a project with this specified identifier.</returns>
        public async Task <Project> GetProjectById(string accessToken, string projectId)
        {
            IEnumerable <GithubDataSourceResourceResult> projects = await FetchAllGithubProjects(accessToken);

            GithubDataSourceResourceResult projectWithSpecifiedId =
                projects?.SingleOrDefault(resource => resource.Id.ToString() == projectId);

            if (projectWithSpecifiedId == null)
            {
                return(null);
            }
            Project p = mapper.Map <GithubDataSourceResourceResult, Project>(projectWithSpecifiedId);

            p.Description =
                await FetchReadme(projectWithSpecifiedId.Owner.Login, projectWithSpecifiedId.Name, accessToken) ??
                p.Description;

            return(p);
        }