-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathXML_Methods.cs
56 lines (54 loc) · 1.77 KB
/
XML_Methods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Reflection;
namespace Towel_Testing;
[TestClass]
public class XML_Methods
{
[TestMethod]
public void Test()
{
foreach (Type type in typeof(Statics).Assembly.GetTypes())
{
foreach (MethodInfo method in type.GetMethods().Where(m => m.Name.StartsWith("XML_")))
{
Assert.IsTrue(method.IsStatic, method.Name);
Assert.IsTrue(method.IsPublic, method.Name);
Assert.IsTrue(!method.IsGenericMethod, method.Name);
Assert.IsTrue(method.ReturnType == typeof(void), method.Name);
Assert.IsTrue(method.GetParameters().Length is 0, method.Name);
ObsoleteAttribute? obsolete = method.GetCustomAttribute<ObsoleteAttribute>();
Assert.IsTrue(obsolete is not null, method.Name);
Assert.IsTrue(obsolete!.IsError, method.Name);
Assert.IsTrue(obsolete!.Message is NotIntended, method.Name);
try
{
MethodInfo invoke = method;
if (method.DeclaringType!.IsGenericType)
{
Type declaringType = method.DeclaringType;
Type[] generics = declaringType.GetGenericArguments();
for (int i = 0; i < generics.Length; i++)
{
if (generics[i].GetGenericParameterConstraints().Length > 1)
{
generics[i] = generics[i].GetGenericParameterConstraints()[^1];
}
else
{
generics[i] = typeof(int);
}
}
declaringType = declaringType.MakeGenericType(generics);
invoke = declaringType.GetMethods().FirstOrDefault(m => m.MetadataToken == method.MetadataToken)!;
}
invoke.Invoke(null, null);
Assert.Fail(method.Name);
}
catch (TargetInvocationException exception)
{
Assert.IsTrue(exception.InnerException is not null, method.Name);
Assert.IsTrue(exception.InnerException is DocumentationMethodException, method.Name);
}
}
}
}
}