public void RequestsTheCorrectUrlWithRepositoryIdWithApiOptions() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservableRepositoriesClient(gitHubClient); var expected = new Uri("repositories/1/teams", UriKind.Relative); var options = new ApiOptions { PageCount = 1, StartPage = 1, PageSize = 1 }; client.GetAllTeams(1, options); gitHubClient.Connection.Received(1).Get <List <Team> >(expected, Arg.Is <IDictionary <string, string> >(d => d.Count == 2 && d["page"] == "1" && d["per_page"] == "1"), Arg.Any <string>()); }
public async Task EnsuresNonNullArguments() { var client = new ObservableRepositoriesClient(Substitute.For <IGitHubClient>()); var update = new BranchUpdate(); Assert.Throws <ArgumentNullException>(() => client.EditBranch(null, "repo", "branch", update)); Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", null, "branch", update)); Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", "repo", null, update)); Assert.Throws <ArgumentNullException>(() => client.EditBranch("owner", "repo", "branch", null)); Assert.Throws <ArgumentNullException>(() => client.EditBranch(1, null, update)); Assert.Throws <ArgumentNullException>(() => client.EditBranch(1, "branch", null)); Assert.Throws <ArgumentException>(() => client.EditBranch("", "repo", "branch", update)); Assert.Throws <ArgumentException>(() => client.EditBranch("owner", "", "branch", update)); Assert.Throws <ArgumentException>(() => client.EditBranch("owner", "repo", "", update)); Assert.Throws <ArgumentException>(() => client.EditBranch(1, "", update)); }
public void RequestsTheCorrectUrlWithApiOptionsWithRepositoryId() { var gitHubClient = Substitute.For <IGitHubClient>(); var client = new ObservableRepositoriesClient(gitHubClient); var expected = new Uri("repositories/1/contributors", UriKind.Relative); var options = new ApiOptions { PageCount = 1, StartPage = 1, PageSize = 1 }; client.GetAllContributors(1, options); gitHubClient.Connection.Received(1) .Get <List <RepositoryContributor> >(expected, Arg.Is <IDictionary <string, string> >(d => d.Count == 2), null); }
public void EnsuresNonNullArguments() { var client = new ObservableRepositoriesClient(Substitute.For <IGitHubClient>()); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors(null, "repo")); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors("owner", null)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors(null, "repo", ApiOptions.None)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors("owner", null, ApiOptions.None)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors("owner", "repo", null)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors(null, "repo", false, ApiOptions.None)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors("owner", null, false, ApiOptions.None)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors("owner", "repo", false, null)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors(1, null)); Assert.Throws <ArgumentNullException>(() => client.GetAllContributors(1, false, null)); Assert.Throws <ArgumentException>(() => client.GetAllContributors("", "repo")); Assert.Throws <ArgumentException>(() => client.GetAllContributors("owner", "")); Assert.Throws <ArgumentException>(() => client.GetAllContributors("", "repo", ApiOptions.None)); Assert.Throws <ArgumentException>(() => client.GetAllContributors("owner", "", ApiOptions.None)); Assert.Throws <ArgumentException>(() => client.GetAllContributors("", "repo", false, ApiOptions.None)); Assert.Throws <ArgumentException>(() => client.GetAllContributors("owner", "", false, ApiOptions.None)); }
public void GetRepos() { //var github = new GitHubClient(new ProductHeaderValue("GitHubClient")); var credential = new Credentials("username", "password"); // GitHubユーザ名とパスワード var github = new GitHubClient( new ProductHeaderValue("GitHubClient_ytyaru"), new InMemoryCredentialStore(credential)); var reposObserver = new ObservableRepositoriesClient(github); using (FileStream fs = new FileStream("/tmp/work/repos.tsv", System.IO.FileMode.OpenOrCreate)) { using (StreamWriter writer = new StreamWriter(fs)) { writer.WriteLine(String.Join("\t", new string[] { "Id", "Name", "Size", "Description", "Homepage", "CreatedAt", "UpdatedAt" })); reposObserver.GetAllForUser("ytyaru").Subscribe( i => { writer.WriteLine(String.Join("\t", new string[] { i.Id.ToString(), i.Name.ToString(), i.Size.ToString(), i.Description, i.Homepage, i.CreatedAt.ToString("yyyy-MM-dd HH:mm:ss"), i.UpdatedAt.ToString("yyyy-MM-dd HH:mm:ss") })); //writer.WriteLine(i.Id + "\t" + i.Name + "\t" + i.Size + "\t" + i.Description + "\t" + i.Homepage + "\t" + i.CreatedAt + "\t" + i.PushedAt + "\t" + i.UpdatedAt); } ); writer.Flush(); } } ; }
public async Task IsALukeWarmObservableWithRepositoryId() { var repository = new Repository(); var response = Task.FromResult <IApiResponse <Repository> >(new ApiResponse <Repository>(new Response(), repository)); var connection = Substitute.For <IConnection>(); connection.Get <Repository>(Args.Uri, null, Args.AnyAcceptHeaders).Returns(response); var gitHubClient = new GitHubClient(connection); var client = new ObservableRepositoriesClient(gitHubClient); var observable = client.Get(1); connection.Received(1).Get <Repository>(Args.Uri, null, Args.AnyAcceptHeaders); var result = await observable; connection.Received(1).Get <Repository>(Args.Uri, null, Args.AnyAcceptHeaders); var result2 = await observable; // TODO: If we change this to a warm observable, we'll need to change this to Received(2) connection.Received(1).Get <Repository>(Args.Uri, null, Args.AnyAcceptHeaders); Assert.Same(repository, result); Assert.Same(repository, result2); }
public async Task StopsMakingNewRequestsWhenTakeIsFulfilled() { var firstPageUrl = new Uri("user/repos", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary <string, Uri> { { "next", secondPageUrl } }; var firstPageResponse = new ApiResponse <List <Repository> > ( CreateResponseWithApiInfo(firstPageLinks), new List <Repository> { new Repository(1), new Repository(2), new Repository(3) } ); var thirdPageUrl = new Uri("https://example.com/page/3"); var secondPageLinks = new Dictionary <string, Uri> { { "next", thirdPageUrl } }; var secondPageResponse = new ApiResponse <List <Repository> > ( CreateResponseWithApiInfo(secondPageLinks), new List <Repository> { new Repository(4), new Repository(5), new Repository(6) } ); var fourthPageUrl = new Uri("https://example.com/page/4"); var thirdPageLinks = new Dictionary <string, Uri> { { "next", fourthPageUrl } }; var thirdPageResponse = new ApiResponse <List <Repository> > ( CreateResponseWithApiInfo(thirdPageLinks), new List <Repository> { new Repository(7) } ); var lastPageResponse = new ApiResponse <List <Repository> > ( new Response(), new List <Repository> { new Repository(8) } ); var gitHubClient = Substitute.For <IGitHubClient>(); gitHubClient.Connection.GetResponse <List <Repository> >(firstPageUrl) .Returns(Task.Factory.StartNew <IApiResponse <List <Repository> > >(() => firstPageResponse)); gitHubClient.Connection.GetResponse <List <Repository> >(secondPageUrl) .Returns(Task.Factory.StartNew <IApiResponse <List <Repository> > >(() => secondPageResponse)); gitHubClient.Connection.GetResponse <List <Repository> >(thirdPageUrl) .Returns(Task.Factory.StartNew <IApiResponse <List <Repository> > >(() => thirdPageResponse)); gitHubClient.Connection.GetResponse <List <Repository> >(fourthPageUrl) .Returns(Task.Factory.StartNew <IApiResponse <List <Repository> > >(() => lastPageResponse)); var repositoriesClient = new ObservableRepositoriesClient(gitHubClient); var results = await repositoriesClient.GetAllForCurrent().Take(4).ToArray(); Assert.Equal(4, results.Length); gitHubClient.Connection.Received(1).Get <List <Repository> >(firstPageUrl, null, null); gitHubClient.Connection.Received(1).Get <List <Repository> >(secondPageUrl, null, null); gitHubClient.Connection.Received(0).Get <List <Repository> >(thirdPageUrl, null, null); gitHubClient.Connection.Received(0).Get <List <Repository> >(fourthPageUrl, null, null); }
public async Task ReturnsEveryPageOfRepositories() { var firstPageUrl = new Uri("user/repos", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); var firstPageLinks = new Dictionary <string, Uri> { { "next", secondPageUrl } }; var firstPageResponse = new ApiResponse <List <Repository> > { BodyAsObject = new List <Repository> { new Repository { Id = 1 }, new Repository { Id = 2 }, new Repository { Id = 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 <Repository> > { BodyAsObject = new List <Repository> { new Repository { Id = 4 }, new Repository { Id = 5 }, new Repository { Id = 6 } }, ApiInfo = CreateApiInfo(secondPageLinks) }; var lastPageResponse = new ApiResponse <List <Repository> > { BodyAsObject = new List <Repository> { new Repository { Id = 7 } }, ApiInfo = CreateApiInfo(new Dictionary <string, Uri>()) }; var gitHubClient = Substitute.For <IGitHubClient>(); gitHubClient.Connection.GetResponse <List <Repository> >(firstPageUrl) .Returns(Task.Factory.StartNew <IResponse <List <Repository> > >(() => firstPageResponse)); gitHubClient.Connection.GetResponse <List <Repository> >(secondPageUrl) .Returns(Task.Factory.StartNew <IResponse <List <Repository> > >(() => secondPageResponse)); gitHubClient.Connection.GetResponse <List <Repository> >(thirdPageUrl) .Returns(Task.Factory.StartNew <IResponse <List <Repository> > >(() => lastPageResponse)); var repositoriesClient = new ObservableRepositoriesClient(gitHubClient); var results = await repositoriesClient.GetAllForCurrent().ToArray(); Assert.Equal(7, results.Length); gitHubClient.Connection.Received(1).Get <List <Repository> >(firstPageUrl, null, null); gitHubClient.Connection.Received(1).Get <List <Repository> >(secondPageUrl, null, null); gitHubClient.Connection.Received(1).Get <List <Repository> >(thirdPageUrl, null, null); }