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); }
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 FetchReadme_badflow() { RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create(It.IsAny <Uri>())) .Returns(MockRestClient(HttpStatusCode.BadRequest, null)); string readme = Source.FetchReadme("http://example.com"); Assert.IsNull(readme); }
public void FetchReadme_goodflow() { string readmeContent = "This project has an amazing readme"; RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create(It.IsAny <Uri>())) .Returns(MockRestClient(HttpStatusCode.OK, readmeContent)); string readme = Source.FetchReadme("http://example.com"); Assert.AreEqual(readmeContent, readme); }
public void GetProjectInformation_badflow_no_fetch_repo() { // Prepare RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create(new Uri("http://example.com/api/v4/projects/group%2Fproject"))) .Returns(MockRestClient(HttpStatusCode.BadRequest, null)); // Ask Project project = Source.GetProjectInformation(new Uri("http://example.com/group/project")); // Assert Assert.AreEqual(JsonConvert.SerializeObject(new Project()), JsonConvert.SerializeObject(project)); }
public void ProjectURIMatches_goodflow() { string response = "<meta content=\"object\" property=\"og:type\">\r\n<meta content=\"GitLab\" property=\"og:site_name\">\r\n<meta content=\"Hari Sekhon / DevOps-Bash-tools\" property=\"og:title\">\r\n"; RestClientFactoryMock.Setup( restClientFactory => restClientFactory.Create(It.IsAny <Uri>())) .Returns( MockRestClient(HttpStatusCode.OK, response) ); Uri requestUri = new Uri("http://domain.com/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("https://domain.com/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("http://www.domain.com/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("https://www.domain.com/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("domain.com/group/project", UriKind.Relative); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("www.domain.com/group/project", UriKind.Relative); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("http://domain.com:123/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("https://domain.com:123/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("http://1.2.3.4/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("https://1.2.3.4/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("http://1.2.3.4:123/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("https://1.2.3.4:123/group/project"); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("1.2.3.4/group/project", UriKind.Relative); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("1.2.3.4:123/group/project", UriKind.Relative); Assert.IsTrue(Source.ProjectURIMatches(requestUri)); }
public void ProjectURIMatches_url_invalid() { string response = "<meta content=\"object\" property=\"og:type\">\r\n<meta content=\"GitHub\" property=\"og:site_name\">\r\n<meta content=\"Hari Sekhon / DevOps-Bash-tools\" property=\"og:title\">\r\n"; RestClientFactoryMock.Setup(restClientFactory => restClientFactory.Create(It.IsAny <Uri>())) .Returns(MockRestClient(HttpStatusCode.OK, response)); Uri requestUri = new Uri("http://example.com/group"); Assert.IsFalse(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("ftp://example.com/group"); Assert.IsFalse(Source.ProjectURIMatches(requestUri)); requestUri = new Uri("gopher://example.com/group"); Assert.IsFalse(Source.ProjectURIMatches(requestUri)); }
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)); }