added unit tests

This commit is contained in:
aedampir@gmail.com
2016-05-22 18:58:27 +07:00
parent 2a18c682b6
commit b0a2cfe987
2 changed files with 190 additions and 11 deletions
+82 -2
View File
@@ -44,7 +44,26 @@ namespace Octokit.Tests.Clients
await client.GetAllForRepository("fake", "repo");
connection.Received().GetAll<Milestone>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones"),
Arg.Any<Dictionary<string, string>>());
Arg.Any<Dictionary<string, string>>(), Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new MilestonesClient(connection);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
await client.GetAllForRepository("fake", "repo", options);
connection.Received().GetAll<Milestone>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones"),
Arg.Any<Dictionary<string, string>>(), options);
}
[Fact]
@@ -59,7 +78,68 @@ namespace Octokit.Tests.Clients
Arg.Is<Dictionary<string, string>>(d => d.Count == 3
&& d["direction"] == "desc"
&& d["state"] == "open"
&& d["sort"] == "due_date"));
&& d["sort"] == "due_date"), Args.ApiOptions);
}
[Fact]
public void SendsAppropriateParametersWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new MilestonesClient(connection);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
client.GetAllForRepository("fake", "repo", new MilestoneRequest { SortDirection = SortDirection.Descending }, options);
connection.Received().GetAll<Milestone>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones"),
Arg.Is<Dictionary<string, string>>(d => d.Count == 3
&& d["direction"] == "desc"
&& d["state"] == "open"
&& d["sort"] == "due_date"), options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new MilestonesClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", new MilestoneRequest()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, new MilestoneRequest()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", ""));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", new MilestoneRequest()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", new MilestoneRequest()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", new MilestoneRequest(), new ApiOptions()));
}
}
@@ -40,7 +40,106 @@ namespace Octokit.Tests.Reactive
public class TheGetForRepositoryMethod
{
[Fact]
public async Task ReturnsEveryPageOfMilestones()
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMilestonesClient(gitHubClient);
client.GetAllForRepository("fake", "repo");
gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo");
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMilestonesClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
client.GetAllForRepository("fake", "repo", options);
gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", options);
}
[Fact]
public void SendsAppropriateParameters()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMilestonesClient(gitHubClient);
var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending };
client.GetAllForRepository("fake", "repo", milestoneRequest);
gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, Args.ApiOptions);
}
[Fact]
public void SendsAppropriateParametersWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMilestonesClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending };
client.GetAllForRepository("fake", "repo", milestoneRequest, options);
gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, options);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableMilestonesClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", new MilestoneRequest()));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, new MilestoneRequest()));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), new ApiOptions()));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", ""));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name"));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", ""));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", new ApiOptions()));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", new ApiOptions()));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", new MilestoneRequest()));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", new MilestoneRequest()));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), new ApiOptions()));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", new MilestoneRequest(), new ApiOptions()));
}
[Fact]
public void ReturnsEveryPageOfMilestones()
{
var firstPageUrl = new Uri("repos/fake/repo/milestones", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
@@ -84,7 +183,7 @@ namespace Octokit.Tests.Reactive
.Returns(Task.Factory.StartNew<IApiResponse<List<Milestone>>>(() => lastPageResponse));
var client = new ObservableMilestonesClient(gitHubClient);
var results = await client.GetAllForRepository("fake", "repo").ToArray();
var results = client.GetAllForRepository("fake", "repo").ToArray().Wait();
Assert.Equal(7, results.Length);
Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number);
@@ -93,7 +192,7 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public async Task SendsAppropriateParameters()
public async Task SendsAppropriateParametersMulti()
{
var firstPageUrl = new Uri("repos/fake/repo/milestones", UriKind.Relative);
var secondPageUrl = new Uri("https://example.com/page/2");
@@ -198,11 +297,11 @@ namespace Octokit.Tests.Reactive
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMilestonesClient(gitHubClient);
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewMilestone("title")));
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewMilestone("x")));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewMilestone("x")));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewMilestone("x")));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.Update(null, "name", 42, new MilestoneUpdate()));
Assert.Throws<ArgumentException>(() => client.Update("", "name", 42, new MilestoneUpdate()));
Assert.Throws<ArgumentNullException>(() => client.Update("owner", null, 42, new MilestoneUpdate()));
Assert.Throws<ArgumentException>(() => client.Update("owner", "", 42, new MilestoneUpdate()));
Assert.Throws<ArgumentNullException>(() => client.Update("owner", "name", 42, null));
}
}
@@ -237,7 +336,7 @@ namespace Octokit.Tests.Reactive
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new MilestonesClient(null));
Assert.Throws<ArgumentNullException>(() => new ObservableMilestonesClient(null));
}
}