Ejemplo n.º 1
0
        public void SetCommentsClient()
        {
            var apiConnection = Substitute.For <IApiConnection>();
            var client        = new GistsClient(apiConnection);

            Assert.NotNull(client.Comment);
        }
Ejemplo n.º 2
0
        public async Task EnsuresArgumentsNotNull()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new GistsClient(connection);

            await Assert.ThrowsAsync <ArgumentNullException>(() => client.Delete(null));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
 public async Task <IEnumerable <Gist> > GetAllStarredGistsForCurrentUser(GitHubClient authorizedGitHubClient)
 {
     if (_gistsClient == null)
     {
         _gistsClient = new GistsClient(new ApiConnection(authorizedGitHubClient.Connection));
     }
     return(await _gistsClient.GetAllStarred());
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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>());
        }
Ejemplo n.º 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")));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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>());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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>());
        }