Skip to content

Commit

Permalink
Merge pull request #1226 from dampir/fix-incos-get-all
Browse files Browse the repository at this point in the history
Some ArgumentNotNullOrEmptyString cheсks were added in ObservableAssigneesClient
  • Loading branch information
ryangribble committed Mar 29, 2016
2 parents 6455001 + 1ae8235 commit 5e37684
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Octokit.Reactive/Clients/ObservableAssigneesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public ObservableAssigneesClient(IGitHubClient client)
/// <returns></returns>
public IObservable<User> GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return GetAllForRepository(owner, name, ApiOptions.None);
}

Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<Compile Include="Reactive\Enterprise\ObservableEnterpriseSearchIndexingClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseOrganizationClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseLicenseClientTests.cs" />
<Compile Include="Reactive\ObservableAssigneesClientTests.cs" />
<Compile Include="Reactive\ObservableAuthorizationsClientTests.cs" />
<Compile Include="Reactive\ObservableBlobClientTests.cs" />
<Compile Include="Reactive\ObservableCommitsClientTests.cs" />
Expand Down
123 changes: 123 additions & 0 deletions Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Xunit;

namespace Octokit.Tests.Reactive
{
public class ObservableAssigneesClientTests
{
private const string owner = "owner";
private const string name = "name";
private const string assignee = "assignee";

public class TheGetAllMethod
{
private readonly Uri _expectedUri;

public TheGetAllMethod()
{
var uri = string.Format("repos/{0}/{1}/assignees", owner, name);
_expectedUri = new Uri(uri, UriKind.Relative);
}

[Fact]
public void RequestsCorrectUrl()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableAssigneesClient(github);

client.GetAllForRepository(owner, name);

github.Connection.Received(1).Get<List<User>>(_expectedUri,
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
}

[Fact]
public void RequestsCorrectUrlWithApiOption()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableAssigneesClient(github);

client.GetAllForRepository(owner, name, new ApiOptions {PageSize = 1, StartPage = 1});

github.Connection.Received(1).Get<List<User>>(_expectedUri,
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2), null);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableAssigneesClient(github);

Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, name));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(owner, null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(owner, name, null));
}

[Fact]
public void EnsuresNonEmptyArguments()
{
var client = CreateFixtureWithNonReactiveClient();

Assert.Throws<ArgumentException>(() => client.GetAllForRepository(string.Empty, name));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository(owner, string.Empty));
}
}

private static ObservableAssigneesClient CreateFixtureWithNonReactiveClient()
{
var nonreactiveClient = new AssigneesClient(Substitute.For<IApiConnection>());
var github = Substitute.For<IGitHubClient>();
github.Issue.Assignee.Returns(nonreactiveClient);
return new ObservableAssigneesClient(github);
}

public class TheCheckAssigneeMethod
{
[Fact]
public void CallsCheckAssigneeOnClient()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableAssigneesClient(github);

client.CheckAssignee(owner, name, assignee);

github.Issue.Assignee.Received(1).CheckAssignee(Arg.Is(owner), Arg.Is(name), Arg.Is(assignee));
}

[Fact]
public void EnsuresNonNullArguments()
{
var client = CreateFixtureWithNonReactiveClient();

Assert.Throws<ArgumentNullException>(() => client.CheckAssignee(null, name, assignee));
Assert.Throws<ArgumentNullException>(() => client.CheckAssignee(owner, null, assignee));
Assert.Throws<ArgumentNullException>(() => client.CheckAssignee(owner, name, null));
}

[Fact]
public void EnsuresNonEmptyArguments()
{
var client = CreateFixtureWithNonReactiveClient();

Assert.Throws<ArgumentException>(() => client.CheckAssignee(string.Empty, name, assignee));
Assert.Throws<ArgumentException>(() => client.CheckAssignee(owner, string.Empty, assignee));
Assert.Throws<ArgumentException>(() => client.CheckAssignee(owner, name, string.Empty));
}
}

public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(
() => new ObservableAssigneesClient(null));
}
}
}
}

0 comments on commit 5e37684

Please sign in to comment.