mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
Add Enterprise and EnterpriseAdminStats to Reactive project and tests
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reactive;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Admin Stats API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public interface IObservableEnterpriseAdminStatsClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets GitHub Enterprise statistics (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///https://developer.github.com/v3/enterprise/admin_stats/#get-statistics
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="AdminStats"/> collection for the requested <see cref="AdminStatsType"/> type.</returns>
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
||||
IObservable<AdminStats> GetStatistics(AdminStatsType type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/">Enterprise API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public interface IObservableEnterpriseClient
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Admin Stats API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
IObservableEnterpriseAdminStatsClient AdminStats { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reactive;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Admin Stats API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public class ObservableEnterpriseAdminStatsClient : IObservableEnterpriseAdminStatsClient
|
||||
{
|
||||
readonly IEnterpriseAdminStatsClient _client;
|
||||
|
||||
public ObservableEnterpriseAdminStatsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Enterprise.AdminStats;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets GitHub Enterprise statistics (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///https://developer.github.com/v3/enterprise/admin_stats/#get-statistics
|
||||
/// </remarks>
|
||||
/// <returns>The <see cref="AdminStats"/> collection for the requested <see cref="AdminStatsType"/> type.</returns>
|
||||
public IObservable<AdminStats> GetStatistics(AdminStatsType type)
|
||||
{
|
||||
return _client.GetStatistics(type).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/">Enterprise API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public class ObservableEnterpriseClient : IObservableEnterpriseClient
|
||||
{
|
||||
public ObservableEnterpriseClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
AdminStats = new ObservableEnterpriseAdminStatsClient(client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's Enterprise Admin Stats API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/enterprise/admin_stats/">Enterprise Admin Stats API documentation</a> for more information.
|
||||
///</remarks>
|
||||
public IObservableEnterpriseAdminStatsClient AdminStats { get; private set; }
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,10 @@
|
||||
<Compile Include="..\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\Enterprise\ObservableEnterpriseAdminStatsClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\IObservableEnterpriseAdminStatsClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\IObservableEnterpriseClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\ObservableEnterpriseClient.cs" />
|
||||
<Compile Include="Clients\IObservableMergingClient.cs" />
|
||||
<Compile Include="Clients\IObservableOauthClient.cs" />
|
||||
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
|
||||
|
||||
@@ -206,6 +206,7 @@
|
||||
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableFollowersTest.cs" />
|
||||
<Compile Include="Reactive\Enterprise\ObservableEnterpriseAdminStatsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableUserEmailsClientTests.cs" />
|
||||
<Compile Include="SelfTests.cs" />
|
||||
<Compile Include="SimpleJsonSerializerTests.cs" />
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests
|
||||
{
|
||||
public class ObservableEnterpriseAdminStatsClientTests
|
||||
{
|
||||
public class TheGetStatisticsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableEnterpriseAdminStatsClient(github);
|
||||
|
||||
foreach (AdminStatsType type in Enum.GetValues(typeof(AdminStatsType)))
|
||||
{
|
||||
var expectedUri = "enterprise/stats/{0}".FormatUri(type.ToString().ToLowerInvariant());
|
||||
client.GetStatistics(type);
|
||||
|
||||
github.Enterprise.AdminStats.Received(1).GetStatistics(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => new ObservableEnterpriseAdminStatsClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user