mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 11:05:56 +00:00
added new unit tests
This commit is contained in:
@@ -21,12 +21,12 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async void RequestsCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var releasesClient = new ReleasesClient(client);
|
||||
|
||||
releasesClient.GetAll("fake", "repo");
|
||||
await releasesClient.GetAll("fake", "repo");
|
||||
|
||||
client.Received().GetAll<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases"),
|
||||
null,
|
||||
@@ -35,7 +35,7 @@ namespace Octokit.Tests.Clients
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
public async void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var releasesClient = new ReleasesClient(client);
|
||||
@@ -47,7 +47,7 @@ namespace Octokit.Tests.Clients
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
releasesClient.GetAll("fake", "repo", options);
|
||||
await releasesClient.GetAll("fake", "repo", options);
|
||||
|
||||
client.Received().GetAll<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases"),
|
||||
null,
|
||||
@@ -73,12 +73,12 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetReleaseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
client.Get("fake", "repo", 1);
|
||||
await client.Get("fake", "repo", 1);
|
||||
|
||||
connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1"));
|
||||
}
|
||||
@@ -98,12 +98,12 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetLatestReleaseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
client.GetLatest("fake", "repo");
|
||||
await client.GetLatest("fake", "repo");
|
||||
|
||||
connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/latest"));
|
||||
}
|
||||
@@ -122,13 +122,13 @@ namespace Octokit.Tests.Clients
|
||||
public class TheCreateReleaseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async void RequestsCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var releasesClient = new ReleasesClient(client);
|
||||
var data = new NewRelease("fake-tag");
|
||||
|
||||
releasesClient.Create("fake", "repo", data);
|
||||
await releasesClient.Create("fake", "repo", data);
|
||||
|
||||
client.Received().Post<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases"),
|
||||
data,
|
||||
@@ -151,13 +151,13 @@ namespace Octokit.Tests.Clients
|
||||
public class TheEditReleaseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var releasesClient = new ReleasesClient(connection);
|
||||
var data = new ReleaseUpdate { TagName = "fake-tag" };
|
||||
|
||||
releasesClient.Edit("fake", "repo", 1, data);
|
||||
await releasesClient.Edit("fake", "repo", 1, data);
|
||||
|
||||
connection.Received().Patch<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1"), data);
|
||||
}
|
||||
@@ -179,12 +179,12 @@ namespace Octokit.Tests.Clients
|
||||
public class TheDeleteReleaseMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
client.Delete("fake", "repo", 1);
|
||||
await client.Delete("fake", "repo", 1);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1"));
|
||||
}
|
||||
@@ -204,26 +204,54 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetAssetsMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
client.GetAllAssets("fake", "repo", 1);
|
||||
await client.GetAllAssets("fake", "repo", 1);
|
||||
|
||||
connection.Received().GetAll<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1/assets"),
|
||||
null,
|
||||
"application/vnd.github.v3");
|
||||
"application/vnd.github.v3",
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void RequestsTheCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAllAssets("fake", "repo", 1, options);
|
||||
|
||||
connection.Received().GetAll<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1/assets"),
|
||||
null,
|
||||
"application/vnd.github.v3", options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ReleasesClient(Substitute.For<IApiConnection>());
|
||||
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets(null, null, 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets(null, "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAssets("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets("owner", null, 1));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets(null, null, 1, null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets(null, null, 1, Args.ApiOptions));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets(null, "name", 1, null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllAssets("owner", null, 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAssets("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllAssets("owner", "", 1));
|
||||
}
|
||||
}
|
||||
@@ -231,7 +259,7 @@ namespace Octokit.Tests.Clients
|
||||
public class TheUploadReleaseAssetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void UploadsToCorrectUrl()
|
||||
public async void UploadsToCorrectUrl()
|
||||
{
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
var releasesClient = new ReleasesClient(client);
|
||||
@@ -239,7 +267,7 @@ namespace Octokit.Tests.Clients
|
||||
var rawData = Substitute.For<Stream>();
|
||||
var upload = new ReleaseAssetUpload("example.zip", "application/zip", rawData, null);
|
||||
|
||||
releasesClient.UploadAsset(release, upload);
|
||||
await releasesClient.UploadAsset(release, upload);
|
||||
|
||||
client.Received().Post<ReleaseAsset>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"),
|
||||
@@ -280,12 +308,12 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetAssetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
client.GetAsset("fake", "repo", 1);
|
||||
await client.GetAsset("fake", "repo", 1);
|
||||
|
||||
connection.Received().Get<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/assets/1"));
|
||||
}
|
||||
@@ -305,13 +333,13 @@ namespace Octokit.Tests.Clients
|
||||
public class TheEditAssetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
var data = new ReleaseAssetUpdate("asset");
|
||||
|
||||
client.EditAsset("fake", "repo", 1, data);
|
||||
await client.EditAsset("fake", "repo", 1, data);
|
||||
|
||||
connection.Received().Patch<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/assets/1"),
|
||||
data);
|
||||
@@ -333,12 +361,12 @@ namespace Octokit.Tests.Clients
|
||||
public class TheDeleteAssetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
public async void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReleasesClient(connection);
|
||||
|
||||
client.DeleteAsset("fake", "repo", 1);
|
||||
await client.DeleteAsset("fake", "repo", 1);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/assets/1"));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reactive.Linq;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
@@ -181,7 +182,26 @@ namespace Octokit.Tests.Reactive
|
||||
client.GetAllAssets("fake", "repo", 1);
|
||||
|
||||
gitHubClient.Connection.Received(1).Get<List<ReleaseAsset>>(
|
||||
new Uri("repos/fake/repo/releases/1/assets", UriKind.Relative), null, null);
|
||||
new Uri("repos/fake/repo/releases/1/assets", UriKind.Relative), Args.EmptyDictionary, null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrlWithApiOptions()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableReleasesClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
client.GetAllAssets("fake", "repo", 1, options);
|
||||
|
||||
gitHubClient.Connection.Received(1).Get<List<ReleaseAsset>>(
|
||||
new Uri("repos/fake/repo/releases/1/assets", UriKind.Relative), Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2), null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -189,9 +209,16 @@ namespace Octokit.Tests.Reactive
|
||||
{
|
||||
var client = new ObservableReleasesClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets(null, null, 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets(null, "name", 1));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllAssets("", "name", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets("owner", null, 1));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets(null, null, 1, null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets(null, null, 1, Args.ApiOptions));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets(null, "name", 1, null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAllAssets("owner", null, 1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllAssets("", "name", 1));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllAssets("owner", "", 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user