Skip to content

Commit

Permalink
Fix null test and add reactive version.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdziadkiewicz authored and shiftkey committed Feb 25, 2020
1 parent ee33acf commit bf0c1cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
9 changes: 9 additions & 0 deletions Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public interface IObservableMiscellaneousClient
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<LicenseMetadata> GetAllLicenses();

/// <summary>
/// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive
/// list of all possible OSS licenses.
/// </summary>
/// <remarks>This is a PREVIEW API! Use it at your own risk.</remarks>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of licenses available on the site</returns>
IObservable<LicenseMetadata> GetAllLicenses(ApiOptions options);

/// <summary>
/// Retrieves a license based on the license key such as "MIT"
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,19 @@ public IObservable<GitIgnoreTemplate> GetGitIgnoreTemplate(string templateName)
/// <returns>A list of licenses available on the site</returns>
public IObservable<LicenseMetadata> GetAllLicenses()
{
return _client.GetAllLicenses().ToObservable().SelectMany(l => l);
return GetAllLicenses(ApiOptions.None);
}

/// <summary>
/// Returns a list of the licenses shown in the license picker on GitHub.com. This is not a comprehensive
/// list of all possible OSS licenses.
/// </summary>
/// <remarks>This is a PREVIEW API! Use it at your own risk.</remarks>
/// <param name="options">Options for changing the API response</param>
/// <returns>A list of licenses available on the site</returns>
public IObservable<LicenseMetadata> GetAllLicenses(ApiOptions options)
{
return _client.GetAllLicenses(options).ToObservable().SelectMany(l => l);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Octokit.Tests/Clients/MiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,20 @@ public void EnsuresNonNullArguments()
public class TheGetAllLicensesMethod
{
[Fact]
public async void EnsuresNonNullArguments()
public void EnsuresNonNullArguments()
{
var client = new MiscellaneousClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllLicenses(null));
Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllLicenses(null));
}

[Fact]
public async Task RequestsTheLicensesEndpoint()
{
IReadOnlyList<LicenseMetadata> response = new ReadOnlyCollection<LicenseMetadata>(new List<LicenseMetadata>()
{
new LicenseMetadata("foo1", "foo2", "http://example.com/foo1" ),
new LicenseMetadata("bar1", "bar2", "http://example.com/bar1" )
new LicenseMetadata("foo1", "node-id-1", "foo2", "http://example.com/foo1", "something", true),
new LicenseMetadata("bar1", "node-id-1", "bar2", "http://example.com/bar1", "something else", false )
});
var connection = Substitute.For<IApiConnection>();
connection.GetAll<LicenseMetadata>(Args.Uri, null, AcceptHeaders.LicensesApiPreview, Args.ApiOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void CallsIntoClient()

client.GetAllLicenses();

gitHubClient.Miscellaneous.Received(1).GetAllLicenses();
gitHubClient.Miscellaneous.Received(1).GetAllLicenses(Args.ApiOptions);
}
}

Expand Down

0 comments on commit bf0c1cc

Please sign in to comment.