From d68d893abdc7ced6603c7c56053358ca419841b4 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 2 Apr 2023 20:48:15 +0100 Subject: [PATCH] test: 100% coverage on Reflection extensions --- X10D.Tests/src/Reflection/MemberInfoTests.cs | 17 +++++++++++------ X10D.Tests/src/Reflection/TypeTests.cs | 4 +++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/X10D.Tests/src/Reflection/MemberInfoTests.cs b/X10D.Tests/src/Reflection/MemberInfoTests.cs index 24d2675..1774b36 100644 --- a/X10D.Tests/src/Reflection/MemberInfoTests.cs +++ b/X10D.Tests/src/Reflection/MemberInfoTests.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Reflection; +using Microsoft.VisualStudio.TestTools.UnitTesting; using X10D.Reflection; namespace X10D.Tests.Reflection; @@ -69,10 +70,14 @@ public class MemberInfoTests Assert.ThrowsException(() => (type!.SelectFromCustomAttribute((CLSCompliantAttribute attribute) => attribute.IsCompliant, true))); - Assert.ThrowsException(() => - { - Func? selector = null; - typeof(int).SelectFromCustomAttribute(selector!); - }); + const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | + BindingFlags.Instance | BindingFlags.Static; + var memberInfo = typeof(int).GetMembers(bindingFlags)[0]; + Func? selector = null; + + Assert.ThrowsException(() => typeof(int).SelectFromCustomAttribute(selector!)); + Assert.ThrowsException(() => typeof(int).SelectFromCustomAttribute(selector!, default)); + Assert.ThrowsException(() => memberInfo.SelectFromCustomAttribute(selector!)); + Assert.ThrowsException(() => memberInfo.SelectFromCustomAttribute(selector!, default)); } } diff --git a/X10D.Tests/src/Reflection/TypeTests.cs b/X10D.Tests/src/Reflection/TypeTests.cs index 4324afb..f76b7fd 100644 --- a/X10D.Tests/src/Reflection/TypeTests.cs +++ b/X10D.Tests/src/Reflection/TypeTests.cs @@ -32,6 +32,7 @@ public class TypeTests { Assert.ThrowsException(() => typeof(object).Inherits(null!)); Assert.ThrowsException(() => ((Type?)null)!.Inherits(typeof(object))); + Assert.ThrowsException(() => ((Type?)null)!.Inherits()); } [TestMethod] @@ -47,7 +48,8 @@ public class TypeTests public void Implements_ShouldThrow_GivenNull() { Assert.ThrowsException(() => typeof(object).Implements(null!)); - Assert.ThrowsException(() => ((Type?)null)!.Implements(typeof(object))); + Assert.ThrowsException(() => ((Type?)null)!.Implements(typeof(IComparable))); + Assert.ThrowsException(() => ((Type?)null)!.Implements()); } [TestMethod]