reactive unit tests

reactive unit tests
This commit is contained in:
Timothy Haagenson
2014-07-09 10:53:06 -05:00
parent 3f18b667bc
commit de56f0ba6d
2 changed files with 56 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ namespace Octokit.Reactive
{ {
Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(reference, "reference"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return _commit.Get(owner, name, reference).ToObservable(); return _commit.Get(owner, name, reference).ToObservable();
} }

View File

@@ -188,6 +188,61 @@ namespace Octokit.Tests.Reactive
} }
} }
public class TheGetCommitMethod
{
[Fact]
public void EnsuresArguments()
{
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.Commits.Get(null, "repo", "reference"));
Assert.Throws<ArgumentNullException>(() => client.Commits.Get("owner", null, "reference"));
Assert.Throws<ArgumentNullException>(() => client.Commits.Get("owner", "repo", null));
Assert.Throws<ArgumentException>(() => client.Commits.Get("", "repo", "reference"));
Assert.Throws<ArgumentException>(() => client.Commits.Get("owner", "", "reference"));
Assert.Throws<ArgumentException>(() => client.Commits.Get("owner", "repo", ""));
}
[Fact]
public void GetsCorrectUrl()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoriesClient(github);
var expected = new Uri("repos/owner/repo/commits/reference", UriKind.Relative);
client.Commits.Get("owner", "repo", "reference");
github.Repository.Commits.Received(1).Get("owner", "repo", "reference");
}
}
public class TheGetAllCommitsMethod
{
[Fact]
public void EnsuresArguments()
{
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.Commits.GetAll(null, "repo"));
Assert.Throws<ArgumentNullException>(() => client.Commits.GetAll("owner", null));
Assert.Throws<ArgumentNullException>(() => client.Commits.GetAll("owner", "repo", null));
Assert.Throws<ArgumentException>(() => client.Commits.GetAll("", "repo"));
Assert.Throws<ArgumentException>(() => client.Commits.GetAll("owner", ""));
}
[Fact]
public void GetsCorrectUrl()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoriesClient(github);
var expected = new Uri("repos/owner/repo/commits", UriKind.Relative);
client.Commits.GetAll("owner", "repo");
github.Connection.Received(1).Get<List<GitHubCommit>>(expected, Arg.Any<IDictionary<string, string>>(), null);
}
}
public class TheGetAllContributorsMethod public class TheGetAllContributorsMethod
{ {
[Fact] [Fact]