コード例 #1
0
        public void SetCommentsClient()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new GistsClient(apiConnection);

            Assert.NotNull(client.Comment);
        }
コード例 #2
0
        public async Task EnsuresArgumentsNotNull()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new GistsClient(connection);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Delete(null));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public async Task <IEnumerable <Gist> > GetAllStarredGistsForCurrentUser(GitHubClient authorizedGitHubClient)
 {
     if (_gistsClient == null)
     {
         _gistsClient = new GistsClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _gistsClient.GetAllStarred());
 }
コード例 #5
0
 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));
 }
コード例 #6
0
 public async Task <Gist> GetGist(string id, GitHubClient authorizedGitHubClient)
 {
     if (_gistsClient == null)
     {
         _gistsClient = new GistsClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _gistsClient.Get(id));
 }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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"));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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"));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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>());
        }
コード例 #15
0
        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")));
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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));
        }
コード例 #18
0
        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));
        }
コード例 #19
0
        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"));
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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>());
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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"));
        }
コード例 #25
0
        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"));
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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>());
        }