mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Added NewArbitraryMarkdown class, RenderArbitraryMakrdown method and unit tests for it.
This commit is contained in:
committed by
Brendan Forster
parent
c1ff2311d1
commit
ce93c4a60c
@@ -14,6 +14,14 @@ namespace Octokit.Reactive
|
||||
Justification = "Makes a network request")]
|
||||
IObservable<Emoji> GetAllEmojis();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered Markdown for an arbitrary markdown document.
|
||||
/// </summary>
|
||||
/// <param name="markdown">An arbitrary Markdown document</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The rendered Markdown.</returns>
|
||||
IObservable<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered Markdown for the specified plain-text Markdown document.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,6 +26,17 @@ namespace Octokit.Reactive
|
||||
return _client.GetAllEmojis().ToObservable().SelectMany(e => e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered Markdown for an arbitrary markdown document.
|
||||
/// </summary>
|
||||
/// <param name="markdown">An arbitrary Markdown document</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The rendered Markdown.</returns>
|
||||
public IObservable<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown)
|
||||
{
|
||||
return _client.RenderArbitraryMarkdown(markdown).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered Markdown for the specified plain-text Markdown document.
|
||||
/// </summary>
|
||||
|
||||
@@ -31,7 +31,27 @@ namespace Octokit.Tests.Clients
|
||||
"text/plain");
|
||||
}
|
||||
}
|
||||
public class TheRenderArbitrryMarkdownMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsTheEmojiEndpoint()
|
||||
{
|
||||
IApiResponse<string> response = new ApiResponse<string>(new Response(), "<strong>Test</strong>");
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var forTest = new NewArbitraryMarkdown("testMarkdown", "gfm", "testContext");
|
||||
connection.Post<string>(Args.Uri,forTest, "text/html", "text/plain")
|
||||
.Returns(Task.FromResult(response));
|
||||
var client = new MiscellaneousClient(connection);
|
||||
|
||||
var html = await client.RenderArbitraryMarkdown(forTest);
|
||||
Assert.Equal("<strong>Test</strong>", html);
|
||||
connection.Received()
|
||||
.Post<string>(Arg.Is<Uri>(u => u.ToString() == "markdown"),
|
||||
forTest,
|
||||
"text/html",
|
||||
"text/plain");
|
||||
}
|
||||
}
|
||||
public class TheGetEmojisMethod
|
||||
{
|
||||
[Fact]
|
||||
|
||||
@@ -30,6 +30,14 @@ namespace Octokit
|
||||
/// <returns>The rendered Markdown.</returns>
|
||||
Task<string> RenderRawMarkdown(string markdown);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered Markdown for an arbitrary markdown document.
|
||||
/// </summary>
|
||||
/// <param name="markdown">An arbitrary Markdown document</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The rendered Markdown.</returns>
|
||||
Task<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown);
|
||||
|
||||
/// <summary>
|
||||
/// List all templates available to pass as an option when creating a repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -58,6 +58,20 @@ namespace Octokit
|
||||
return response.Body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendered Markdown for an arbitrary markdown document.
|
||||
/// </summary>
|
||||
/// <param name="markdown">An arbitrary Markdown document</param>
|
||||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
||||
/// <returns>The rendered Markdown.</returns>
|
||||
public async Task<string> RenderArbitraryMarkdown(NewArbitraryMarkdown markdown)
|
||||
{
|
||||
var endpoint = new Uri("markdown", UriKind.Relative);
|
||||
var response = await _connection.Post<string>(endpoint, markdown, "text/html", "text/plain")
|
||||
.ConfigureAwait(false);
|
||||
return response.Body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all templates available to pass as an option when creating a repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to create anarbitrary markdown
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// API: https://developer.github.com/v3/markdown/#render-an-arbitrary-markdown-document
|
||||
/// </remarks>
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq}")]
|
||||
public class NewArbitraryMarkdown
|
||||
{
|
||||
const string _markdown = "markdown";
|
||||
const string _gfm = "gfm";
|
||||
|
||||
/// <summary>
|
||||
/// Create an arbitrary markdown
|
||||
/// </summary>
|
||||
/// <param name="text">The Markdown text to render</param>
|
||||
/// <param name="mode">The rendering mode. Can be either markdown by default or gfm</param>
|
||||
/// <param name="context">
|
||||
/// The repository context. Only taken into account when rendering as gfm
|
||||
/// </param>
|
||||
public NewArbitraryMarkdown(string text, string mode, string context)
|
||||
{
|
||||
Text = text;
|
||||
Mode = GetMode(mode);
|
||||
Context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an arbitrary markdown
|
||||
/// </summary>
|
||||
/// <param name="text">The Markdown text to render
|
||||
/// </param>
|
||||
|
||||
public NewArbitraryMarkdown(string text)
|
||||
:this(text,_markdown,null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an arbitrary markdown
|
||||
/// </summary>
|
||||
/// <param name="text">The Markdown text to render</param>
|
||||
/// <param name="mode">The rendering mode. Can be either markdown by default or gfm</param>
|
||||
/// </param>
|
||||
public NewArbitraryMarkdown(string text, string mode)
|
||||
: this(text, mode, null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the markdown text
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The text.
|
||||
/// </value>
|
||||
public string Text { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mode of the text
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The mode.
|
||||
/// </value>
|
||||
public string Mode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the context of the markdown
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The context.
|
||||
/// </value>
|
||||
public string Context { get; private set; }
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "gfm")]
|
||||
static string GetMode(string mode)
|
||||
{
|
||||
if (mode != _markdown || mode != _gfm)
|
||||
{
|
||||
throw (new FormatException("The mode must be either 'markdown' or 'gfm'"));
|
||||
}
|
||||
else
|
||||
return mode;
|
||||
}
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return String.Format(CultureInfo.InvariantCulture, "Text: {0}", Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@
|
||||
<Compile Include="Models\Request\LabelUpdate.cs" />
|
||||
<Compile Include="Models\Request\MergePullRequest.cs" />
|
||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
|
||||
<Compile Include="Models\Request\NewBlob.cs" />
|
||||
<Compile Include="Models\Request\NewCommit.cs" />
|
||||
<Compile Include="Models\Request\NewCommitStatus.cs" />
|
||||
@@ -405,4 +406,4 @@
|
||||
<Compile Include="Models\Common\Committer.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -184,6 +184,7 @@
|
||||
<Compile Include="Models\Request\MergePullRequest.cs" />
|
||||
<Compile Include="Models\Request\MilestoneRequest.cs" />
|
||||
<Compile Include="Models\Request\MilestoneUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
|
||||
<Compile Include="Models\Request\NewAuthorization.cs" />
|
||||
<Compile Include="Models\Request\NewBlob.cs" />
|
||||
<Compile Include="Models\Request\NewCommit.cs" />
|
||||
@@ -430,4 +431,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -87,6 +87,7 @@
|
||||
<Compile Include="Http\ProductHeaderValue.cs" />
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Models\Request\GistFileUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewArbitraryMarkDown.cs" />
|
||||
<Compile Include="Models\Request\NewMerge.cs" />
|
||||
<Compile Include="Models\Request\PublicRepositoryRequest.cs" />
|
||||
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
|
||||
@@ -441,4 +442,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user