public void SetCommentsClient() { var apiConnection = Substitute.For <IApiConnection>(); var client = new GistsClient(apiConnection); Assert.NotNull(client.Comment); }
public async Task EnsuresArgumentsNotNull() { var connection = Substitute.For <IApiConnection>(); var client = new GistsClient(connection); await Assert.ThrowsAsync <ArgumentNullException>(() => client.Delete(null)); }
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 async Task <IEnumerable <Gist> > GetAllStarredGistsForCurrentUser(GitHubClient authorizedGitHubClient) { if (_gistsClient == null) { _gistsClient = new GistsClient(new ApiConnection(authorizedGitHubClient.Connection)); } return(await _gistsClient.GetAllStarred()); }
public async Task <IEnumerable <Gist> > GetAllPublicGistsForUser(string userName, GitHubClient githubClient) { if (_gistsClient == null) { _gistsClient = new GistsClient(new ApiConnection(githubClient.Connection)); } return(await _gistsClient.GetAllForUser(userName)); }
public async Task <Gist> GetGist(string id, GitHubClient authorizedGitHubClient) { if (_gistsClient == null) { _gistsClient = new GistsClient(new ApiConnection(authorizedGitHubClient.Connection)); } return(await _gistsClient.Get(id)); }
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 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 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 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 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")); }
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"), Args.ApiOptions); }
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)); }
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 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 async Task EnsureNonNullArguments() { var connection = Substitute.For <IApiConnection>(); var client = new GistsClient(connection); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForks(null)); await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForks("")); await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForks("id", null)); await Assert.ThrowsAsync <ArgumentException>(() => client.GetAllForks("", ApiOptions.None)); }
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 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 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 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 RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { var response = Task.Factory.StartNew <IApiResponse <object> >(() => new ApiResponse <object>(new Response(status, 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); var result = await client.IsStarred("1"); Assert.Equal(expected, result); }
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 ThrowsExceptionForInvalidStatusCode() { var response = Task.Factory.StartNew <IResponse <object> >(() => new ApiResponse <object> { StatusCode = HttpStatusCode.Conflict }); var connection = Substitute.For <IConnection>(); connection.GetAsync <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); AssertEx.Throws <ApiException>(async() => await client.IsStarred("1")); }
public async Task ThrowsExceptionForInvalidStatusCode() { var response = CreateResponse(HttpStatusCode.Conflict); var responseTask = Task.FromResult <IApiResponse <object> >(new ApiResponse <object>(response)); var connection = Substitute.For <IConnection>(); connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "gists/1/star"), null, null) .Returns(responseTask); var apiConnection = Substitute.For <IApiConnection>(); apiConnection.Connection.Returns(connection); var client = new GistsClient(apiConnection); await Assert.ThrowsAsync <ApiException>(() => client.IsStarred("1")); }
public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) { var response = CreateResponse(status); var responseTask = Task.FromResult <IApiResponse <object> >(new ApiResponse <object>(response)); var connection = Substitute.For <IConnection>(); connection.Get <object>(Arg.Is <Uri>(u => u.ToString() == "gists/1/star"), null, null) .Returns(responseTask); 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 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>()); }