mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-08 20:45:51 +00:00
3c818934b8
* Add release notes and bump version to 0.24 * run "build FormatCode" to fix up whitespace/formatting issues * Fix failing Ssh key tests due to "validation exception". This key must be in use on github (under another user, most likely from these tests failing). Changed to a new SSH key and tweaked tests to reduce chance of a key being created and not destroyed * Assignee and Assignees cant both be specified on NewIssue. We missed this one in the PR. Marked Assignee as [Obsolete] and fixed tests to use Assignees * Fix a couple of Reactions tests that were calling the wrong client methods * Fix timeline tests - looks like the response class has changed shape a bit, it now has an Issue object in the payload and Id field isnt present (leaving Id field there in case other timeline events do use it) * Fix some following tests that require the test user to follow more than 1 other user * Unskip these Event tests now because apparently they work! * add breaking changes notes * Update ApiErrorMessageSafe to return null for empty and whitespace strings (#1540) * return null if ApiError.Message is empty or whitespace * Uncomment test, which now passes * update release notes to include PR1540 * Add "Bot" AccountType, was causing a deserialization exception when running the integration test "SearchForExcludedLanguage" (#1541) * Update to include PR1541 * add bullets to make release notes easier to read * markup additional code mentions in notes * Fix grammar fields => field
268 lines
10 KiB
C#
268 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reactive.Linq;
|
|
using System.Threading.Tasks;
|
|
using NSubstitute;
|
|
using Octokit.Reactive.Clients;
|
|
using Octokit.Tests.Helpers;
|
|
using Xunit;
|
|
|
|
namespace Octokit.Tests.Reactive
|
|
{
|
|
public class ObservableDeploymentsClientTests
|
|
{
|
|
public class TheGetAllMethod
|
|
{
|
|
private readonly IGitHubClient _githubClient;
|
|
private readonly ObservableDeploymentsClient _client;
|
|
private const string owner = "owner";
|
|
private const string name = "name";
|
|
private const long repositoryId = 1;
|
|
|
|
public TheGetAllMethod()
|
|
{
|
|
_githubClient = Substitute.For<IGitHubClient>();
|
|
_client = new ObservableDeploymentsClient(_githubClient);
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsuresNonNullArguments()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, name));
|
|
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, null));
|
|
Assert.Throws<ArgumentNullException>(() => _client.GetAll(owner, name, null));
|
|
|
|
Assert.Throws<ArgumentNullException>(() => _client.GetAll(repositoryId, null));
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsuresNonEmptyArguments()
|
|
{
|
|
Assert.Throws<ArgumentException>(() => _client.GetAll("", name));
|
|
Assert.Throws<ArgumentException>(() => _client.GetAll(owner, ""));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task EnsuresNonWhitespaceArguments()
|
|
{
|
|
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
|
async whitespace => await _client.GetAll(whitespace, name));
|
|
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
|
async whitespace => await _client.GetAll(owner, whitespace));
|
|
}
|
|
|
|
[Fact]
|
|
public void RequestsCorrectUrl()
|
|
{
|
|
var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name);
|
|
|
|
_client.GetAll(owner, name);
|
|
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
|
Arg.Any<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void RequestsCorrectUrlWithRepositoryId()
|
|
{
|
|
var expectedUrl = string.Format("repositories/{0}/deployments", repositoryId);
|
|
|
|
_client.GetAll(repositoryId);
|
|
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
|
Arg.Any<string>());
|
|
}
|
|
|
|
[Fact]
|
|
public void RequestsCorrectUrlWithApiOptions()
|
|
{
|
|
var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name);
|
|
|
|
// all properties are setted => only 2 options (StartPage, PageSize) in dictionary
|
|
var options = new ApiOptions
|
|
{
|
|
StartPage = 1,
|
|
PageCount = 1,
|
|
PageSize = 1
|
|
};
|
|
|
|
_client.GetAll(owner, name, options);
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
|
|
null);
|
|
|
|
// StartPage is setted => only 1 option (StartPage) in dictionary
|
|
options = new ApiOptions
|
|
{
|
|
StartPage = 1
|
|
};
|
|
|
|
_client.GetAll(owner, name, options);
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
|
null);
|
|
|
|
// PageCount is setted => none of options in dictionary
|
|
options = new ApiOptions
|
|
{
|
|
PageCount = 1
|
|
};
|
|
|
|
_client.GetAll(owner, name, options);
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
|
null);
|
|
}
|
|
|
|
[Fact]
|
|
public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
|
{
|
|
var expectedUrl = string.Format("repositories/{0}/deployments", repositoryId);
|
|
|
|
// all properties are setted => only 2 options (StartPage, PageSize) in dictionary
|
|
var options = new ApiOptions
|
|
{
|
|
StartPage = 1,
|
|
PageCount = 1,
|
|
PageSize = 1
|
|
};
|
|
|
|
_client.GetAll(repositoryId, options);
|
|
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
|
|
null);
|
|
|
|
// StartPage is setted => only 1 option (StartPage) in dictionary
|
|
options = new ApiOptions
|
|
{
|
|
StartPage = 1
|
|
};
|
|
|
|
_client.GetAll(repositoryId, options);
|
|
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
|
|
null);
|
|
|
|
// PageCount is setted => none of options in dictionary
|
|
options = new ApiOptions
|
|
{
|
|
PageCount = 1
|
|
};
|
|
|
|
_client.GetAll(repositoryId, options);
|
|
|
|
_githubClient.Connection.Received(1)
|
|
.Get<List<Deployment>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
|
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
|
|
null);
|
|
}
|
|
}
|
|
|
|
public class TheCreateMethod
|
|
{
|
|
private readonly IGitHubClient _githubClient;
|
|
private ObservableDeploymentsClient _client;
|
|
|
|
public TheCreateMethod()
|
|
{
|
|
_githubClient = Substitute.For<IGitHubClient>();
|
|
}
|
|
|
|
private void SetupWithoutNonReactiveClient()
|
|
{
|
|
_client = new ObservableDeploymentsClient(_githubClient);
|
|
}
|
|
|
|
private void SetupWithNonReactiveClient()
|
|
{
|
|
var deploymentsClient = new DeploymentsClient(Substitute.For<IApiConnection>());
|
|
_githubClient.Repository.Deployment.Returns(deploymentsClient);
|
|
_client = new ObservableDeploymentsClient(_githubClient);
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsuresNonNullArguments()
|
|
{
|
|
SetupWithNonReactiveClient();
|
|
|
|
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", new NewDeployment("ref")));
|
|
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, new NewDeployment("ref")));
|
|
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", null));
|
|
|
|
Assert.Throws<ArgumentNullException>(() => _client.Create(1, null));
|
|
}
|
|
|
|
[Fact]
|
|
public void EnsuresNonEmptyArguments()
|
|
{
|
|
SetupWithNonReactiveClient();
|
|
|
|
Assert.Throws<ArgumentException>(() => _client.Create("", "repo", new NewDeployment("ref")));
|
|
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", new NewDeployment("ref")));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task EnsuresNonWhitespaceArguments()
|
|
{
|
|
SetupWithNonReactiveClient();
|
|
|
|
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
|
async whitespace => await _client.Create(whitespace, "repo", new NewDeployment("ref")));
|
|
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
|
async whitespace => await _client.Create("owner", whitespace, new NewDeployment("ref")));
|
|
}
|
|
|
|
[Fact]
|
|
public void CallsCreateOnRegularDeploymentsClient()
|
|
{
|
|
SetupWithoutNonReactiveClient();
|
|
|
|
var newDeployment = new NewDeployment("ref");
|
|
|
|
_client.Create("owner", "repo", newDeployment);
|
|
|
|
_githubClient.Repository.Deployment.Received(1).Create("owner", "repo", newDeployment);
|
|
}
|
|
|
|
[Fact]
|
|
public void CallsCreateOnRegularDeploymentsClientWithRepositoryId()
|
|
{
|
|
SetupWithoutNonReactiveClient();
|
|
|
|
var newDeployment = new NewDeployment("ref");
|
|
|
|
_client.Create(1, newDeployment);
|
|
|
|
_githubClient.Repository.Deployment.Received(1).Create(1, newDeployment);
|
|
}
|
|
}
|
|
|
|
public class TheCtor
|
|
{
|
|
[Fact]
|
|
public void EnsuresNonNullArguments()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(() => new ObservableDeploymentsClient(null));
|
|
}
|
|
|
|
[Fact]
|
|
public void SetsStatusesClient()
|
|
{
|
|
var client = new ObservableDeploymentsClient(Substitute.For<IGitHubClient>());
|
|
Assert.NotNull(client.Status);
|
|
}
|
|
}
|
|
}
|
|
}
|