public async Task EnsuresArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                await AssertEx.Throws<ArgumentException>(async () => await client.GetAllStargazers(null, "name"));
                await AssertEx.Throws<ArgumentException>(async () => await client.GetAllStargazers("owner", null));
            }
            public async Task EnsuresArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckStarred(null, "james").ToTask());
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckStarred("james", null).ToTask());
            }
            public async Task EnsuresArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers(null, "name").ToTask());
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllStargazers("owner", null).ToTask());
            }
            public async Task EnsuresArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                await AssertEx.Throws<ArgumentException>(async () => await client.CheckStarred(null, "james"));
                await AssertEx.Throws<ArgumentException>(async () => await client.CheckStarred("james", null));
            }
            public void GetsStargazersFromClient()
            {
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

                client.GetAllStargazers("jugglingnutcase", "katiejamie");
                connection.Received().Get<List<User>>(ApiUrls.Stargazers("jugglingnutcase", "katiejamie"), null, null);
            }
            public void GetsStarsForUser()
            {
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

                client.GetAllForUser("jugglingnutcase");
                connection.Received().Get<List<Repository>>(ApiUrls.StarredByUser("jugglingnutcase"), null, null);
            }
            public void RequestsCorrectUrlWithRepositoryId()
            {
                var endpoint = new Uri("repositories/1/stargazers", UriKind.Relative);
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

                client.GetAllStargazers(1);

                connection.Received().Get<List<User>>(endpoint, Args.EmptyDictionary, null);
            }
            public void RequestsCorrectUrlWithTimestamps()
            {
                var endpoint = new Uri("repos/fight/club/stargazers", UriKind.Relative);
                var connection = Substitute.For<IConnection>();
                var gitHubClient = Substitute.For<IGitHubClient>();
                gitHubClient.Connection.Returns(connection);
                var client = new ObservableStarredClient(gitHubClient);

                client.GetAllStargazersWithTimestamps("fight", "club");

                connection.Received().Get<List<UserStar>>(endpoint, Args.EmptyDictionary, "application/vnd.github.v3.star+json");
            }
            public void RequestsCorrectUrlWithTimestampsWithApiOptions()
            {
                var endpoint = new Uri("repos/fight/club/stargazers", 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
                };

                client.GetAllStargazersWithTimestamps("fight", "club", options);

                connection.Received().Get<List<UserStar>>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2), "application/vnd.github.v3.star+json");
            }
            public void RequestsCorrectUrlWithApiOptionsWithRepositoryId()
            {
                var endpoint = new Uri("repositories/1/stargazers", 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
                };

                client.GetAllStargazers(1, options);

                connection.Received().Get<List<User>>(endpoint, Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
            }
            public void RequestsCorrectUrlWithTimestamps()
            {
                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);

                client.GetAllForUserWithTimestamps("banana");

                connection.Received().Get<List<RepositoryStar>>(endpoint, Args.EmptyDictionary,
                    "application/vnd.github.v3.star+json");
            }
            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 void EnsuresNonNullArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent((ApiOptions)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent((StarredRequest)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps((ApiOptions)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps((StarredRequest)null));

                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(null, new ApiOptions()));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(new StarredRequest(), null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps(null, new ApiOptions()));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrentWithTimestamps(new StarredRequest(), null));
            }
            public void EnsuresNonNullArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazers(null, "club"));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazers("fight", null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazers(null, "club", ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazers("fight", null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazers("fight", "club", null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(null, "club"));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps(null, "club", ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllStargazersWithTimestamps("fight", "club", null));

                Assert.Throws<ArgumentException>(() => client.GetAllStargazers("", "club"));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazers("fight", ""));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazers("", "club", ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazers("fight", "", ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazersWithTimestamps("", "club"));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazersWithTimestamps("fight", ""));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazersWithTimestamps("", "club", ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAllStargazersWithTimestamps("fight", "", ApiOptions.None));
            }
            public void ChecksStarredForUser()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableStarredClient(gitHubClient);

                client.RemoveStarFromRepo("jugglingnutcase", "katiejamie");
                gitHubClient.Activity.Starring.Received().RemoveStarFromRepo("jugglingnutcase", "katiejamie");
            }
            public void EnsuresNonNullArguments()
            {
                var client = new ObservableStarredClient(Substitute.For<IGitHubClient>());

                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser("banana", (ApiOptions)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null, new StarredRequest()));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser("banana", (StarredRequest)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null, new StarredRequest(), ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser("banana", null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUser("banana", new StarredRequest(), null));

                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", (ApiOptions)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, new StarredRequest()));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", (StarredRequest)null));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps(null, new StarredRequest(), ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", null, ApiOptions.None));
                Assert.Throws<ArgumentNullException>(() => client.GetAllForUserWithTimestamps("banana", new StarredRequest(), null));

                Assert.Throws<ArgumentException>(() => client.GetAllForUser(""));
                Assert.Throws<ArgumentException>(() => client.GetAllForUser("", ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAllForUser("", new StarredRequest(), ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAllForUserWithTimestamps(""));
                Assert.Throws<ArgumentException>(() => client.GetAllForUserWithTimestamps("", ApiOptions.None));
                Assert.Throws<ArgumentException>(() => client.GetAllForUserWithTimestamps("", new StarredRequest(), ApiOptions.None));
            }
            public void RequestsCorrectUrl()
            {
                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);

                client.GetAllForUser("banana");

                connection.Received().Get<List<Repository>>(endpoint, Args.EmptyDictionary, null);
            }
            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 void RequestsCorrectUrlWithApiOptions()
            {
                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
                };

                client.GetAllForUser("banana", options);

                connection.Received().Get<List<Repository>>(endpoint, 
                    Arg.Is<IDictionary<string, string>>(d => d.Count == 2 && d["per_page"] == "1" && d["page"] == "1"), null);
            }
            public async Task ChecksStarredForUser()
            {
                var gitHubClient = Substitute.For<IGitHubClient>();
                var client = new ObservableStarredClient(gitHubClient);

                client.CheckStarred("jugglingnutcase", "katiejamie");
                gitHubClient.Activity.Starring.Received().CheckStarred("jugglingnutcase", "katiejamie");
            }
            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");
            }