catch an obscure requirement when creating trees

This commit is contained in:
Brendan Forster
2013-11-27 12:37:58 -08:00
parent c89ca5fc11
commit 06737995ed
2 changed files with 21 additions and 1 deletions
+13
View File
@@ -62,6 +62,19 @@ namespace Octokit.Tests
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, new NewTree()));
await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", new NewTree()));
}
[Fact]
public async Task EnsureExceptionIsThrownWhenModeIsNotProvided()
{
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem { Path = "README.md", Type = TreeType.Blob, Sha = "2e1a73d60f004fd842d4bad28aa42392d4f35d28" });
var connection = Substitute.For<IApiConnection>();
var client = new TreesClient(connection);
await AssertEx.Throws<ArgumentException>(
async () => await client.Create("fake", "repo", newTree));
}
}
public class TheCtor
+8 -1
View File
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace Octokit
{
@@ -44,6 +46,11 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(newTree, "newTree");
if (newTree.Tree.Any(t => String.IsNullOrWhiteSpace(t.Mode)))
{
throw new ArgumentException("You have specified items in the tree which do not have a Mode value set.");
}
return ApiConnection.Post<TreeResponse>(ApiUrls.Tree(owner, name), newTree);
}
}