mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
Implement Miscellaneous Client emoji and markdown
This commit is contained in:
+3
-4
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
public class ObservableAutoCompleteClient : IObservableAutoCompleteClient
|
||||
public class ObservableMiscellaneousClient : IObservableMiscellaneousClient
|
||||
{
|
||||
readonly IAutoCompleteClient _client;
|
||||
readonly IMiscellaneousClient _client;
|
||||
|
||||
public ObservableAutoCompleteClient(IAutoCompleteClient client)
|
||||
public ObservableMiscellaneousClient(IMiscellaneousClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
public interface IObservableGitHubClient
|
||||
{
|
||||
IObservableAuthorizationsClient Authorization { get; }
|
||||
IObservableAutoCompleteClient AutoComplete { get; }
|
||||
IObservableMiscellaneousClient Miscellaneous { get; }
|
||||
IObservableOrganizationsClient Organization { get; }
|
||||
IObservableRepositoriesClient Repository { get; }
|
||||
IObservableSshKeysClient SshKey { get; }
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public interface IObservableAutoCompleteClient
|
||||
public interface IObservableMiscellaneousClient
|
||||
{
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
|
||||
Justification = "Makes a network request")]
|
||||
@@ -9,7 +9,7 @@ namespace Octokit.Reactive
|
||||
Ensure.ArgumentNotNull(gitHubClient, "githubClient");
|
||||
|
||||
Authorization = new ObservableAuthorizationsClient(gitHubClient.Authorization);
|
||||
AutoComplete = new ObservableAutoCompleteClient(gitHubClient.AutoComplete);
|
||||
Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous);
|
||||
Organization = new ObservableOrganizationsClient(gitHubClient.Organization);
|
||||
Repository = new ObservableRepositoriesClient(gitHubClient.Repository);
|
||||
SshKey = new ObservableSshKeysClient(gitHubClient.SshKey);
|
||||
@@ -17,7 +17,7 @@ namespace Octokit.Reactive
|
||||
}
|
||||
|
||||
public IObservableAuthorizationsClient Authorization { get; private set; }
|
||||
public IObservableAutoCompleteClient AutoComplete { get; private set; }
|
||||
public IObservableMiscellaneousClient Miscellaneous { get; private set; }
|
||||
public IObservableOrganizationsClient Organization { get; private set; }
|
||||
public IObservableRepositoriesClient Repository { get; private set; }
|
||||
public IObservableSshKeysClient SshKey { get; private set; }
|
||||
|
||||
@@ -83,14 +83,14 @@
|
||||
<Link>Helpers\Ensure.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\ObservableAuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableAutoCompleteClient.cs" />
|
||||
<Compile Include="Clients\ObservableMiscellaneousClient.cs" />
|
||||
<Compile Include="Clients\ObservableOrganizationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableReleasesClient.cs" />
|
||||
<Compile Include="Clients\ObservableRepositoriesClient.cs" />
|
||||
<Compile Include="Clients\ObservableSshKeysClient.cs" />
|
||||
<Compile Include="Clients\ObservableUsersClient.cs" />
|
||||
<Compile Include="IObservableAuthorizationsClient.cs" />
|
||||
<Compile Include="IObservableAutoCompleteClient.cs" />
|
||||
<Compile Include="IObservableMiscellaneousClient.cs" />
|
||||
<Compile Include="IObservableGitHubClient.cs" />
|
||||
<Compile Include="IObservableReleasesClient.cs" />
|
||||
<Compile Include="IObservableRepositoriesClient.cs" />
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Integration
|
||||
{
|
||||
public class AutoCompleteClientTests
|
||||
{
|
||||
public class TheGetEmojisMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task GetsAllTheEmojis()
|
||||
{
|
||||
var github = new GitHubClient("Octokit Test Runner")
|
||||
{
|
||||
Credentials = AutomationSettings.Current.GitHubCredentials
|
||||
};
|
||||
|
||||
var emojis = await github.AutoComplete.GetEmojis();
|
||||
|
||||
Assert.True(emojis.Count > 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Integration
|
||||
{
|
||||
public class MiscellaneousClientTests
|
||||
{
|
||||
public class TheGetEmojisMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task GetsAllTheEmojis()
|
||||
{
|
||||
var github = new GitHubClient("Octokit Test Runner")
|
||||
{
|
||||
Credentials = AutomationSettings.Current.GitHubCredentials
|
||||
};
|
||||
|
||||
var emojis = await github.Miscellaneous.GetEmojis();
|
||||
|
||||
Assert.True(emojis.Count > 1);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRenderRawMarkdownMethod
|
||||
{
|
||||
[IntegrationTest]
|
||||
public async Task CanRenderGitHubFlavoredMarkdown()
|
||||
{
|
||||
var github = new GitHubClient("Test Runner User Agent")
|
||||
{
|
||||
Credentials = AutomationSettings.Current.GitHubCredentials
|
||||
};
|
||||
|
||||
var result = await github.Miscellaneous.RenderRawMarkdown("This is a **test**");
|
||||
|
||||
Assert.Equal("<p>This is a <strong>test</strong></p>", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,9 +46,9 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AutoCompleteClientTests.cs" />
|
||||
<Compile Include="AutomationSettings.cs" />
|
||||
<Compile Include="IntegrationTestAttribute.cs" />
|
||||
<Compile Include="MiscellaneousClientTests.cs" />
|
||||
<Compile Include="ReleasesClientTests.cs" />
|
||||
<Compile Include="RepositoriesClientTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
+34
-6
@@ -8,14 +8,33 @@ using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
public class AutoCompleteClientTests
|
||||
public class MiscellaneousClientTests
|
||||
{
|
||||
public class TheCtor
|
||||
public class TheRenderRawMarkdownMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgumentsNotNull()
|
||||
public async Task RequestsTheEmojiEndpoint()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new AutoCompleteClient(null));
|
||||
var links = new Dictionary<string, Uri>();
|
||||
var scopes = new List<string>();
|
||||
IResponse<string> response = new ApiResponse<string>
|
||||
{
|
||||
ApiInfo = new ApiInfo(links, scopes, scopes, "", 1, 1),
|
||||
Body = "<strong>Test</strong>"
|
||||
};
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.PostAsync<string>(Args.Uri, "**Test**", "text/plain", "text/html")
|
||||
.Returns(Task.FromResult(response));
|
||||
var client = new MiscellaneousClient(connection);
|
||||
|
||||
var html = await client.RenderRawMarkdown("**Test**");
|
||||
|
||||
Assert.Equal("<strong>Test</strong>", html);
|
||||
connection.Received()
|
||||
.PostAsync<string>(Arg.Is<Uri>(u => u.ToString() == "/markdown/raw"),
|
||||
"**Test**",
|
||||
"text/plain",
|
||||
"text/html");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,14 +56,23 @@ namespace Octokit.Tests.Clients
|
||||
};
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<Dictionary<string, string>>(Args.Uri, null).Returns(Task.FromResult(response));
|
||||
var autoComplete = new AutoCompleteClient(connection);
|
||||
var client = new MiscellaneousClient(connection);
|
||||
|
||||
var emojis = await autoComplete.GetEmojis();
|
||||
var emojis = await client.GetEmojis();
|
||||
|
||||
Assert.Equal(2, emojis.Count);
|
||||
connection.Received()
|
||||
.GetAsync<Dictionary<string, string>>(Arg.Is<Uri>(u => u.ToString() == "/emojis"), null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgumentsNotNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new MiscellaneousClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@
|
||||
<Compile Include="Helpers\UriExtensionsTests.cs" />
|
||||
<Compile Include="Http\ApiConnectionTests.cs" />
|
||||
<Compile Include="Clients\AuthorizationsClientTests.cs" />
|
||||
<Compile Include="Clients\AutoCompleteClientTests.cs" />
|
||||
<Compile Include="Clients\MiscellaneousClientTests.cs" />
|
||||
<Compile Include="Clients\OrganizationsClientTests.cs" />
|
||||
<Compile Include="Helpers\Arg.cs" />
|
||||
<Compile Include="Helpers\AssertEx.cs" />
|
||||
|
||||
@@ -51,12 +51,13 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Clients\MiscellaneousClientTests.cs" />
|
||||
<Compile Include="Clients\ReleasesClientTests.cs" />
|
||||
<Compile Include="Clients\SshKeysClientTests.cs" />
|
||||
<Compile Include="Exceptions\ApiValidationExceptionTests.cs" />
|
||||
<Compile Include="Helpers\UriExtensionsTests.cs" />
|
||||
<Compile Include="Http\ApiConnectionTests.cs" />
|
||||
<Compile Include="Clients\AuthorizationsClientTests.cs" />
|
||||
<Compile Include="Clients\AutoCompleteClientTests.cs" />
|
||||
<Compile Include="Clients\OrganizationsClientTests.cs" />
|
||||
<Compile Include="Helpers\Arg.cs" />
|
||||
<Compile Include="Helpers\AssertEx.cs" />
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Http;
|
||||
|
||||
namespace Octokit.Clients
|
||||
{
|
||||
/// <summary>
|
||||
/// Calls API methods meant to support auto complete.
|
||||
/// </summary>
|
||||
public class AutoCompleteClient : IAutoCompleteClient
|
||||
public class MiscellaneousClient : IMiscellaneousClient
|
||||
{
|
||||
readonly IConnection _connection;
|
||||
|
||||
public AutoCompleteClient(IConnection connection)
|
||||
public MiscellaneousClient(IConnection connection)
|
||||
{
|
||||
Ensure.ArgumentNotNull(connection, "connection");
|
||||
|
||||
|
||||
_connection = connection;
|
||||
}
|
||||
|
||||
@@ -28,5 +25,12 @@ namespace Octokit.Clients
|
||||
return new ReadOnlyDictionary<string, Uri>(
|
||||
response.BodyAsObject.ToDictionary(kvp => kvp.Key, kvp => new Uri(kvp.Value)));
|
||||
}
|
||||
|
||||
public async Task<string> RenderRawMarkdown(string markdown)
|
||||
{
|
||||
var endpoint = new Uri("/markdown/raw", UriKind.Relative);
|
||||
var response = await _connection.PostAsync<string>(endpoint, markdown, "text/plain", "text/html");
|
||||
return response.Body;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace Octokit
|
||||
|
||||
Connection = connection;
|
||||
Authorization = new AuthorizationsClient(new ApiConnection<Authorization>(connection));
|
||||
AutoComplete = new AutoCompleteClient(connection);
|
||||
Miscellaneous = new MiscellaneousClient(connection);
|
||||
Organization = new OrganizationsClient(new ApiConnection<Organization>(connection));
|
||||
Repository = new RepositoriesClient(new ApiConnection<Repository>(connection));
|
||||
Release = new ReleasesClient(new ApiConnection<Release>(connection));
|
||||
@@ -77,7 +77,7 @@ namespace Octokit
|
||||
public IConnection Connection { get; private set; }
|
||||
|
||||
public IAuthorizationsClient Authorization { get; private set; }
|
||||
public IAutoCompleteClient AutoComplete { get; private set; }
|
||||
public IMiscellaneousClient Miscellaneous { get; private set; }
|
||||
public IOrganizationsClient Organization { get; private set; }
|
||||
public IRepositoriesClient Repository { get; private set; }
|
||||
public IReleasesClient Release { get; private set; }
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Octokit
|
||||
IConnection Connection { get; }
|
||||
|
||||
IAuthorizationsClient Authorization { get; }
|
||||
IAutoCompleteClient AutoComplete { get; }
|
||||
IMiscellaneousClient Miscellaneous { get; }
|
||||
IOrganizationsClient Organization { get; }
|
||||
IRepositoriesClient Repository { get; }
|
||||
IReleasesClient Release { get; }
|
||||
|
||||
@@ -5,10 +5,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public interface IAutoCompleteClient
|
||||
public interface IMiscellaneousClient
|
||||
{
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
|
||||
Justification = "Makes a network request")]
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
||||
Task<IReadOnlyDictionary<string, Uri>> GetEmojis();
|
||||
Task<string> RenderRawMarkdown(string markdown);
|
||||
}
|
||||
}
|
||||
@@ -77,12 +77,12 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Clients\MiscellaneousClient.cs" />
|
||||
<Compile Include="Exceptions\ApiException.cs" />
|
||||
<Compile Include="ApiExtensions.cs" />
|
||||
<Compile Include="Clients\ApiClient.cs" />
|
||||
<Compile Include="Clients\AuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ApiPagination.cs" />
|
||||
<Compile Include="Clients\AutoCompleteClient.cs" />
|
||||
<Compile Include="Clients\OrganizationsClient.cs" />
|
||||
<Compile Include="Authentication\AnonymousAuthenticator.cs" />
|
||||
<Compile Include="Authentication\Authenticator.cs" />
|
||||
@@ -105,8 +105,8 @@
|
||||
<Compile Include="Http\InMemoryCredentialStore.cs" />
|
||||
<Compile Include="IApiPagination.cs" />
|
||||
<Compile Include="IAuthorizationsClient.cs" />
|
||||
<Compile Include="IAutoCompleteClient.cs" />
|
||||
<Compile Include="IGitHubClient.cs" />
|
||||
<Compile Include="IMiscellaneousClient.cs" />
|
||||
<Compile Include="IReleasesClient.cs" />
|
||||
<Compile Include="ISshKeysClient.cs" />
|
||||
<Compile Include="IOrganizationsClient.cs" />
|
||||
|
||||
@@ -108,7 +108,7 @@
|
||||
<Compile Include="Clients\ApiClient.cs" />
|
||||
<Compile Include="Clients\ApiPagination.cs" />
|
||||
<Compile Include="Clients\AuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\AutoCompleteClient.cs" />
|
||||
<Compile Include="Clients\MiscellaneousClient.cs" />
|
||||
<Compile Include="Clients\OrganizationsClient.cs" />
|
||||
<Compile Include="Clients\ReleasesClient.cs" />
|
||||
<Compile Include="Clients\RepositoriesClient.cs" />
|
||||
@@ -132,8 +132,8 @@
|
||||
<Compile Include="Http\ReadOnlyPagedCollection.cs" />
|
||||
<Compile Include="IApiPagination.cs" />
|
||||
<Compile Include="IAuthorizationsClient.cs" />
|
||||
<Compile Include="IAutoCompleteClient.cs" />
|
||||
<Compile Include="IGitHubClient.cs" />
|
||||
<Compile Include="IMiscellaneousClient.cs" />
|
||||
<Compile Include="IOrganizationsClient.cs" />
|
||||
<Compile Include="IReadOnlyPagedCollection.cs" />
|
||||
<Compile Include="Http\ApiInfoExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user