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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
using NUnit.Framework;
namespace Mono.Linker.Tests {
[TestFixture]
public class TypeNameParserTests {
[Test]
public void TryParseTypeAssemblyQualifiedName_Null ()
{
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (null, out string typeName, out string assemblyName), Is.False);
}
[Test]
public void TryParseTypeAssemblyQualifiedName_FullyQualified ()
{
var value = typeof (TypeNameParserTests).AssemblyQualifiedName;
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo (typeof (TypeNameParserTests).FullName));
Assert.That (assemblyName, Is.EqualTo (typeof (TypeNameParserTests).Assembly.GetName ().Name));
}
[Test]
public void TryParseTypeAssemblyQualifiedName_NameAndAssemblyOnly ()
{
var value = $"{typeof (TypeNameParserTests).FullName}, {typeof (TypeNameParserTests).Assembly.GetName ().Name}";
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo (typeof (TypeNameParserTests).FullName));
Assert.That (assemblyName, Is.EqualTo (typeof (TypeNameParserTests).Assembly.GetName ().Name));
}
[Test]
public void TryParseTypeAssemblyQualifiedName_NameOnly ()
{
var value = typeof (TypeNameParserTests).FullName;
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo (typeof (TypeNameParserTests).FullName));
Assert.That (assemblyName, Is.Null);
}
[Test]
public void TryParseTypeAssemblyQualifiedName_GenericType_FullyQualified ()
{
var value = typeof (SampleGenericType<,>).AssemblyQualifiedName;
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo($"{typeof (TypeNameParserTests).FullName}/SampleGenericType`2"));
Assert.That (assemblyName, Is.EqualTo(typeof (TypeNameParserTests).Assembly.GetName ().Name));
}
[Test]
public void TryParseTypeAssemblyQualifiedName_GenericType_NameAndAssemblyOnly ()
{
var value = $"{typeof (SampleGenericType<,>).FullName}, {typeof (TypeNameParserTests).Assembly.GetName ().Name}";
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo ($"{typeof (TypeNameParserTests).FullName}/SampleGenericType`2"));
Assert.That (assemblyName, Is.EqualTo (typeof (TypeNameParserTests).Assembly.GetName ().Name));
}
[Test]
public void TryParseTypeAssemblyQualifiedName_GenericType_NameOnly ()
{
var value = typeof (SampleGenericType<,>).FullName;
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo ($"{typeof (TypeNameParserTests).FullName}/SampleGenericType`2"));
Assert.That (assemblyName, Is.Null);
}
[Test]
public void TryParseTypeAssemblyQualifiedName_NestedType_FullyQualified ()
{
var value = typeof (SampleNestedType).AssemblyQualifiedName;
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo($"{typeof (TypeNameParserTests).FullName}/{nameof (SampleNestedType)}"));
Assert.That (assemblyName, Is.EqualTo(typeof (TypeNameParserTests).Assembly.GetName ().Name));
}
[Test]
public void TryParseTypeAssemblyQualifiedName_NestedType_NameAndAssemblyOnly ()
{
var value = $"{typeof (SampleNestedType).FullName}, {typeof (TypeNameParserTests).Assembly.GetName().Name}";
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo ($"{typeof (TypeNameParserTests).FullName}/{nameof (SampleNestedType)}"));
Assert.That (assemblyName, Is.EqualTo (typeof (TypeNameParserTests).Assembly.GetName ().Name));
}
[Test]
public void TryParseTypeAssemblyQualifiedName_NestedType_NameOnly ()
{
var value = typeof (SampleNestedType).FullName;
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (value, out string typeName, out string assemblyName), Is.True);
Assert.That (typeName, Is.EqualTo ($"{typeof (TypeNameParserTests).FullName}/{nameof (SampleNestedType)}"));
Assert.That (assemblyName, Is.Null);
}
[Test]
public void MissingTypeName ()
{
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (", System", out string typeName, out string assemblyName), Is.False);
Assert.That (typeName, Is.Null);
Assert.That (assemblyName, Is.Null);
}
[TestCase ("A[]][")]
[TestCase ("A][")]
[TestCase ("A[")]
[TestCase (", , ")]
[TestCase (", , , ")]
[TestCase (", , , , ")]
public void InvalidValues (string name)
{
Assert.That (TypeNameParser.TryParseTypeAssemblyQualifiedName (name, out string typeName, out string assemblyName), Is.False);
Assert.That (typeName, Is.Null);
Assert.That (assemblyName, Is.Null);
}
class SampleNestedType {
}
class SampleGenericType<T1, T2> {
}
}
}
|