mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
added integration tests
This commit is contained in:
committed by
maddin2016
parent
c1115f548c
commit
4ca64d457d
@@ -20,6 +20,176 @@ namespace Octokit.Tests.Integration.Clients
|
||||
Assert.Equal("TeamBinary", masterFork.Owner.Login);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfForksWithoutStart()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
var forks = await github.Repository.Forks.GetAll("octokit", "octokit.net", options);
|
||||
|
||||
Assert.Equal(1, forks.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfForksWithStart()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
var forks = await github.Repository.Forks.GetAll("octokit", "octokit.net", options);
|
||||
|
||||
Assert.Equal(1, forks.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctForksBasedOnStartPage()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 3,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
var firstPage = await github.Repository.Forks.GetAll("octokit", "octokit.net", startOptions);
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 3,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var secondPage = await github.Repository.Forks.GetAll("octokit", "octokit.net", skipStartOptions);
|
||||
|
||||
Assert.Equal(3, firstPage.Count);
|
||||
Assert.Equal(3, secondPage.Count);
|
||||
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
|
||||
Assert.NotEqual(firstPage[1].Id, secondPage[1].Id);
|
||||
Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfForksWithoutStartParameterized()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest };
|
||||
|
||||
var forks = await github.Repository.Forks.GetAll("octokit", "octokit.net", repositoryForksListRequest, options);
|
||||
|
||||
Assert.Equal(1, forks.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfForksWithStartParameterized()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 1,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest };
|
||||
|
||||
var forks = await github.Repository.Forks.GetAll("octokit", "octokit.net", repositoryForksListRequest, options);
|
||||
|
||||
Assert.Equal(1, forks.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctForksBasedOnStartPageParameterized()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest };
|
||||
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 3,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
var firstPage = await github.Repository.Forks.GetAll("octokit", "octokit.net", repositoryForksListRequest, startOptions);
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 3,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var secondPage = await github.Repository.Forks.GetAll("octokit", "octokit.net", repositoryForksListRequest, skipStartOptions);
|
||||
|
||||
Assert.Equal(3, firstPage.Count);
|
||||
Assert.Equal(3, secondPage.Count);
|
||||
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
|
||||
Assert.NotEqual(firstPage[1].Id, secondPage[1].Id);
|
||||
Assert.NotEqual(firstPage[2].Id, secondPage[2].Id);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithApiOptions()
|
||||
{
|
||||
var github = Helper.GetAuthenticatedClient();
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Oldest };
|
||||
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 3,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
var firstPage = await github.Repository.Forks.GetAll("octokit", "octokit.net", repositoryForksListRequest, startOptions);
|
||||
var firstPageOrdered = firstPage.OrderBy(r => r.CreatedAt).ToList();
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
PageSize = 3,
|
||||
StartPage = 1
|
||||
};
|
||||
|
||||
var secondPage = await github.Repository.Forks.GetAll("octokit", "octokit.net", repositoryForksListRequest, skipStartOptions);
|
||||
var secondPageOrdered = secondPage.OrderBy(r => r.CreatedAt).ToList();
|
||||
|
||||
for (var index = 0; index < firstPage.Count; index++)
|
||||
{
|
||||
Assert.Equal(firstPageOrdered[index].FullName, firstPage[index].FullName);
|
||||
}
|
||||
|
||||
for (var index = 0; index < firstPage.Count; index++)
|
||||
{
|
||||
Assert.Equal(secondPageOrdered[index].FullName, secondPage[index].FullName);
|
||||
}
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirst()
|
||||
{
|
||||
|
||||
@@ -21,36 +21,93 @@ namespace Octokit.Tests.Clients
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
client.Forks.GetAll("fake", "repo");
|
||||
await client.Forks.GetAll("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"));
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRequestParameters()
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
client.Forks.GetAll("fake", "repo", new RepositoryForksListRequest { Sort = Sort.Stargazers });
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.Forks.GetAll("fake", "repo", options);
|
||||
|
||||
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRequestParameters()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
await client.Forks.GetAll("fake", "repo", new RepositoryForksListRequest { Sort = Sort.Stargazers });
|
||||
|
||||
connection.Received().GetAll<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"));
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRequestParametersWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.Forks.GetAll("fake", "repo", new RepositoryForksListRequest { Sort = Sort.Stargazers }, options);
|
||||
|
||||
connection.Received().GetAll<Repository>(
|
||||
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"),
|
||||
Arg.Is<Dictionary<string, string>>(d => d["sort"] == "stargazers"), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoryForksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Forks.GetAll(null, "name"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Forks.GetAll("owner", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name"));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", (ApiOptions)null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", new RepositoryForksListRequest()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, new RepositoryForksListRequest()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", (RepositoryForksListRequest)null));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", new RepositoryForksListRequest(), ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, new RepositoryForksListRequest(), ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", new RepositoryForksListRequest(), null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name"));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", ""));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", new RepositoryForksListRequest()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", new RepositoryForksListRequest()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", new RepositoryForksListRequest(), ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", new RepositoryForksListRequest(), ApiOptions.None));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +118,7 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
|
||||
var newRepositoryFork = new NewRepositoryFork();
|
||||
|
||||
client.Forks.Create("fake", "repo", newRepositoryFork);
|
||||
@@ -71,23 +129,14 @@ namespace Octokit.Tests.Clients
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
|
||||
var client = new RepositoryForksClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Forks.Create(null, "name", new NewRepositoryFork()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Forks.Create("owner", null, new NewRepositoryFork()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Forks.Create("owner", "name", null));
|
||||
}
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewRepositoryFork()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewRepositoryFork()));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
[Fact]
|
||||
public void UsesTheSuppliedHook()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoriesClient(connection);
|
||||
var newRepositoryFork = new NewRepositoryFork { Organization = "aName" };
|
||||
|
||||
client.Forks.Create("owner", "repo", newRepositoryFork);
|
||||
|
||||
connection.Received().Post<Repository>(Arg.Any<Uri>(), newRepositoryFork);
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewRepositoryFork()));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewRepositoryFork()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +239,7 @@
|
||||
<Compile Include="Reactive\ObservableRepositoryCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesEventsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryCommitsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryForksClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryPagesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableGistsTests.cs" />
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
using System;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableRepositoryForksClientTests
|
||||
{
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => new ObservableRepositoryForksClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
client.GetAll("fake", "repo");
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll("fake", "repo");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
client.GetAll("fake", "repo", options);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll("fake", "repo", options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRequestParameters()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Stargazers };
|
||||
|
||||
client.GetAll("fake", "repo", repositoryForksListRequest);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll(
|
||||
"fake", "repo", repositoryForksListRequest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRequestParametersWithApiOptions()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageCount = 1,
|
||||
StartPage = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Stargazers };
|
||||
|
||||
client.GetAll("fake", "repo", repositoryForksListRequest, options);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.GetAll("fake", "name", repositoryForksListRequest, options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableRepositoryForksClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name"));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", (ApiOptions)null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", new RepositoryForksListRequest()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, new RepositoryForksListRequest()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", (RepositoryForksListRequest)null));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", new RepositoryForksListRequest(), ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, new RepositoryForksListRequest(), ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", null, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", new RepositoryForksListRequest(), null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name"));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", new RepositoryForksListRequest()));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", new RepositoryForksListRequest()));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", new RepositoryForksListRequest(), ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", new RepositoryForksListRequest(), ApiOptions.None));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryForksClient(gitHubClient);
|
||||
|
||||
var newRepositoryFork = new NewRepositoryFork();
|
||||
|
||||
client.Create("fake", "repo", newRepositoryFork);
|
||||
|
||||
gitHubClient.Received().Repository.Forks.Create("fake", "repo", newRepositoryFork);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableRepositoryForksClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewRepositoryFork()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewRepositoryFork()));
|
||||
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewRepositoryFork()));
|
||||
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewRepositoryFork()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user