Skip to content

Commit

Permalink
Merge pull request #2 from TattsGroup/Ctor_Overload
Browse files Browse the repository at this point in the history
Add unit tests for CreateFile DeleteFile and UpdateFile
  • Loading branch information
M-Zuber committed Feb 8, 2016
2 parents 84c7746 + 1bfa625 commit d88fb85
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions Octokit.Tests/Clients/RepositoryContentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,135 @@ public async Task ReturnsContents()
Assert.Equal(1, contents.Count);
}
}

public class TheCreateFileMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

string expectedUri = "repos/org/repo/contents/path/to/file";
client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

client.CreateFile("org", "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<CreateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Branch == "mybranch"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateFile(null, "repo", "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateFile("org", null, "path/to/file", new CreateFileRequest("message", "myfilecontents", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateFile("org", "repo", null, new CreateFileRequest("message", "myfilecontents", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateFile("org", "repo", "path/to/file", null));
}
}

public class TheDeleteFileMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

string expectedUri = "repos/org/repo/contents/path/to/file";
client.DeleteFile("org", "repo", "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch"));

connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

client.DeleteFile("org", "repo", "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch"));

connection.Received().Delete(
Arg.Any<Uri>(),
Arg.Is<DeleteFileRequest>(a =>
a.Message == "message"
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteFile(null, "repo", "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteFile("org", null, "path/to/file", new DeleteFileRequest("message", "1234abc", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteFile("org", "repo", null, new DeleteFileRequest("message", "1234abc", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.DeleteFile("org", "repo", "path/to/file", null));
}
}

public class TheUpdateFileMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

string expectedUri = "repos/org/repo/contents/path/to/file";
client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(Arg.Is<Uri>(u => u.ToString() == expectedUri), Arg.Any<object>());
}

[Fact]
public void PassesRequestObject()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

client.UpdateFile("org", "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch"));

connection.Received().Put<RepositoryContentChangeSet>(
Arg.Any<Uri>(),
Arg.Is<UpdateFileRequest>(a =>
a.Message == "message"
&& a.Content == "myfilecontents"
&& a.Sha == "1234abc"
&& a.Branch == "mybranch"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryContentsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile(null, "repo", "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile("org", null, "path/to/file", new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile("org", "repo", null, new UpdateFileRequest("message", "myfilecontents", "1234abc", "mybranch")));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.UpdateFile("org", "repo", "path/to/file", null));
}
}
}
}

0 comments on commit d88fb85

Please sign in to comment.