add convention test to ensure all response models have a public parameterless ctor

2 model classes were missing one - technically not needed for these 2 classes due to their api calls being basic data types that then get populated into these objects, but it's easiest to just add them to these 2 classes so the test can pass on all response models
This commit is contained in:
Ryan Gribble
2016-07-05 23:29:42 +10:00
parent e701ae763c
commit e3fa865381
5 changed files with 30 additions and 0 deletions
@@ -0,0 +1,11 @@
using System;
namespace Octokit.Tests.Conventions
{
public class MissingPublicParameterlessCtorException : Exception
{
public MissingPublicParameterlessCtorException(Type modelType)
: base(string.Format("Model type '{0}' is missing a Public Parameterless Constructor required by SimpleJson Deserializer.", modelType.FullName))
{ }
}
}
+12
View File
@@ -37,6 +37,18 @@ namespace Octokit.Tests.Conventions
}
}
[Theory]
[MemberData("ResponseModelTypes")]
public void AllResponseModelsHavePublicParameterlessCtors(Type modelType)
{
var ctor = modelType.GetConstructor(Type.EmptyTypes);
if (ctor == null || !ctor.IsPublic)
{
throw new MissingPublicParameterlessCtorException(modelType);
}
}
[Theory]
[MemberData("ResponseModelTypes")]
public void ResponseModelsHaveGetterOnlyProperties(Type modelType)
@@ -67,6 +67,7 @@
<Compile Include="Exception\MissingClientConstructorTestClassException.cs" />
<Compile Include="Exception\MissingClientConstructorTestMethodException.cs" />
<Compile Include="Exception\MissingDebuggerDisplayAttributeException.cs" />
<Compile Include="Exception\MissingPublicParameterlessCtorException.cs" />
<Compile Include="Exception\MissingDebuggerDisplayPropertyException.cs" />
<Compile Include="Exception\MutableModelPropertiesException.cs" />
<Compile Include="Exception\PaginationGetAllMethodNameMismatchException.cs" />
+3
View File
@@ -10,6 +10,9 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PunchCard
{
public PunchCard()
{ }
public PunchCard(IEnumerable<IList<int>> punchCardData)
{
Ensure.ArgumentNotNull(punchCardData, "punchCardData");
@@ -7,6 +7,9 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryLanguage
{
public RepositoryLanguage()
{ }
public RepositoryLanguage(string name, long numberOfBytes)
{
Name = name;