public async Task ReturnsDistinctResultsBasedOnStartPage()
            {
                var github = Helper.GetAuthenticatedClient();

                var client = new ObservableRepositoryHooksClient(github);

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

                var firstPage = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, startOptions).ToList();

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

                var secondPage = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, skipStartOptions).ToList();

                Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
                Assert.NotEqual(firstPage[1].Id, secondPage[1].Id);
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableRepositoryHooksClient(gitHubClient);

                client.GetAll(1);

                gitHubClient.Received().Repository.Hooks.GetAll(1);
            }
                public void GetsCorrectUrlWithApiOption()
                {
                    var gitHubClient = Substitute.For<IGitHubClient>();
                    var hooksClient = new ObservableRepositoryHooksClient(gitHubClient);
                    var expectedUrl = string.Format("repos/{0}/{1}/hooks", owner, repositoryName);

                    // all properties are setted => only 2 options (StartPage, PageSize) in dictionary
                    var options = new ApiOptions
                    {
                        StartPage = 1,
                        PageCount = 1,
                        PageSize = 1
                    };

                    hooksClient.GetAll(owner, repositoryName, options);
                    gitHubClient.Connection.Received(1)
                        .Get<List<RepositoryHook>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
                            Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
                            null);

                    // StartPage is setted => only 1 option (StartPage) in dictionary
                    options = new ApiOptions
                    {
                        StartPage = 1
                    };

                    hooksClient.GetAll(owner, repositoryName, options);
                    gitHubClient.Connection.Received(1)
                        .Get<List<RepositoryHook>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
                            Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
                            null);

                    // PageCount is setted => none of options in dictionary
                    options = new ApiOptions
                    {
                        PageCount = 1
                    };

                    hooksClient.GetAll(owner, repositoryName, options);
                    gitHubClient.Connection.Received(1)
                        .Get<List<RepositoryHook>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
                            Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
                            null);
                }
                public void GetsCorrectUrl()
                {
                    var client = Substitute.For<IGitHubClient>();
                    var authEndpoint = new ObservableRepositoryHooksClient(client);
                    var expectedUrl = string.Format("repos/{0}/{1}/hooks", owner, repositoryName);

                    authEndpoint.GetAll(owner, repositoryName);

                    client.Connection.Received(1).Get<List<RepositoryHook>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
                        Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
                }
            public async Task ReturnsAllHooksFromRepository()
            {
                var github = Helper.GetAuthenticatedClient();

                var client = new ObservableRepositoryHooksClient(github);

                var hooks = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName).ToList();

                Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count);

                var actualHook = hooks[0];
                AssertHook(_fixture.ExpectedHook, actualHook);
            }
            public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableRepositoryHooksClient(gitHubClient);

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

                client.GetAll(1, options);

                gitHubClient.Received(1).Repository.Hooks.GetAll(1, options);
            }
            public async Task ReturnsCorrectCountOfHooksWithoutStart()
            {
                var github = Helper.GetAuthenticatedClient();

                var client = new ObservableRepositoryHooksClient(github);

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

                var hooks = await client.GetAll(_fixture.RepositoryOwner, _fixture.RepositoryName, options).ToList();

                Assert.Equal(_fixture.ExpectedHooks.Count, hooks.Count);
            }
            public void EnsuresNonNullArguments()
            {
                var client = new ObservableRepositoryHooksClient(Substitute.For<IGitHubClient>());

                Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name"));
                Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null));
                Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "name", null));

                Assert.Throws<ArgumentNullException>(() => client.GetAll(1, null));

                Assert.Throws<ArgumentException>(() => client.GetAll("", "name"));
                Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
                Assert.Throws<ArgumentException>(() => client.GetAll("", "name", ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", ApiOptions.None));
            }