public void PostsToTheCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); var updateGist = new GistUpdate(); updateGist.Description = "my newly updated gist"; var gistFileUpdate = new GistFileUpdate { NewFileName = "myNewGistTestFile.cs", Content = "new GistsClient(connection).Edit();" }; updateGist.Files.Add("myGistTestFile.cs", gistFileUpdate); client.Edit("1", updateGist); connection.Received().Patch<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"), Arg.Any<object>()); }
/// <summary> /// Create a new instance of the GitHub API v3 client using the specified connection. /// </summary> /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param> public GitHubClient(IConnection connection) { Ensure.ArgumentNotNull(connection, "connection"); Connection = connection; var apiConnection = new ApiConnection(connection); Activity = new ActivitiesClient(apiConnection); Authorization = new AuthorizationsClient(apiConnection); Deployment = new DeploymentsClient(apiConnection); Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); Notification = new NotificationsClient(apiConnection); Oauth = new OauthClient(connection); Organization = new OrganizationsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Search = new SearchClient(apiConnection); SshKey = new SshKeysClient(apiConnection); User = new UsersClient(apiConnection); Reaction = new ReactionsClient(apiConnection); }
/// <summary> /// Create a new instance of the GitHub API v3 client using the specified connection. /// </summary> /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param> public GitHubClient(IConnection connection) { Ensure.ArgumentNotNull(connection, nameof(connection)); Connection = connection; var apiConnection = new ApiConnection(connection); Activity = new ActivitiesClient(apiConnection); Authorization = new AuthorizationsClient(apiConnection); Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); GitHubApps = new GitHubAppsClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); Miscellaneous = new MiscellaneousClient(apiConnection); Oauth = new OauthClient(connection); Organization = new OrganizationsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Search = new SearchClient(apiConnection); User = new UsersClient(apiConnection); Reaction = new ReactionsClient(apiConnection); Check = new ChecksClient(apiConnection); }
public void RequestsCorrectGetAllUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.GetAll(); connection.Received().GetAll<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists"), Args.ApiOptions); }
public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.Get("1"); connection.Received().Get<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"), null); }
public void RequestsCorrectGetAllWithSinceUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); DateTimeOffset since = DateTimeOffset.Now; client.GetAll(since); connection.Received().GetAll<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists"), Arg.Is<IDictionary<string,string>>(x => x.ContainsKey("since"))); }
public void RequestsCorrectGetAllWithSinceUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); DateTimeOffset since = DateTimeOffset.Now; client.GetAll(since); connection.Received().GetAll<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists"), DictionaryWithSince, Args.ApiOptions); }
public void RequestsCorrectGetAllUrlWithApiOptions() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; client.GetAll(options); connection.Received().GetAll<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists"), options); }
public void RequestsCorrectUnstarUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.Unstar("1"); connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "gists/1/star")); }
public async Task EnsuresArgumentsNotNull() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); Assert.Throws<ArgumentNullException>(() => client.Delete(null)); }
public void PostsToTheCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.Delete("1"); connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "gists/1")); }
public void RequestsCorrectGetCommitsUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.GetAllCommits("9257657"); connection.Received().GetAll<GistHistory>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/commits"), Args.ApiOptions); }
public void SetCommentsClient() { var apiConnection = Substitute.For<IApiConnection>(); var client = new GistsClient(apiConnection); Assert.NotNull(client.Comment); }
public void RequestsCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.Fork("1"); connection.Received().Post<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1/forks"), Arg.Any<object>()); }
public async Task ThrowsExceptionForInvalidStatusCode() { var response = Task.Factory.StartNew<IApiResponse<object>>(() => new ApiResponse<object>(new Response(HttpStatusCode.Conflict, null, new Dictionary<string, string>(), "application/json"))); var connection = Substitute.For<IConnection>(); connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "gists/1/star"), null, null).Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new GistsClient(apiConnection); await Assert.ThrowsAsync<ApiException>(() => client.IsStarred("1")); }
public void RequestsCorrectGetForksUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.GetAllForks("9257657"); connection.Received().GetAll<GistFork>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/forks")); }
public async Task EnsureNonNullArguments() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllCommits(null)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllCommits("")); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForks(null)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForks("")); }
public void RequestsCorrectGetAllWithSinceUrlAndApiOptions() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); var options = new ApiOptions { PageSize = 1, PageCount = 1, StartPage = 1 }; DateTimeOffset since = DateTimeOffset.Now; client.GetAll(since, options); connection.Received().GetAll<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists"), DictionaryWithSince, options); }
public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew<IResponse<object>>(() => new ApiResponse<object> { StatusCode = status }); var connection = Substitute.For<IConnection>(); connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "gists/1/star"), null, null).Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new GistsClient(apiConnection); var result = await client.IsStarred("1"); Assert.Equal(expected, result); }
public async Task ThrowsExceptionForInvalidStatusCode() { var response = Task.Factory.StartNew<IResponse<object>>(() => new ApiResponse<object> { StatusCode = HttpStatusCode.Conflict }); var connection = Substitute.For<IConnection>(); connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "gists/1/star"), null, null).Returns(response); var apiConnection = Substitute.For<IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new GistsClient(apiConnection); await AssertEx.Throws<ApiException>(async () => await client.IsStarred("1")); }
/// <summary> /// Create a new instance of the GitHub API v3 client using the specified connection. /// </summary> /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param> public GitHubClient(IConnection connection) { Ensure.ArgumentNotNull(connection, "connection"); Connection = connection; var apiConnection = new ApiConnection(connection); Authorization = new AuthorizationsClient(apiConnection); Activity = new ActivitiesClient(apiConnection); Issue = new IssuesClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); Notification = new NotificationsClient(apiConnection); Oauth = new OauthClient(connection); Organization = new OrganizationsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Gist = new GistsClient(apiConnection); Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); SshKey = new SshKeysClient(apiConnection); GitDatabase = new GitDatabaseClient(apiConnection); Search = new SearchClient(apiConnection); Deployment = new DeploymentsClient(apiConnection); }
public async Task EnsureNonNullArguments() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStarred(null)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStarred(DateTimeOffset.Now, null)); }
/// <summary> /// Create a new instance of the GitHub API v3 client using the specified connection. /// </summary> /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param> public GitHubClient(IConnection connection) { Ensure.ArgumentNotNull(connection, "connection"); Connection = connection; var apiConnection = new ApiConnection(connection); Authorization = new AuthorizationsClient(apiConnection); Activity = new ActivitiesClient(apiConnection); Blob = new BlobsClient(apiConnection); Issue = new IssuesClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); Notification = new NotificationsClient(apiConnection); Organization = new OrganizationsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Gist = new GistsClient(apiConnection); Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); SshKey = new SshKeysClient(apiConnection); GitDatabase = new GitDatabaseClient(apiConnection); Tree = new TreesClient(apiConnection); }
public void PostsToTheCorrectUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); var newGist = new NewGist(); newGist.Description = "my new gist"; newGist.Public = true; newGist.Files.Add("myGistTestFile.cs", "new GistsClient(connection).Create();"); client.Create(newGist); connection.Received().Post<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists"), Arg.Any<object>()); }
public async Task EnsureNonNullArguments() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("")); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", DateTimeOffset.Now)); await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", DateTimeOffset.Now, ApiOptions.None)); await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("user", DateTimeOffset.Now, null)); }
public void RequestsCorrectGetGistsForAUserUrl() { var connection = Substitute.For<IApiConnection>(); var client = new GistsClient(connection); client.GetAllForUser("octokit"); connection.Received().GetAll<Gist>(Arg.Is<Uri>(u => u.ToString() == "users/octokit/gists")); }
/// <summary> /// Create a new instance of the GitHub API v3 client using the specified connection. /// </summary> /// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param> public GitHubClient(IConnection connection) { Ensure.ArgumentNotNull(connection, "connection"); Connection = connection; var apiConnection = new ApiConnection(connection); Activity = new ActivitiesClient(apiConnection); Authorization = new AuthorizationsClient(apiConnection); Enterprise = new EnterpriseClient(apiConnection); Gist = new GistsClient(apiConnection); Git = new GitDatabaseClient(apiConnection); Issue = new IssuesClient(apiConnection); Migration = new MigrationClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); Oauth = new OauthClient(connection); Organization = new OrganizationsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Search = new SearchClient(apiConnection); User = new UsersClient(apiConnection); Reaction = new ReactionsClient(apiConnection); }