test: 100% coverage on Reflection extensions

This commit is contained in:
Oliver Booth 2023-04-02 20:48:15 +01:00
parent 303617a888
commit d68d893abd
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
2 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Reflection; using X10D.Reflection;
namespace X10D.Tests.Reflection; namespace X10D.Tests.Reflection;
@ -69,10 +70,14 @@ public class MemberInfoTests
Assert.ThrowsException<ArgumentNullException>(() => Assert.ThrowsException<ArgumentNullException>(() =>
(type!.SelectFromCustomAttribute((CLSCompliantAttribute attribute) => attribute.IsCompliant, true))); (type!.SelectFromCustomAttribute((CLSCompliantAttribute attribute) => attribute.IsCompliant, true)));
Assert.ThrowsException<ArgumentNullException>(() => const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic |
{ BindingFlags.Instance | BindingFlags.Static;
Func<CLSCompliantAttribute, bool>? selector = null; var memberInfo = typeof(int).GetMembers(bindingFlags)[0];
typeof(int).SelectFromCustomAttribute(selector!); Func<CLSCompliantAttribute, bool>? selector = null;
});
Assert.ThrowsException<ArgumentNullException>(() => typeof(int).SelectFromCustomAttribute(selector!));
Assert.ThrowsException<ArgumentNullException>(() => typeof(int).SelectFromCustomAttribute(selector!, default));
Assert.ThrowsException<ArgumentNullException>(() => memberInfo.SelectFromCustomAttribute(selector!));
Assert.ThrowsException<ArgumentNullException>(() => memberInfo.SelectFromCustomAttribute(selector!, default));
} }
} }

View File

@ -32,6 +32,7 @@ public class TypeTests
{ {
Assert.ThrowsException<ArgumentNullException>(() => typeof(object).Inherits(null!)); Assert.ThrowsException<ArgumentNullException>(() => typeof(object).Inherits(null!));
Assert.ThrowsException<ArgumentNullException>(() => ((Type?)null)!.Inherits(typeof(object))); Assert.ThrowsException<ArgumentNullException>(() => ((Type?)null)!.Inherits(typeof(object)));
Assert.ThrowsException<ArgumentNullException>(() => ((Type?)null)!.Inherits<object>());
} }
[TestMethod] [TestMethod]
@ -47,7 +48,8 @@ public class TypeTests
public void Implements_ShouldThrow_GivenNull() public void Implements_ShouldThrow_GivenNull()
{ {
Assert.ThrowsException<ArgumentNullException>(() => typeof(object).Implements(null!)); Assert.ThrowsException<ArgumentNullException>(() => typeof(object).Implements(null!));
Assert.ThrowsException<ArgumentNullException>(() => ((Type?)null)!.Implements(typeof(object))); Assert.ThrowsException<ArgumentNullException>(() => ((Type?)null)!.Implements(typeof(IComparable)));
Assert.ThrowsException<ArgumentNullException>(() => ((Type?)null)!.Implements<IComparable>());
} }
[TestMethod] [TestMethod]