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

            Assert.Throws <ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories((ApiOptions)null));
            Assert.Throws <ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories((IssueRequest)null));
            Assert.Throws <ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories(null, new ApiOptions()));
            Assert.Throws <ArgumentNullException>(
                () => client.GetAllForOwnedAndMemberRepositories(new IssueRequest(), null));
        }
Exemple #2
0
    public async Task ReturnsAllIssuesForOwnedAndMemberRepositories()
    {
        var newIssue = new NewIssue("Integration test issue");
        await _client.Create(_createdRepository.Owner.Login, _repoName, newIssue);

        var result = await _client.GetAllForOwnedAndMemberRepositories().ToList();

        Assert.NotEmpty(result);
    }
Exemple #3
0
        public async void ReturnsAllIssuesForOwnedAndMemberRepositories()
        {
            var newIssue     = new NewIssue("Integration test issue");
            var createResult = await client.Create(createdRepository.Owner.Name, repoName, newIssue);

            var result = client.GetAllForOwnedAndMemberRepositories().ToList().Wait();

            Assert.NotEmpty(result);
        }
Exemple #4
0
    public async Task ReturnsAllIssuesForOwnedAndMemberRepositories()
    {
        var newIssue = new NewIssue("Integration test issue");

        newIssue.Assignees.Add(_context.RepositoryOwner);
        await _client.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue);

        var result = await _client.GetAllForOwnedAndMemberRepositories().ToList();

        Assert.NotEmpty(result);
    }
        public async Task ReturnsEveryPageOfIssues()
        {
            var firstPageUrl   = new Uri("user/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"), Arg.Any <string>())
            .Returns(Task.Factory.StartNew <IApiResponse <List <Issue> > >(() => firstPageResponse));
            gitHubClient.Connection.Get <List <Issue> >(secondPageUrl, null, null)
            .Returns(Task.Factory.StartNew <IApiResponse <List <Issue> > >(() => secondPageResponse));
            gitHubClient.Connection.Get <List <Issue> >(thirdPageUrl, null, null)
            .Returns(Task.Factory.StartNew <IApiResponse <List <Issue> > >(() => lastPageResponse));
            var client = new ObservableIssuesClient(gitHubClient);

            var results = await client.GetAllForOwnedAndMemberRepositories().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);
        }
Exemple #6
0
            public void ReturnsEveryPageOfIssues()
            {
                var firstPageUrl   = new Uri("user/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.GetAllForOwnedAndMemberRepositories().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);
            }