Skip to content

Commit

Permalink
Merge pull request #909 from willsb/disposable-repositories
Browse files Browse the repository at this point in the history
Disposable repositories
  • Loading branch information
haacked committed Sep 29, 2015
2 parents 5811d9d + 6573c20 commit 1266ac0
Show file tree
Hide file tree
Showing 29 changed files with 720 additions and 821 deletions.
26 changes: 10 additions & 16 deletions Octokit.Tests.Integration/Clients/AssigneesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,40 @@
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using Xunit;

public class AssigneesClientTests
{
readonly IGitHubClient _gitHubClient;
readonly Repository _repository;
readonly string _owner;
readonly IGitHubClient _github;
readonly RepositoryContext _context;

public AssigneesClientTests()
{
_gitHubClient = Helper.GetAuthenticatedClient();
_github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");

_repository = _gitHubClient.Repository.Create(new NewRepository(repoName)).Result;
_owner = _repository.Owner.Login;
_context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result;
}

[IntegrationTest]
public async Task CanCheckAssignees()
{
var isAssigned = await
_gitHubClient.Issue.Assignee.CheckAssignee(_owner, _repository.Name, "FakeHaacked");
_github.Issue.Assignee.CheckAssignee(_context.RepositoryOwner, _context.RepositoryName, "FakeHaacked");
Assert.False(isAssigned);

// Repository owner is always an assignee
isAssigned = await
_gitHubClient.Issue.Assignee.CheckAssignee(_owner, _repository.Name, _owner);
_github.Issue.Assignee.CheckAssignee(_context.RepositoryOwner, _context.RepositoryName, _context.RepositoryOwner);
Assert.True(isAssigned);
}

[IntegrationTest]
public async Task CanListAssignees()
{
// Repository owner is always an assignee
var assignees = await _gitHubClient.Issue.Assignee.GetAllForRepository(_owner, _repository.Name);
var assignees = await _github.Issue.Assignee.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName);
Assert.True(assignees.Any(u => u.Login == Helper.UserName));
}

public void Dispose()
{
Helper.DeleteRepo(_repository);
}
}
}
52 changes: 26 additions & 26 deletions Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public class AuthorizationClientTests
[ApplicationTest]
public async Task CanCreateAndGetAuthorizationWithoutFingerPrint()
{
var client = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new[] { "user" });

