diff --git a/Octokit.Tests/Helpers/AssertEx.cs b/Octokit.Tests/Helpers/AssertEx.cs index 7044aec2..ed388d23 100644 --- a/Octokit.Tests/Helpers/AssertEx.cs +++ b/Octokit.Tests/Helpers/AssertEx.cs @@ -58,5 +58,12 @@ namespace Octokit.Tests.Helpers await Throws(async () => await action(argument)); } } + + public static void IsReadOnlyCollection(object instance) where T : class + { + var collection = instance as ICollection; + // The collection == null case is for .NET 4.0 + Assert.True(instance is IReadOnlyCollection && (collection == null || collection.IsReadOnly)); + } } } diff --git a/Octokit.Tests/Models/PunchCardTests.cs b/Octokit.Tests/Models/PunchCardTests.cs index 05f6f19e..b83efb34 100644 --- a/Octokit.Tests/Models/PunchCardTests.cs +++ b/Octokit.Tests/Models/PunchCardTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using Octokit.Response; +using Octokit.Tests.Helpers; using Xunit; public class PunchCardTests @@ -61,7 +62,7 @@ public class PunchCardTests var punchCard = new PunchCard(points); - Assert.Null(punchCard.PunchPoints as ICollection); + AssertEx.IsReadOnlyCollection(punchCard.PunchPoints); } } } \ No newline at end of file diff --git a/Octokit.Tests/Models/SearchCodeRequestTests.cs b/Octokit.Tests/Models/SearchCodeRequestTests.cs index 7035c6e4..86587d57 100644 --- a/Octokit.Tests/Models/SearchCodeRequestTests.cs +++ b/Octokit.Tests/Models/SearchCodeRequestTests.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Octokit; +using Octokit; +using Octokit.Tests.Helpers; using Xunit; public class SearchCodeRequestTests @@ -14,7 +14,7 @@ public class SearchCodeRequestTests var result = request.MergedQualifiers(); // If I can cast this to a writeable collection, then that defeats the purpose of a read only. - Assert.Null(result as ICollection); + AssertEx.IsReadOnlyCollection(result); } } } diff --git a/Octokit.Tests/Models/SearchIssuesRequestTests.cs b/Octokit.Tests/Models/SearchIssuesRequestTests.cs index b26d343c..03a48514 100644 --- a/Octokit.Tests/Models/SearchIssuesRequestTests.cs +++ b/Octokit.Tests/Models/SearchIssuesRequestTests.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Octokit; +using Octokit; +using Octokit.Tests.Helpers; using Xunit; internal class SearchIssuesRequestTests @@ -14,7 +14,7 @@ internal class SearchIssuesRequestTests var result = request.MergedQualifiers(); // If I can cast this to a writeable collection, then that defeats the purpose of a read only. - Assert.Null(result as ICollection); + AssertEx.IsReadOnlyCollection(result); } } } diff --git a/Octokit.Tests/Models/SearchUsersRequestTests.cs b/Octokit.Tests/Models/SearchUsersRequestTests.cs index 7a6a3a39..110a3f60 100644 --- a/Octokit.Tests/Models/SearchUsersRequestTests.cs +++ b/Octokit.Tests/Models/SearchUsersRequestTests.cs @@ -1,5 +1,5 @@ -using System.Collections.Generic; -using Octokit; +using Octokit; +using Octokit.Tests.Helpers; using Xunit; internal class SearchUsersRequestTests @@ -14,7 +14,7 @@ internal class SearchUsersRequestTests var result = request.MergedQualifiers(); // If I can cast this to a writeable collection, then that defeats the purpose of a read only. - Assert.Null(result as ICollection); + AssertEx.IsReadOnlyCollection(result); } } }