Added test for readonly collections

This commit is contained in:
Kristian Hellang
2015-01-06 09:19:45 +01:00
parent 6731a59263
commit 273ad8acdc
2 changed files with 32 additions and 0 deletions
+23
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using Octokit.Tests.Helpers;
@@ -36,6 +37,28 @@ namespace Octokit.Tests.Conventions
}
}
[Theory]
[MemberData("ResponseModelTypes")]
public void ResponseModelsHaveReadOnlyCollections(Type modelType)
{
foreach (var property in modelType.GetProperties())
{
var propertyType = property.PropertyType;
if (typeof(IEnumerable).IsAssignableFrom(propertyType))
{
// Let's skip arrays as well for now.
// There seems to be some special array handling in the Gist model.
if (propertyType == typeof(string) || propertyType.IsArray)
{
continue;
}
AssertEx.IsReadOnlyCollection(propertyType);
}
}
}
public static IEnumerable<object[]> ModelTypes
{
get { return GetModelTypes(includeRequestModels: true).Select(type => new[] { type }); }