Files
octokit.net/Octokit.Tests/Clients/LicensesClientTests.cs
dependabot[bot] c895ac8efb build(deps): bump xunit from 2.6.1 to 2.6.3 (#2834)
* build(deps): bump xunit from 2.6.1 to 2.6.3

Bumps [xunit](https://github.com/xunit/xunit) from 2.6.1 to 2.6.3.
- [Commits](https://github.com/xunit/xunit/compare/2.6.1...2.6.3)

---
updated-dependencies:
- dependency-name: xunit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Add required async/awaits

* public async void --> public async Task

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Keegan Campbell <me@kfcampbell.com>
2023-12-18 13:07:52 -08:00

60 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;
namespace Octokit.Tests.Clients
{
public class LicensesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new LicensesClient(null));
}
}
public class TheGetAllLicensesMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new LicensesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllLicenses(null));
}
[Fact]
public async Task RequestsTheLicensesEndpoint()
{
IReadOnlyList<LicenseMetadata> response = new ReadOnlyCollection<LicenseMetadata>(new List<LicenseMetadata>()
{
new LicenseMetadata("foo1", "node-id-1", "foo2", "something", "http://example.com/foo1", true),
new LicenseMetadata("bar1", "node-id-1", "bar2", "something else", "http://example.com/bar1", false)
});
var connection = Substitute.For<IApiConnection>();
connection.GetAll<LicenseMetadata>(Arg.Is<Uri>(u => u.ToString() == "licenses"), Args.ApiOptions)
.Returns(Task.FromResult(response));
var client = new LicensesClient(connection);
var licenses = await client.GetAllLicenses();
Assert.Equal(2, licenses.Count);
Assert.Equal("foo1", licenses[0].Key);
Assert.Equal("foo2", licenses[0].Name);
Assert.Equal("http://example.com/foo1", licenses[0].Url);
Assert.Equal("bar1", licenses[1].Key);
Assert.Equal("bar2", licenses[1].Name);
Assert.Equal("http://example.com/bar1", licenses[1].Url);
connection.Received()
.GetAll<LicenseMetadata>(Arg.Is<Uri>(u => u.ToString() == "licenses"), Args.ApiOptions);
}
}
}
}