public IObservable<Repository> GetAllForUser(string user, StarredRequest request)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(request, "request");

            return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.StarredByUser(user), request.ToParametersDictionary());
        }
            public async Task RequestsCorrectUrlParametrized()
            {
                var endpoint = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

                var request = new StarredRequest { SortDirection = SortDirection.Ascending };

                await client.GetAllForCurrent(request);

                connection.Received().GetAll<Repository>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["direction"] == "asc"),
                    Args.ApiOptions);
            }
        public async Task CanGetAllForUserWithTimestampsParameterized()
        {
            var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending };

            var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest);
            Assert.NotEmpty(stars);

            var repo = stars.FirstOrDefault(repository => repository.Repo.Owner.Login == _repositoryContext.RepositoryOwner && repository.Repo.Name == _repositoryContext.RepositoryName);
            Assert.NotNull(repo);

            for (int i = 1; i < stars.Count; i++)
            {
                Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt);
            }
        }
        /// <summary>
        /// Retrieves all of the <see cref="Repository"/>(ies) starred by the specified user with star creation timestamps.
        /// </summary>
        /// <param name="user">The login of the user</param>
        /// <param name="request">Star-specific request parameters that sort the results</param>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
        public IObservable<RepositoryStar> GetAllForUserWithTimestamps(string user, StarredRequest request, ApiOptions options)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(request, "request");
            Ensure.ArgumentNotNull(options, "options");

            return _connection.GetAndFlattenAllPages<RepositoryStar>(ApiUrls.StarredByUser(user), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps, options);
        }
            public async Task RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions()
            {
                var endpoint = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For<IApiConnection>();
                var client = new StarredClient(connection);

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

                var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending };

                await client.GetAllForUserWithTimestamps("banana", starredRequest, options);

                connection.Received().GetAll<RepositoryStar>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["direction"] == "asc"),
                    "application/vnd.github.v3.star+json", options);
            }
        public IObservable<RepositoryStar> GetAllForCurrentWithTimestamps(StarredRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return GetAllForCurrentWithTimestamps(request, ApiOptions.None);
        }
        public IObservable<RepositoryStar> GetAllForUserWithTimestamps(string user, StarredRequest request)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(request, "request");

            return GetAllForUserWithTimestamps(user, request, ApiOptions.None);
        }
        public async Task ReturnsDistinctRepositoriesBasedOnStartPageForUserWithTimestampsParameterized()
        {
            var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Descending };

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

            var firstPage = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, startOptions);

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

            var secondPage = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, skipStartOptions);

            Assert.Equal(1, firstPage.Count);
            Assert.Equal(1, secondPage.Count);
            Assert.NotEqual(firstPage.First().Repo.Id, secondPage.First().Repo.Id);

            for (int i = 0; i < firstPage.Count; i++)
            {
                Assert.True(firstPage[i].StarredAt >= secondPage[i].StarredAt);
            }
        }
        public async Task CanGetAllForCurrentParameterized()
        {
            var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created };

            var repositories = await _fixture.GetAllForCurrent(starredRequest);
            Assert.NotEmpty(repositories);
        }
        public IObservable<Repository> GetAllForCurrent(StarredRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Starred(), request.ToParametersDictionary());
        }
            public void RequestsCorrectUrlWithTimestampsParametrized()
            {
                var endpoint = new Uri("user/starred", UriKind.Relative);
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

                var request = new StarredRequest { SortDirection = SortDirection.Ascending };

                client.GetAllForCurrentWithTimestamps(request);

                connection.Received().Get<List<RepositoryStar>>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["direction"] == "asc"),
                    "application/vnd.github.v3.star+json");
            }
        public async Task ReturnsCorrectCountOfRepositoriesWithStartForUserParameterized()
        {
            var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created };

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

            var repositories = await _fixture.GetAllForUser(Helper.UserName, starredRequest, options);
            Assert.Equal(1, repositories.Count);
        }
        public async Task ReturnsDistinctRepositoriesBasedOnStartPageForUserParameterized()
        {
            var starredRequestFirstPage = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created };
            var starredRequestSecondPage = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created };

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

            var firstPage = await _fixture.GetAllForUser(Helper.UserName, starredRequestFirstPage, startOptions);

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

            var secondPage = await _fixture.GetAllForUser(Helper.UserName, starredRequestSecondPage, skipStartOptions);

            Assert.Equal(1, firstPage.Count);
            Assert.Equal(1, secondPage.Count);
            Assert.NotEqual(firstPage.First().Id, secondPage.First().Id);
        }
        public async Task CanGetAllForUserParameterized()
        {
            var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending, SortProperty = StarredSort.Created };

            var repositories = await _fixture.GetAllForUser(Helper.UserName, starredRequest);
            Assert.NotEmpty(repositories);

            var repo = repositories.FirstOrDefault(repository => repository.Owner.Login == _repositoryContext.RepositoryOwner && repository.Name == _repositoryContext.RepositoryName);
            Assert.NotNull(repo);
        }
        public IObservable<RepositoryStar> GetAllForCurrentWithTimestamps(StarredRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return _connection.GetAndFlattenAllPages<RepositoryStar>(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps);
        }
        public IObservable <Repository> GetAllForCurrent(StarredRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return(_connection.GetAndFlattenAllPages <Repository>(ApiUrls.Starred(), request.ToParametersDictionary()));
        }
            public void RequestsCorrectUrlWithTimestampsParametrizedWithApiOptions()
            {
                var endpoint = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

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

                var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending };

                client.GetAllForUserWithTimestamps("banana", starredRequest, options);

                connection.Received().Get<List<RepositoryStar>>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 4 && d["direction"] == "asc" && d["direction"] == "asc" && d["per_page"] == "1" && d["page"] == "1"),
                    "application/vnd.github.v3.star+json");
            }
            public void RequestsCorrectUrlParametrized()
            {
                var endpoint = new Uri("users/banana/starred", UriKind.Relative);
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

                var starredRequest = new StarredRequest { SortDirection = SortDirection.Ascending };

                client.GetAllForUser("banana", starredRequest);

                connection.Received().Get<List<Repository>>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["direction"] == "asc"), null);
            }
        public async Task ReturnsCorrectCountOfRepositoriesWithStartForUserWithTimestampsParameterized()
        {
            var starredRequest = new StarredRequest { SortProperty = StarredSort.Created, SortDirection = SortDirection.Ascending };

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

            var stars = await _fixture.GetAllForUserWithTimestamps(Helper.UserName, starredRequest, options);
            Assert.Equal(1, stars.Count);

            for (int i = 1; i < stars.Count; i++)
            {
                Assert.True(stars[i - 1].StarredAt >= stars[i].StarredAt);
            }
        }
        public IObservable <RepositoryStar> GetAllForCurrentWithTimestamps(StarredRequest request)
        {
            Ensure.ArgumentNotNull(request, "request");

            return(_connection.GetAndFlattenAllPages <RepositoryStar>(ApiUrls.Starred(), request.ToParametersDictionary(), AcceptHeaders.StarCreationTimestamps));
        }