internal Readme(ReadmeResponse response, IApiConnection client) { Ensure.ArgumentNotNull(response, "response"); Ensure.ArgumentNotNull(client, "client"); Name = response.Name; Url = new Uri(response.Url); HtmlUrl = new Uri(response.HtmlUrl); if (response.Encoding.Equals("base64", StringComparison.OrdinalIgnoreCase)) { var contentAsBytes = Convert.FromBase64String(response.Content); Content = Encoding.UTF8.GetString(contentAsBytes, 0, contentAsBytes.Length); } htmlContent = new Lazy<Task<string>>(async () => await client.GetHtml(Url).ConfigureAwait(false)); }
internal Readme(ReadmeResponse response, IApiConnection client) { Ensure.ArgumentNotNull(response, "response"); Ensure.ArgumentNotNull(client, "client"); Name = response.Name; Url = new Uri(response.Url); HtmlUrl = new Uri(response.HtmlUrl); if (response.Encoding.Equals("base64", StringComparison.OrdinalIgnoreCase)) { var contentAsBytes = Convert.FromBase64String(response.Content); Content = Encoding.UTF8.GetString(contentAsBytes, 0, contentAsBytes.Length); } htmlContent = new Lazy <Task <string> >(async() => await client.GetHtml(Url).ConfigureAwait(false)); }
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); }