mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 19:46:07 +00:00
catch an obscure requirement when creating trees
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user