diff --git a/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs b/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs new file mode 100644 index 00000000..6932b4ec --- /dev/null +++ b/Octokit.Tests.Conventions/Exception/MissingConstructorTestClassException.cs @@ -0,0 +1,16 @@ +using System; + +namespace Octokit.Tests.Conventions +{ + public class MissingConstructorTestClassException : Exception + { + public MissingConstructorTestClassException(Type modelType) + : base(CreateMessage(modelType)) + { } + + static string CreateMessage(Type ctorTest) + { + return string.Format("Constructor test method is missing {0}.", ctorTest.FullName); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj index c6012156..8f3c5695 100644 --- a/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj +++ b/Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj @@ -64,6 +64,7 @@ + @@ -81,6 +82,7 @@ + diff --git a/Octokit.Tests.Conventions/TestConstructorTests.cs b/Octokit.Tests.Conventions/TestConstructorTests.cs new file mode 100644 index 00000000..c3ef0f2f --- /dev/null +++ b/Octokit.Tests.Conventions/TestConstructorTests.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Octokit.Tests.Clients; +using Xunit; + +namespace Octokit.Tests.Conventions +{ + public class TestConstructorTests + { + [Theory] + [MemberData("GetTestConstructorsClasses")] + public void CheckTestConstructorsNames(Type type) + { + const string constructorClassName = "TheCtor"; + var classes = new HashSet(type.GetNestedTypes().Select(t => t.Name)); + + if (!classes.Contains(constructorClassName)) + { + throw new MissingConstructorTestClassException(type); + } + } + + public static IEnumerable GetTestConstructorsClasses() + { + var tests = typeof(EventsClientTests) + .Assembly + .ExportedTypes + .Where(type => type.IsClass && type.IsPublic && type.Name.EndsWith("ClientTests")) + .Select(type => new[] { type }).ToList(); + return tests; + } + } +} \ No newline at end of file