New convention test was added. Now each "TheCtor" class must have "EnsuresNonNullArguments" method were throwing of ArgumentNullException from client constructor class should be tested.

All unused "using" directives were removed.
This commit is contained in:
aedampir@gmail.com
2016-04-10 22:28:18 +07:00
parent a783d05abb
commit 36c08248fa
52 changed files with 119 additions and 76 deletions

View File

@@ -8,19 +8,32 @@ namespace Octokit.Tests.Conventions
public class ClientConstructorTests
{
[Theory]
[MemberData("GetTestConstructorsClasses")]
public void CheckTestConstructorsNames(Type type)
[MemberData("GetTestConstructorClasses")]
public void CheckTestConstructorNames(Type type)
{
const string constructorClassName = "TheCtor";
const string constructorTestClassName = "TheCtor";
const string constructorTestMethodName = "EnsuresNonNullArguments";
var classes = new HashSet<string>(type.GetNestedTypes().Select(t => t.Name));
if (!classes.Contains(constructorClassName))
if (!classes.Contains(constructorTestClassName))
{
throw new MissingClientConstructorTestClassException(type);
}
var ctors = type.GetNestedTypes().Where(t => t.Name == constructorTestClassName)
.SelectMany(t => t.GetMethods())
.Where(info => info.ReturnType == typeof(void) && info.IsPublic)
.Select(info => info.Name);
var methods = new HashSet<string>(ctors);
if (!methods.Contains(constructorTestMethodName))
{
throw new MissingClientConstructorTestMethodException(type);
}
}
public static IEnumerable<object[]> GetTestConstructorsClasses()
public static IEnumerable<object[]> GetTestConstructorClasses()
{
var tests = typeof(GitHubClientTests)
.Assembly

View File

@@ -10,7 +10,7 @@ namespace Octokit.Tests.Conventions
static string CreateMessage(Type ctorTest)
{
return string.Format("Constructor test method is missing {0}.", ctorTest.FullName);
return string.Format("Constructor test class is missing {0}.", ctorTest.FullName);
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
namespace Octokit.Tests.Conventions
{
public class MissingClientConstructorTestMethodException : Exception
{
public MissingClientConstructorTestMethodException(Type modelType)
: base(CreateMessage(modelType))
{ }
static string CreateMessage(Type ctorTest)
{
return string.Format("Constructor test method is missing {0}.", ctorTest.FullName);
}
}
}

View File

@@ -65,6 +65,7 @@
<Compile Include="Exception\InvalidDebuggerDisplayAttributeValueException.cs" />
<Compile Include="Exception\InvalidDebuggerDisplayReturnType.cs" />
<Compile Include="Exception\MissingClientConstructorTestClassException.cs" />
<Compile Include="Exception\MissingClientConstructorTestMethodException.cs" />
<Compile Include="Exception\MissingDebuggerDisplayAttributeException.cs" />
<Compile Include="Exception\MissingDebuggerDisplayPropertyException.cs" />
<Compile Include="Exception\MutableModelPropertiesException.cs" />

View File

@@ -115,7 +115,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new AssigneesClient(null));
}

View File

@@ -17,7 +17,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void ThrowsForBadArgs()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new AuthorizationsClient(null));
}

View File

@@ -4,7 +4,6 @@ using System.Linq;
using System.Threading.Tasks;
using NSubstitute;
using Octokit;
using Octokit.Tests.Helpers;
using Xunit;
public class CommitsClientTests
@@ -71,7 +70,7 @@ public class CommitsClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new CommitsClient(null));
}

View File

@@ -105,7 +105,7 @@ public class DeploymentStatusClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new DeploymentStatusClient(null));
}

View File

@@ -143,7 +143,7 @@ public class DeploymentsClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new DeploymentsClient(null));
}

View File

@@ -10,7 +10,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new GistCommentsClient(null));
}
@@ -71,7 +71,7 @@ namespace Octokit.Tests.Clients
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForGist(""));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForGist("24", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForGist("", ApiOptions.None));
}
}

View File

@@ -305,7 +305,7 @@ public class GistsClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new GistsClient(null));
}

View File

@@ -8,7 +8,7 @@ public class GitDatabaseClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new GitDatabaseClient(null));
}

View File

@@ -209,14 +209,14 @@ namespace Octokit.Tests.Clients
}
}
public class TheCtor
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
[Fact]
public void EnsuresArgument()
{
Assert.Throws<ArgumentNullException>(() => new IssueCommentsClient(null));
}
Assert.Throws<ArgumentNullException>(() => new IssueCommentsClient(null));
}
}
[Fact]
public void CanDeserializeIssueComment()

View File

@@ -4,7 +4,6 @@ using System.Net;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
@@ -240,7 +239,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new IssuesClient(null));
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
@@ -46,7 +45,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new CommitsClient(null));
}

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
@@ -151,7 +150,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new MilestonesClient(null));
}

View File

@@ -175,7 +175,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgumentsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new MiscellaneousClient(null));
}

View File

@@ -12,7 +12,7 @@ public class OauthClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() =>
new OauthClient(null));

View File

@@ -4,7 +4,6 @@ using System.Net;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
@@ -18,7 +17,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsureNonNullArguments()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new OrganizationMembersClient(null));
}

