From 8eba9a6a9cf044d0d3e590f436ab17f976a4c1b0 Mon Sep 17 00:00:00 2001 From: William Barbosa Date: Tue, 22 Sep 2015 23:02:17 -0300 Subject: [PATCH] RepositoryContext class and Extension methods --- .../Helpers/GithubClientExtensions.cs | 33 +++++++++++++++++++ .../Helpers/RepositoryContext.cs | 23 +++++++++++++ .../Octokit.Tests.Integration.csproj | 2 ++ 3 files changed, 58 insertions(+) create mode 100644 Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs create mode 100644 Octokit.Tests.Integration/Helpers/RepositoryContext.cs diff --git a/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs new file mode 100644 index 00000000..58c53d05 --- /dev/null +++ b/Octokit.Tests.Integration/Helpers/GithubClientExtensions.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit.Tests.Integration.Helpers +{ + internal static class GithubClientExtensions + { + internal async static Task CreateRepositoryContext(this IGitHubClient client, string repositoryName) + { + var repoName = Helper.MakeNameWithTimestamp(repositoryName); + var repo = await client.Repository.Create(new NewRepository(repoName) { AutoInit = true }); + + return new RepositoryContext(repo); + } + + internal async static Task CreateRepositoryContext(this IGitHubClient client, string organizationLogin, NewRepository newRepository) + { + var repo = await client.Repository.Create(organizationLogin, newRepository); + + return new RepositoryContext(repo); + } + + internal async static Task CreateRepositoryContext(this IGitHubClient client, NewRepository newRepository) + { + var repo = await client.Repository.Create(newRepository); + + return new RepositoryContext(repo); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs new file mode 100644 index 00000000..71cdf86f --- /dev/null +++ b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit.Tests.Integration.Helpers +{ + internal sealed class RepositoryContext : IDisposable + { + internal RepositoryContext(Repository repo) + { + Repository = repo; + } + + internal Repository Repository { get; private set; } + + public void Dispose() + { + Helper.DeleteRepo(Repository); + } + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index f6154d28..7398edbe 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -102,8 +102,10 @@ + +