/// <summary> /// This method is responsible for retrieving a project from the user, via the access token, by id from the Gitlab 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) { GitlabDataSourceResourceResult resourceResult = await FetchGitlabRepositoryById(projectId, accessToken); Project project = mapper.Map <GitlabDataSourceResourceResult, Project>(resourceResult); project.Description = await FetchReadme(resourceResult.ReadmeUrl) ?? project.Description; return(project); }
/// <summary> /// This method is responsible for retrieving a public project from the user, by id from the Gitlab 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) { GitlabDataSourceResourceResult resourceResult = await FetchPublicGitlabRepositoryById(identifier); Project project = mapper.Map <GitlabDataSourceResourceResult, Project>(resourceResult); project.Description = await FetchReadme(resourceResult.ReadmeUrl) ?? project.Description; List <GitLabDataSourceContributorResourceResult> contributors = await FetchContributorsFromRepository(resourceResult.Id); project.Collaborators = new List <Collaborator>(contributors.Select(c => new Collaborator { FullName = c.Name })); return(project); }
public async Task FetchGitlabRepositoryById_GoodFlow( [GitlabDataSourceResourceResultDataSource] GitlabDataSourceResourceResult resourceResult) { // Arrange MockRestClient(resourceResult, HttpStatusCode.OK); DataSourceAdaptee = new GitlabDataSourceAdaptee(ConfigurationMock, ClientFactoryMock.Object, Mapper); // Act Action act = () => DataSourceAdaptee.FetchGitlabRepositoryById(It.IsAny <string>(), It.IsAny <string>()); GitlabDataSourceResourceResult retrievedResourceResult = await DataSourceAdaptee.FetchGitlabRepositoryById(It.IsAny <string>(), It.IsAny <string>()); // Assert act.Should() .NotThrow(); retrievedResourceResult.Should() .BeEquivalentTo(resourceResult); }
/// <summary> /// This method is responsible for retrieving the content from a public Gitlab project by id. /// </summary> /// <param name="identifier">The identifier which is used to retrieve the correct project.</param> /// <returns>This method returns a Gitlab data source resource result with the specified identifier.</returns> /// <exception cref="ExternalException"> /// This method could throw an external exception whenever the status code is not /// successful. /// </exception> public async Task <GitlabDataSourceResourceResult> FetchPublicGitlabRepositoryById(string identifier) { IRestClient client = restClientFactory.Create(new Uri(BaseUrl)); RestRequest request = new RestRequest($"projects/{identifier}", Method.GET); IRestResponse response = await client.ExecuteAsync(request); if (!response.IsSuccessful) { throw new ExternalException(response.ErrorMessage); } if (string.IsNullOrEmpty(response.Content)) { return(null); } GitlabDataSourceResourceResult resourceResult = JsonConvert.DeserializeObject <GitlabDataSourceResourceResult>(response.Content); return(resourceResult); }
public async Task FetchPublicRepository_GoodFlow( [GitlabDataSourceResourceResultDataSource] GitlabDataSourceResourceResult resourceResult) { // Arrange MockRestClient(resourceResult, HttpStatusCode.OK); DataSourceAdaptee = new GitlabDataSourceAdaptee(ConfigurationMock, ClientFactoryMock.Object, Mapper); // Act Uri testUri = new Uri("https://google.nl/test"); Action act = () => DataSourceAdaptee.FetchPublicRepository(testUri); GitlabDataSourceResourceResult retrievedResourceResult = await DataSourceAdaptee.FetchPublicRepository(testUri); // Assert act.Should() .NotThrow(); retrievedResourceResult.Should() .BeEquivalentTo(resourceResult); }