public void GetProjectInformation_badflow_no_readme() { // Prepare Uri projectUri = new Uri("http://example.com/group/project"); GitLabResourceResult gitLabResourceResult = new GitLabResourceResult(); gitLabResourceResult.Name = "repo name"; gitLabResourceResult.Description = "repo description"; gitLabResourceResult.WebUrl = "web url"; string data = JsonConvert.SerializeObject(gitLabResourceResult); RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create( new Uri("http://example.com/api/v4/projects/group%2Fproject"))) .Returns(MockRestClient(HttpStatusCode.OK, data)); // Ask Project project = Source.GetProjectInformation(projectUri); // Assert Assert.AreEqual(project.Name, gitLabResourceResult.Name); Assert.AreEqual(project.ShortDescription, gitLabResourceResult.Description); Assert.AreEqual(project.Uri, gitLabResourceResult.WebUrl); Assert.IsNull(project.Description); }
/// <summary> /// Gets the project information. /// </summary> /// <param name="sourceUri">The source URI.</param> /// <returns>the project object filled with information retrieved online.</returns> public Project GetProjectInformation(Uri sourceUri) { // Create valid URL try { Uri.TryCreate(sourceUri.AbsoluteUri, UriKind.Absolute, out sourceUri); } catch (InvalidOperationException) { Uri.TryCreate("https://" + sourceUri, UriKind.Absolute, out sourceUri); } string domain = sourceUri.GetLeftPart(UriPartial.Authority); // Get the project path without the prefix slash. string projectPath = sourceUri.AbsoluteUri.Replace(domain, "") .Substring(1); Uri serializedUrl = new Uri(domain + gitlabApiUri + projectPath.Replace("/", "%2F")); Project project = new Project(); GitLabResourceResult resourceResult = FetchRepo(serializedUrl); if (resourceResult == null) { return(project); } project.Name = resourceResult.Name; project.ShortDescription = resourceResult.Description; project.Uri = resourceResult.WebUrl; if (!string.IsNullOrEmpty(resourceResult.ReadmeUrl)) { project.Description = FetchReadme(resourceResult.ReadmeUrl); } return(project); }
public void FetchRepo_badflow() { RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create(It.IsAny <Uri>())) .Returns(MockRestClient(HttpStatusCode.BadRequest, null)); GitLabResourceResult gitLabResourceResult = Source.FetchRepo(new Uri("http://example.com")); Assert.IsNull(gitLabResourceResult); }
public void FetchRepo_goodflow() { GitLabResourceResult resource = new GitLabResourceResult { Name = "repo name", ReadmeUrl = "readme url", WebUrl = "repo url" }; string response = JsonConvert.SerializeObject(resource); RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create(It.IsAny <Uri>())) .Returns(MockRestClient(HttpStatusCode.OK, response)); GitLabResourceResult resourceResult = Source.FetchRepo(new Uri("http://example.com")); Assert.AreEqual(JsonConvert.SerializeObject(resource), JsonConvert.SerializeObject(resourceResult)); }