public void EnsuresNonNullArguments()
        {
            var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>());

            var options = new ApiOptions();
            var request = new RepositoryIssueRequest();

            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name"));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", options));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, options));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request, options));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request, options));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, options));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request, null));

            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, (ApiOptions)null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, (RepositoryIssueRequest)null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, null, options));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, request, null));

            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name"));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", ""));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", options));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", options));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", request));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", request));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name", request, options));
            Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", "", request, options));
        }
        public async Task EnsuresArgumentsNotNull()
        {
            var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>());

            var options = new ApiOptions();
            var request = new RepositoryIssueRequest();

            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name").ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", options).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", request, options).ToTask());

            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name").ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", options).ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request).ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name", request, options).ToTask());

            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, options).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, request, options).ToTask());

            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "").ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", options).ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request).ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", "", request, options).ToTask());

            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (ApiOptions)null).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null).ToTask());

            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, options).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request, null).ToTask());
        }
        public async Task EnsuresNonNullArguments()
        {
            var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>());

            await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", 1).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, 1).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "", 1).ToTask());
            await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", null, 1).ToTask());
        }
        public void GetsFromClientIssueIssueWithRepositoryId()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Get(1, 42);

            gitHubClient.Issue.Received().Get(1, 42);
        }
    public ObservableIssuesClientTests()
    {
        var github = Helper.GetAuthenticatedClient();

        _client = new ObservableIssuesClient(github);

        var repoName = Helper.MakeNameWithTimestamp("public-repo");
        _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
    }
    public ObservableIssuesClientTests()
    {
        var github = Helper.GetAuthenticatedClient();

        _client = new ObservableIssuesClient(github);
        _repoName = Helper.MakeNameWithTimestamp("public-repo");
        var result = github.Repository.Create(new NewRepository { Name = _repoName }).Result;
        _createdRepository = result;
    }
        public void GetsFromClientIssueIssue()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Get("fake", "repo", 42);

            gitHubClient.Issue.Received().Get("fake", "repo", 42);
        }
        public void EnsuresNonNullArguments()
        {
            var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>());

            Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", 1));
            Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, 1));

            Assert.Throws<ArgumentException>(() => client.Get("owner", "", 1));
            Assert.Throws<ArgumentException>(() => client.Get("", "name", 1));
        }
    public ObservableIssuesClientTests()
    {
        var github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
        {
            Credentials = Helper.Credentials
        };

        _client = new ObservableIssuesClient(github);
        _repoName = Helper.MakeNameWithTimestamp("public-repo");
        var result = github.Repository.Create(new NewRepository { Name = _repoName }).Result;
        _createdRepository = result;
    }
