public async Task ReturnsReadme()
            {
                string encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
                var readmeInfo = new ReadmeResponse(
                    encodedContent,
                    "README.md",
                    "https://github.example.com/readme",
                    "https://github.example.com/readme.md",
                    "base64");
                var connection = Substitute.For<IApiConnection>();
                connection.Get<ReadmeResponse>(Args.Uri, null).Returns(Task.FromResult(readmeInfo));
                connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
                var contentsClient = new RepositoryContentsClient(connection);

                var readme = await contentsClient.GetReadme("fake", "repo");

                Assert.Equal("README.md", readme.Name);
                connection.Received().Get<ReadmeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/readme"),
                    null);
                connection.DidNotReceive().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"),
                    null);
                var htmlReadme = await readme.GetHtmlContent();
                Assert.Equal("<html>README</html>", htmlReadme);
                connection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme.md"), null);
            }
            public async Task ReturnsReadmeWithRepositoryId()
            {
                string encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
                var readmeInfo = new ReadmeResponse(
                    encodedContent,
                    "README.md",
                    "https://github.example.com/readme",
                    "https://github.example.com/readme.md",
                    "base64");

                var gitHubClient = Substitute.For<IGitHubClient>();
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.GetHtml(new Uri(readmeInfo.Url)).Returns(Task.FromResult("<html>README</html>"));
                var readmeFake = new Readme(readmeInfo, apiConnection);
                var contentsClient = new ObservableRepositoryContentsClient(gitHubClient);

                gitHubClient.Repository.Content.GetReadme(1).Returns(Task.FromResult(readmeFake));

                IApiResponse<string> apiResponse = new ApiResponse<string>(new Response(), "<html>README</html>");
                gitHubClient.Connection.GetHtml(Args.Uri, null)
                    .Returns(Task.FromResult(apiResponse));

                var readme = await contentsClient.GetReadme(1);

                Assert.Equal("README.md", readme.Name);

                gitHubClient.Repository.Content.Received(1).GetReadme(1);
                gitHubClient.Connection.DidNotReceive().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"),
                    Args.EmptyDictionary);

                var htmlReadme = await readme.GetHtmlContent();
                Assert.Equal("<html>README</html>", htmlReadme);
                apiConnection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme.md"), null);
            }
示例#3
0
            public async Task ReturnsReadme()
            {
                string encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
                var    readmeInfo     = new ReadmeResponse
                {
                    Content  = encodedContent,
                    Encoding = "base64",
                    Name     = "README.md",
                    Url      = "https://github.example.com/readme.md",
                    HtmlUrl  = "https://github.example.com/readme"
                };
                var connection = Substitute.For <IApiConnection>();

                connection.Get <ReadmeResponse>(Args.Uri, null).Returns(Task.FromResult(readmeInfo));
                connection.GetHtml(Args.Uri, null).Returns(Task.FromResult("<html>README</html>"));
                var reposEndpoint = new RepositoriesClient(connection);

                var readme = await reposEndpoint.GetReadme("fake", "repo");

                Assert.Equal("README.md", readme.Name);
                connection.Received().Get <ReadmeResponse>(Arg.Is <Uri>(u => u.ToString() == "repos/fake/repo/readme"),
                                                           null);
                connection.DidNotReceive().GetHtml(Arg.Is <Uri>(u => u.ToString() == "https://github.example.com/readme.md"),
                                                   null);
                var htmlReadme = await readme.GetHtmlContent();

                Assert.Equal("<html>README</html>", htmlReadme);
                connection.Received().GetHtml(Arg.Is <Uri>(u => u.ToString() == "https://github.example.com/readme.md"), null);
            }
示例#4
0
            public async Task ReturnsReadmeWithRepositoryId()
            {
                string encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
                var    readmeInfo     = new ReadmeResponse(
                    encodedContent,
                    "README.md",
                    "https://github.example.com/readme",
                    "https://github.example.com/readme.md",
                    "base64");

                var gitHubClient  = Substitute.For <IGitHubClient>();
                var apiConnection = Substitute.For <IApiConnection>();

                apiConnection.GetHtml(new Uri(readmeInfo.Url)).Returns(Task.FromResult("<html>README</html>"));
                var readmeFake     = new Readme(readmeInfo, apiConnection);
                var contentsClient = new ObservableRepositoryContentsClient(gitHubClient);

                gitHubClient.Repository.Content.GetReadme(1).Returns(Task.FromResult(readmeFake));

                IApiResponse <string> apiResponse = new ApiResponse <string>(new Response(), "<html>README</html>");

                gitHubClient.Connection.GetHtml(Args.Uri, null)
                .Returns(Task.FromResult(apiResponse));

                var readme = await contentsClient.GetReadme(1);

                Assert.Equal("README.md", readme.Name);

                gitHubClient.Repository.Content.Received(1).GetReadme(1);
                gitHubClient.Connection.DidNotReceive().GetHtml(Arg.Is <Uri>(u => u.ToString() == "https://github.example.com/readme"),
                                                                Args.EmptyDictionary);

                var htmlReadme = await readme.GetHtmlContent();

                Assert.Equal("<html>README</html>", htmlReadme);
                apiConnection.Received().GetHtml(Arg.Is <Uri>(u => u.ToString() == "https://github.example.com/readme.md"), null);
            }