// the first call will create the authorization
var created = await client.Authorization.GetOrCreateApplicationAuthentication(
var created = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -27,14 +27,14 @@ public async Task CanCreateAndGetAuthorizationWithoutFingerPrint()
Assert.False(String.IsNullOrWhiteSpace(created.HashedToken));

// we can then query it through the regular API
var get = await client.Authorization.Get(created.Id);
var get = await github.Authorization.Get(created.Id);

Assert.Equal(created.Id, get.Id);
Assert.Equal(created.Note, get.Note);

// but the second time we call this API we get
// a different set of data
var getExisting = await client.Authorization.GetOrCreateApplicationAuthentication(
var getExisting = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -47,21 +47,21 @@ public async Task CanCreateAndGetAuthorizationWithoutFingerPrint()
Assert.False(String.IsNullOrWhiteSpace(getExisting.TokenLastEight));
Assert.False(String.IsNullOrWhiteSpace(getExisting.HashedToken));

await client.Authorization.Delete(created.Id);
await github.Authorization.Delete(created.Id);
}

[ApplicationTest]
public async Task CanCreateAndGetAuthorizationByFingerprint()
{
var client = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new[] { "user" },
fingerprint);

var created = await client.Authorization.GetOrCreateApplicationAuthentication(
var created = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -70,14 +70,14 @@ public async Task CanCreateAndGetAuthorizationByFingerprint()
Assert.False(String.IsNullOrWhiteSpace(created.Token));

// we can then query it through the regular API
var get = await client.Authorization.Get(created.Id);
var get = await github.Authorization.Get(created.Id);

Assert.Equal(created.Id, get.Id);
Assert.Equal(created.Note, get.Note);

// but the second time we call this API we get
// a different set of data
var getExisting = await client.Authorization.GetOrCreateApplicationAuthentication(
var getExisting = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -93,21 +93,21 @@ public async Task CanCreateAndGetAuthorizationByFingerprint()
Assert.False(String.IsNullOrWhiteSpace(getExisting.TokenLastEight));
Assert.False(String.IsNullOrWhiteSpace(getExisting.HashedToken));

await client.Authorization.Delete(created.Id);
await github.Authorization.Delete(created.Id);
}

[ApplicationTest]
public async Task CanCheckApplicationAuthentication()
{
var client = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new[] { "user" },
fingerprint);

var created = await client.Authorization.GetOrCreateApplicationAuthentication(
var created = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -118,22 +118,22 @@ public async Task CanCheckApplicationAuthentication()
Assert.NotNull(applicationAuthorization);
Assert.Equal(created.Token, applicationAuthorization.Token);

await client.Authorization.Delete(created.Id);
Assert.ThrowsAsync<NotFoundException>(() => client.Authorization.Get(created.Id));
await github.Authorization.Delete(created.Id);
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(created.Id));
}

[ApplicationTest]
public async Task CanResetApplicationAuthentication()
{
var client = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new[] { "user" },
fingerprint);

var created = await client.Authorization.GetOrCreateApplicationAuthentication(
var created = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -144,22 +144,22 @@ public async Task CanResetApplicationAuthentication()
Assert.NotNull(applicationAuthorization);
Assert.NotEqual(created.Token, applicationAuthorization.Token);

await client.Authorization.Delete(created.Id);
Assert.ThrowsAsync<NotFoundException>(() => client.Authorization.Get(created.Id));
await github.Authorization.Delete(created.Id);
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(created.Id));
}

[ApplicationTest]
public async Task CanRevokeApplicationAuthentication()
{
var client = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var newAuthorization = new NewAuthorization(
note,
new[] { "user" },
fingerprint);

var created = await client.Authorization.GetOrCreateApplicationAuthentication(
var created = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
newAuthorization);
Expand All @@ -168,17 +168,17 @@ public async Task CanRevokeApplicationAuthentication()
await applicationClient.Authorization.RevokeApplicationAuthentication(Helper.ClientId, created.Token);

Assert.ThrowsAsync<NotFoundException>(() => applicationClient.Authorization.CheckApplicationAuthentication(Helper.ClientId, created.Token));
Assert.ThrowsAsync<NotFoundException>(() => client.Authorization.Get(created.Id));
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(created.Id));
}