Exemplo n.º 10
0
        public ObservableGitHubClient(IGitHubClient gitHubClient)
        {
            Ensure.ArgumentNotNull(gitHubClient, "githubClient");

            _gitHubClient = gitHubClient;
            Authorization = new ObservableAuthorizationsClient(gitHubClient);
            Activity = new ObservableActivitiesClient(gitHubClient);
            Issue = new ObservableIssuesClient(gitHubClient);
            Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous);
            Notification = new ObservableNotificationsClient(gitHubClient);
            Organization = new ObservableOrganizationsClient(gitHubClient);
            Repository = new ObservableRepositoriesClient(gitHubClient);
            SshKey = new ObservableSshKeysClient(gitHubClient);
            User = new ObservableUsersClient(gitHubClient);
            Release = new ObservableReleasesClient(gitHubClient);
            GitDatabase = new ObservableGitDatabaseClient(gitHubClient);
            Gist = new ObservableGistsClient(gitHubClient);
            Search = new ObservableSearchClient(gitHubClient);
        }
        public ObservableGitHubClient(IGitHubClient gitHubClient)
        {
            Ensure.ArgumentNotNull(gitHubClient, "githubClient");

            _gitHubClient = gitHubClient;
            Authorization = new ObservableAuthorizationsClient(gitHubClient);
            Activity = new ObservableActivitiesClient(gitHubClient);
            Issue = new ObservableIssuesClient(gitHubClient);
            Miscellaneous = new ObservableMiscellaneousClient(gitHubClient);
            Oauth = new ObservableOauthClient(gitHubClient);
            Organization = new ObservableOrganizationsClient(gitHubClient);
            PullRequest = new ObservablePullRequestsClient(gitHubClient);
            Repository = new ObservableRepositoriesClient(gitHubClient);
            User = new ObservableUsersClient(gitHubClient);
            Git = new ObservableGitDatabaseClient(gitHubClient);
            Gist = new ObservableGistsClient(gitHubClient);
            Search = new ObservableSearchClient(gitHubClient);
            Enterprise = new ObservableEnterpriseClient(gitHubClient);
            Migration = new ObservableMigrationClient(gitHubClient);
            Reaction = new ObservableReactionsClient(gitHubClient);
        }
        public void UnlocksIssueWithRepositoryId()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Unlock(1, 42);

            gitHubClient.Issue.Received().Unlock(1, 42);
        }
        public void UnlocksIssue()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Unlock("fake", "repo", 42);

            gitHubClient.Issue.Received().Unlock("fake", "repo", 42);
        }
        public void UpdatesClientIssueIssueWithRepositoryId()
        {
            var issueUpdate = new IssueUpdate();
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Update(1, 42, issueUpdate);

            gitHubClient.Issue.Received().Update(1, 42, issueUpdate);
        }
        public void UpdatesClientIssueIssue()
        {
            var issueUpdate = new IssueUpdate();
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Update("fake", "repo", 42, issueUpdate);

            gitHubClient.Issue.Received().Update("fake", "repo", 42, issueUpdate);
        }
        public void CreatesFromClientIssueIssueWithRepositoryId()
        {
            var newIssue = new NewIssue("some title");
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.Create(1, newIssue);

            gitHubClient.Issue.Received().Create(1, newIssue);
        }
            public async Task EnsuresArgumentsNotNull()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableIssuesClient(gitHubClient);

                AssertEx.Throws<ArgumentNullException>(async () => await
                    client.Create(null, "name", new NewIssue("title")));
                AssertEx.Throws<ArgumentException>(async () => await
                    client.Create("", "name", new NewIssue("x")));
                AssertEx.Throws<ArgumentNullException>(async () => await
                    client.Create("owner", null, new NewIssue("x")));
                AssertEx.Throws<ArgumentException>(async () => await
                    client.Create("owner", "", new NewIssue("x")));
                AssertEx.Throws<ArgumentNullException>(async () => await
                    client.Create("owner", "name", null));
            }
        public async Task ReturnsEveryPageOfIssues()
        {
            var firstPageUrl = new Uri("issues", UriKind.Relative);
            var secondPageUrl = new Uri("https://example.com/page/2");
            var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } };
            var firstPageResponse = new ApiResponse<List<Issue>>
            (
                CreateResponseWithApiInfo(firstPageLinks),
                new List<Issue>
                {
                    CreateIssue(1),
                    CreateIssue(2),
                    CreateIssue(3)
                }
            );
            var thirdPageUrl = new Uri("https://example.com/page/3");
            var secondPageLinks = new Dictionary<string, Uri> { { "next", thirdPageUrl } };
            var secondPageResponse = new ApiResponse<List<Issue>>
            (
                CreateResponseWithApiInfo(secondPageLinks),
                new List<Issue>
                {
                    CreateIssue(4),
                    CreateIssue(5),
                    CreateIssue(6)
                }
            );
            var lastPageResponse = new ApiResponse<List<Issue>>
            (
                new Response(),
                new List<Issue>
                {
                    CreateIssue(7)
                }
            );
            var gitHubClient = Substitute.For<IGitHubClient>();
            gitHubClient.Connection.Get<List<Issue>>(Arg.Is(firstPageUrl),
                Arg.Is<Dictionary<string, string>>(d => d.Count == 4
                    && d["direction"] == "desc"
                    && d["state"] == "open"
                    && d["sort"] == "created"
                    && d["filter"] == "assigned"), "application/vnd.github.squirrel-girl-preview")
                .Returns(Task.Factory.StartNew<IApiResponse<List<Issue>>>(() => firstPageResponse));
            gitHubClient.Connection.Get<List<Issue>>(secondPageUrl, Arg.Any<Dictionary<string, string>>(), "application/vnd.github.squirrel-girl-preview")
                .Returns(Task.Factory.StartNew<IApiResponse<List<Issue>>>(() => secondPageResponse));
            gitHubClient.Connection.Get<List<Issue>>(thirdPageUrl, Arg.Any<Dictionary<string, string>>(), "application/vnd.github.squirrel-girl-preview")
                .Returns(Task.Factory.StartNew<IApiResponse<List<Issue>>>(() => lastPageResponse));
            var client = new ObservableIssuesClient(gitHubClient);

            var results = await client.GetAllForCurrent().ToArray();

            Assert.Equal(7, results.Length);
            Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number);
            Assert.Equal(secondPageResponse.Body[1].Number, results[4].Number);
            Assert.Equal(lastPageResponse.Body[0].Number, results[6].Number);
        }
        public void EnsuresNonNullArguments()
        {
            var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>());

            Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent((ApiOptions)null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent((IssueRequest)null));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(null, new ApiOptions()));
            Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(new IssueRequest(), null));
        }
            public void ReturnsEveryPageOfIssues()
            {
                var firstPageUrl = new Uri("repos/fake/repo/issues", UriKind.Relative);
                var secondPageUrl = new Uri("https://example.com/page/2");
                var firstPageLinks = new Dictionary<string, Uri> { { "next", secondPageUrl } };
                var firstPageResponse = new ApiResponse<List<Issue>>
                {
                    BodyAsObject = new List<Issue>
                    {
                        new Issue {Number = 1},
                        new Issue {Number = 2},
                        new Issue {Number = 3},
                    },
                    ApiInfo = CreateApiInfo(firstPageLinks)
                };
                var thirdPageUrl = new Uri("https://example.com/page/3");
                var secondPageLinks = new Dictionary<string, Uri> { { "next", thirdPageUrl } };
                var secondPageResponse = new ApiResponse<List<Issue>>
                {
                    BodyAsObject = new List<Issue>
                    {
                        new Issue {Number = 4},
                        new Issue {Number = 5},
                        new Issue {Number = 6},
                    },
                    ApiInfo = CreateApiInfo(secondPageLinks)
                };
                var lastPageResponse = new ApiResponse<List<Issue>>
                {
                    BodyAsObject = new List<Issue>
                    {
                        new Issue {Number = 7},
                    },
                    ApiInfo = CreateApiInfo(new Dictionary<string, Uri>())
                };
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.GetAsync<List<Issue>>(Arg.Is(firstPageUrl),
                    Arg.Is<Dictionary<string, string>>(d => d.Count == 4
                        && d["direction"] == "desc"
                        && d["state"] == "open"
                        && d["sort"] == "created"
                        && d["filter"] == "assigned"), Arg.Any<string>())
                    .Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => firstPageResponse));
                gitHubClient.Connection.GetAsync<List<Issue>>(secondPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => secondPageResponse));
                gitHubClient.Connection.GetAsync<List<Issue>>(thirdPageUrl, null, null)
                    .Returns(Task.Factory.StartNew<IResponse<List<Issue>>>(() => lastPageResponse));
                var client = new ObservableIssuesClient(gitHubClient);

                var results = client.GetForRepository("fake", "repo").ToArray().Wait();

                Assert.Equal(7, results.Length);
                Assert.Equal(firstPageResponse.BodyAsObject[0].Number, results[0].Number);
                Assert.Equal(secondPageResponse.BodyAsObject[1].Number, results[4].Number);
                Assert.Equal(lastPageResponse.BodyAsObject[0].Number, results[6].Number);
            }
        public async Task EnsuresNonNullArguments()
        {
            var client = new ObservableIssuesClient(Substitute.For<IGitHubClient>());

            await Assert.ThrowsAsync<ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories((ApiOptions)null).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories((IssueRequest)null).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories(null, new ApiOptions()).ToTask());
            await Assert.ThrowsAsync<ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories(new IssueRequest(), null).ToTask());
        }
        public void SendsAppropriateParametersWithRepositoryIdWithApiOptions()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            var options = new ApiOptions
            {
                PageCount = 1,
                StartPage = 1,
                PageSize = 1
            };

            client.GetAllForRepository(1, new RepositoryIssueRequest
            {
                SortDirection = SortDirection.Ascending
            }, options);

            gitHubClient.Connection.Received().Get<List<Issue>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues"),
                Arg.Is<IDictionary<string, string>>(d => d.Count == 6
                && d["filter"] == "assigned"
                && d["state"] == "open"
                && d["sort"] == "created"
                && d["direction"] == "asc"
                && d["page"] == "1"
                && d["per_page"] == "1"),
                null);
        }
        public void EnsuresArgumentsNotNull()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            Assert.Throws<ArgumentNullException>(() => client.Update(null, "name", 42, new IssueUpdate()));
            Assert.Throws<ArgumentException>(() => client.Update("", "name", 42, new IssueUpdate()));
            Assert.Throws<ArgumentNullException>(() => client.Update("owner", null, 42, new IssueUpdate()));
            Assert.Throws<ArgumentException>(() => client.Update("owner", "", 42, new IssueUpdate()));
            Assert.Throws<ArgumentNullException>(() => client.Update("owner", "name", 42, null));
        }
        public void EnsuresNonNullArguments()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            Assert.Throws<ArgumentNullException>(() => client.Unlock(null, "name", 42));
            Assert.Throws<ArgumentNullException>(() => client.Unlock("owner", null, 42));

            Assert.Throws<ArgumentException>(() => client.Unlock("", "name", 42));
            Assert.Throws<ArgumentException>(() => client.Unlock("owner", "", 42));
        }
        public void RequestsCorrectUrlWithApiOptions()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            var options = new ApiOptions
            {
                PageCount = 1,
                StartPage = 1,
                PageSize = 1
            };

            client.GetAllForRepository("fake", "repo", options);

            gitHubClient.Connection.Received().Get<List<Issue>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues"), 
                Arg.Is<IDictionary<string, string>>(d => d.Count == 6 
                && d["filter"] == "assigned" 
                && d["state"] == "open"
                && d["sort"] == "created"
                && d["direction"] == "desc"
                && d["page"] == "1"
                && d["per_page"] == "1"),
                "application/vnd.github.squirrel-girl-preview");
        }
        public void RequestsCorrectUrlWithRepositoryId()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.GetAllForRepository(1);

            gitHubClient.Connection.Received().Get<List<Issue>>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/issues"),
                Arg.Any<IDictionary<string, string>>(), null);
        }
        public void RequestsCorrectUrl()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.GetAllForRepository("fake", "repo");

            gitHubClient.Connection.Received().Get<List<Issue>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues"),
                Arg.Any<IDictionary<string, string>>(),
                "application/vnd.github.squirrel-girl-preview");
        }
        public void SendsAppropriateParameters()
        {
            var gitHubClient = Substitute.For<IGitHubClient>();
            var client = new ObservableIssuesClient(gitHubClient);

            client.GetAllForRepository("fake", "repo", new RepositoryIssueRequest
            {
                SortDirection = SortDirection.Ascending
            });

            gitHubClient.Connection.Received().Get<List<Issue>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues"),
                Arg.Is<IDictionary<string, string>>(d => d.Count == 4
                && d["filter"] == "assigned"
                && d["state"] == "open"
                && d["sort"] == "created"
                && d["direction"] == "asc"),
                "application/vnd.github.squirrel-girl-preview");
        }