View File

@@ -9,6 +9,12 @@ public class PullRequestReviewCommentsClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new PullRequestReviewCommentsClient(null));
}
[Fact]
public void PullRequestReviewCommentCreateEnsuresArgumentsValue()
{

View File

@@ -249,7 +249,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new PullRequestsClient(null));
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
@@ -11,7 +10,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ReferencesClient(null));
}

View File

@@ -11,7 +11,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() =>
new ReleasesClient(null));

View File

@@ -17,7 +17,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void ThrowsForBadArgs()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new RepoCollaboratorsClient(null));
}

View File

@@ -5,7 +5,6 @@ using System.Threading.Tasks;
using NSubstitute;
using Octokit;
using Octokit.Internal;
using Octokit.Tests.Helpers;
using Xunit;
public class RepositoryCommentsClientTests
@@ -177,7 +176,7 @@ public class RepositoryCommentsClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new RepositoryCommentsClient(null));
}

View File

@@ -14,7 +14,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void ThrowsForBadArgs()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new RepositoryDeployKeysClient(null));
}

View File

@@ -14,7 +14,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void ThrowsForBadArgs()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new SshKeysClient(null));
}

View File

@@ -13,7 +13,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void DoesThrowOnBadArguments()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new StatisticsClient(null));
}

View File

@@ -64,7 +64,7 @@ public class TagsClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new TagsClient(null));
}

View File

@@ -4,7 +4,6 @@ using System.Net;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests
@@ -108,7 +107,7 @@ namespace Octokit.Tests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new TreesClient(null));
}

View File

@@ -113,7 +113,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArguments()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(
() => new UserEmailsClient(null));

View File

@@ -1,6 +1,5 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
@@ -129,7 +128,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void EnsuresArguments()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(
() => new UserEmailsClient(null));

View File

@@ -18,7 +18,7 @@ namespace Octokit.Tests.Clients
public class TheCtor
{
[Fact]
public void ThrowsForBadArgs()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new UsersClient(null));
}

View File

@@ -11,6 +11,30 @@ namespace Octokit.Tests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new GitHubClient((IConnection)null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient((ProductHeaderValue)null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(new ProductHeaderValue("UnitTest"), (ICredentialStore)null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, Substitute.For<ICredentialStore>()));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(new ProductHeaderValue("UnitTest"), (Uri)null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, new Uri("http://github.com")));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, (ICredentialStore)null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, (Uri)null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(new ProductHeaderValue("UnitTest"), null, null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, Substitute.For<ICredentialStore>(), null));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, null, new Uri("http://github.com")));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(null, Substitute.For<ICredentialStore>(), new Uri("http://github.com")));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(new ProductHeaderValue("UnitTest"), null, new Uri("http://github.com")));
Assert.Throws<ArgumentNullException>(() => new GitHubClient(new ProductHeaderValue("UnitTest"), Substitute.For<ICredentialStore>(), null));
}
[Fact]
public void CreatesAnonymousClientByDefault()
{

View File

@@ -10,7 +10,7 @@ namespace Octokit.Tests
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() =>
new ObservableEnterpriseSearchIndexingClient(null));

View File

@@ -1,10 +1,8 @@
using System;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Reactive
@@ -69,7 +67,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableBlobClient(null));
}

View File

@@ -12,7 +12,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableCommitsClient(null));
}

View File

@@ -121,7 +121,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(
() => new ObservableDeploymentStatusClient(null));

View File

@@ -174,7 +174,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArguments()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableDeploymentsClient(null));
}

View File

@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Reactive
@@ -192,7 +190,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableIssueCommentsClient(null));
}

View File

@@ -2,7 +2,6 @@
using Octokit;
using Octokit.Internal;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
@@ -390,7 +389,7 @@ public class ObservableIssuesClientTests
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new IssuesClient(null));
}

View File

@@ -6,7 +6,6 @@ using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Reactive
@@ -236,7 +235,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new MilestonesClient(null));
}

View File

@@ -136,7 +136,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableMiscellaneousClient((IGitHubClient)null));
}

View File

@@ -7,7 +7,6 @@ using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Reactive
@@ -352,10 +351,11 @@ namespace Octokit.Tests.Reactive
await Assert.ThrowsAsync<ArgumentException>(() => client.Files("owner", "", 1));
}
}
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new PullRequestsClient(null));
}

View File

@@ -12,7 +12,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableReleasesClient(null));
}

View File

@@ -12,7 +12,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableRepositoryCommitsClient(null));
}

View File

@@ -11,7 +11,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void ThrowsForBadArgs()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableRepositoryDeployKeysClient(null));
}

View File

@@ -13,7 +13,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableStarredClient(null));
}

View File

@@ -1,6 +1,5 @@
using System;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
@@ -38,7 +37,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresNotNullGitHubClient()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableTeamsClient(null));
}

View File

@@ -12,7 +12,7 @@ namespace Octokit.Tests
public class TheCtor
{
[Fact]
public void EnsuresArgumentIsNotNull()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableTreesClient(null));
}

View File

@@ -180,7 +180,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableUserAdministrationClient(null));
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Linq;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
@@ -84,7 +83,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArgument()
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableUserKeysClient(null));
}