[ApplicationTest]
public async Task CanRevokeAllApplicationAuthentications()
{
var client = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();

var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing");
var note = Helper.MakeNameWithTimestamp("Testing authentication");
var token1 = await client.Authorization.GetOrCreateApplicationAuthentication(
var token1 = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
new NewAuthorization(
Expand All @@ -188,7 +188,7 @@ public async Task CanRevokeAllApplicationAuthentications()

fingerprint = Helper.MakeNameWithTimestamp("authorization-testing-2");
note = Helper.MakeNameWithTimestamp("Testing authentication 2");
var token2 = await client.Authorization.GetOrCreateApplicationAuthentication(
var token2 = await github.Authorization.GetOrCreateApplicationAuthentication(
Helper.ClientId,
Helper.ClientSecret,
new NewAuthorization(
Expand All @@ -204,8 +204,8 @@ public async Task CanRevokeAllApplicationAuthentications()
Assert.ThrowsAsync<NotFoundException>(async () =>
await applicationClient.Authorization.CheckApplicationAuthentication(Helper.ClientId, token2.Token));

Assert.ThrowsAsync<NotFoundException>(() => client.Authorization.Get(token1.Id));
Assert.ThrowsAsync<NotFoundException>(() => client.Authorization.Get(token2.Id));
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(token1.Id));
Assert.ThrowsAsync<NotFoundException>(() => github.Authorization.Get(token2.Id));
}
}
}
28 changes: 13 additions & 15 deletions Octokit.Tests.Integration/Clients/BlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@
using Octokit.Tests.Integration;
using System.Threading.Tasks;
using Xunit;
using Octokit.Tests.Integration.Helpers;

public class BlobClientTests : IDisposable
{
readonly IBlobsClient _fixture;
readonly Repository _repository;
readonly string _owner;
private readonly IBlobsClient _fixture;
private readonly RepositoryContext _context;

public BlobClientTests()
{
var client = Helper.GetAuthenticatedClient();
_fixture = client.GitDatabase.Blob;
var github = Helper.GetAuthenticatedClient();
_fixture = github.GitDatabase.Blob;

var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = client.Repository.Create(new NewRepository(repoName) { AutoInit = true }).Result;
_owner = _repository.Owner.Login;
_context = github.CreateRepositoryContext("public-repo").Result;
}

[IntegrationTest]
Expand All @@ -30,7 +28,7 @@ public async Task CanCreateABlob()
Encoding = EncodingType.Utf8
};

var result = await _fixture.Create(_owner, _repository.Name, blob);
var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, blob);

Assert.False(String.IsNullOrWhiteSpace(result.Sha));
}
Expand All @@ -47,7 +45,7 @@ public async Task CanCreateABlobWithBase64Contents()
Encoding = EncodingType.Base64
};

var result = await _fixture.Create(_owner, _repository.Name, blob);
var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, blob);

Assert.False(String.IsNullOrWhiteSpace(result.Sha));
}
Expand All @@ -61,8 +59,8 @@ public async Task CanGetABlob()
Encoding = EncodingType.Utf8
};

var result = await _fixture.Create(_owner, _repository.Name, newBlob);
var blob = await _fixture.Get(_owner, _repository.Name, result.Sha);
var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newBlob);
var blob = await _fixture.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha);

Assert.Equal(result.Sha, blob.Sha);
Assert.Equal(EncodingType.Base64, blob.Encoding);
Expand All @@ -84,8 +82,8 @@ public async Task CanGetABlobWithBase64Text()
Encoding = EncodingType.Base64
};

var result = await _fixture.Create(_owner, _repository.Name, newBlob);
var blob = await _fixture.Get(_owner, _repository.Name, result.Sha);
var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newBlob);
var blob = await _fixture.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha);

Assert.Equal(result.Sha, blob.Sha);
Assert.Equal(EncodingType.Base64, blob.Encoding);
Expand All @@ -98,6 +96,6 @@ public async Task CanGetABlobWithBase64Text()

public void Dispose()
{
Helper.DeleteRepo(_repository);
_context.Dispose();
}
}
29 changes: 11 additions & 18 deletions Octokit.Tests.Integration/Clients/BranchesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,27 @@
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using Xunit;

public class BranchesClientTests
{
public class TheGetBranchesMethod : IDisposable
public class TheGetBranchesMethod
{
readonly Repository _repository;
readonly IGitHubClient _github;

public TheGetBranchesMethod()
{
_github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = _github.Repository.Create(new NewRepository(repoName) { AutoInit = true }).Result;
}
public TheGetBranchesMethod() { }

[IntegrationTest]
public async Task ReturnsBranches()
{
var branches = await _github.Repository.GetAllBranches(_repository.Owner.Login, _repository.Name);

Assert.NotEmpty(branches);
Assert.Equal(branches[0].Name, "master");
}
var github = Helper.GetAuthenticatedClient();

public void Dispose()
{
Helper.DeleteRepo(_repository);
using (var context = await github.CreateRepositoryContext("public-repo"))
{
var branches = await github.Repository.GetAllBranches(context.Repository.Owner.Login, context.Repository.Name);

Assert.NotEmpty(branches);
Assert.Equal(branches[0].Name, "master");
}
}
}
}
Loading

0 comments on commit 1266ac0

Please sign in to comment.