Skip to content

Commit 3de8e01

Browse files
committed
Fixes in unit tests
- Replace Debug with Console. - Remove real metadata token from check. ***NO_CI***
1 parent 5da547f commit 3de8e01

File tree

3 files changed

+63
-45
lines changed

3 files changed

+63
-45
lines changed

MetadataProcessor.Tests/Core/Utility/DumperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void DumpAssemblyTest()
133133
nanoTablesContext.TypeReferencesTable.TryGetTypeReferenceId(type1.BaseType, out baseTypeReferenceId);
134134
typeFlags = (uint)nanoTypeDefinitionTable.GetFlags(type1, nanoTablesContext.MethodDefinitionTable);
135135

136-
Assert.IsTrue(dumpFileContent.Contains($"TypeDef {nanoDumperGenerator.TypeDefRefIdToString(type1, typeRefId)}\r\n-------------------------------------------------------\r\n '{type1.Name}'\r\n Flags: {typeFlags:X8}\r\n Extends: {nanoDumperGenerator.TypeDefExtendsTypeToString(type1.BaseType, baseTypeReferenceId)}\r\n Enclosed: TestNFApp.OneClassOverAll[04000000] /*0200001D*/"));
136+
Assert.IsTrue(dumpFileContent.Contains($"TypeDef {nanoDumperGenerator.TypeDefRefIdToString(type1, typeRefId)}\r\n-------------------------------------------------------\r\n '{type1.Name}'\r\n Flags: {typeFlags:X8}\r\n Extends: {nanoDumperGenerator.TypeDefExtendsTypeToString(type1.BaseType, baseTypeReferenceId)}\r\n Enclosed: TestNFApp.OneClassOverAll[04000000]"));
137137

138138
// String heap
139139
foreach (string stringKey in nanoTablesContext.StringTable.GetItems().Keys)

MetadataProcessor.Tests/TestNFApp/GenericClass.cs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Diagnostics;
56

67
namespace TestNFApp
@@ -21,58 +22,58 @@ class ClassDoThis : IDo
2122
{
2223
public void Do1()
2324
{
24-
Debug.WriteLine($"{nameof(Do1)}");
25+
Console.WriteLine($"{nameof(Do1)}");
2526
}
2627

2728
public void Do2()
2829
{
29-
Debug.WriteLine($"{nameof(Do2)}");
30+
Console.WriteLine($"{nameof(Do2)}");
3031
}
3132

3233
public void DoThis1()
3334
{
34-
Debug.WriteLine($"{nameof(DoThis1)}");
35+
Console.WriteLine($"{nameof(DoThis1)}");
3536
}
3637

3738
public void DoThis2()
3839
{
39-
Debug.WriteLine($"{nameof(DoThis2)}");
40+
Console.WriteLine($"{nameof(DoThis2)}");
4041
}
4142
}
4243

4344
class ClassDoInt : IDo
4445
{
4546
public void Do1()
4647
{
47-
Debug.WriteLine($"{nameof(Do1)}");
48+
Console.WriteLine($"{nameof(Do1)}");
4849
}
4950

5051
public void Do2()
5152
{
52-
Debug.WriteLine($"{nameof(Do2)}");
53+
Console.WriteLine($"{nameof(Do2)}");
5354
}
5455
}
5556

5657
class ClassDoThatInt : IDo, IDoThat
5758
{
5859
public void Do1()
5960
{
60-
Debug.WriteLine($"{nameof(Do1)}");
61+
Console.WriteLine($"{nameof(Do1)}");
6162
}
6263

6364
public void Do2()
6465
{
65-
Debug.WriteLine($"{nameof(Do2)}");
66+
Console.WriteLine($"{nameof(Do2)}");
6667
}
6768

6869
public void DoThat1()
6970
{
70-
Debug.WriteLine($"{nameof(DoThat1)}");
71+
Console.WriteLine($"{nameof(DoThat1)}");
7172
}
7273

7374
public void DoThat2()
7475
{
75-
Debug.WriteLine($"{nameof(DoThat2)}");
76+
Console.WriteLine($"{nameof(DoThat2)}");
7677
}
7778

7879
}
@@ -81,25 +82,25 @@ class ClassDoThisAndThat : ClassDoThis, IDoThat
8182
{
8283
public void DoThat1()
8384
{
84-
Debug.WriteLine($"{nameof(DoThat1)}");
85+
Console.WriteLine($"{nameof(DoThat1)}");
8586
}
8687

8788
public void DoThat2()
8889
{
89-
Debug.WriteLine($"{nameof(DoThat2)}");
90+
Console.WriteLine($"{nameof(DoThat2)}");
9091
}
9192
}
9293

9394
public class ClassDoString : IDo
9495
{
9596
public void Do1()
9697
{
97-
Debug.WriteLine($"{nameof(Do1)}");
98+
Console.WriteLine($"{nameof(Do1)}");
9899
}
99100

100101
public void Do2()
101102
{
102-
Debug.WriteLine($"{nameof(Do2)}");
103+
Console.WriteLine($"{nameof(Do2)}");
103104
}
104105
}
105106

@@ -118,22 +119,22 @@ public void InstanceGenericDoOne(T t)
118119
{
119120
T v = t;
120121

121-
Debug.WriteLine($"{nameof(InstanceGenericDoOne)} --> {v} is <{v.GetType()}>");
122+
Console.WriteLine($"{nameof(InstanceGenericDoOne)} --> {v} is <{v.GetType()}>");
122123
}
123124

124125
public void InstanceGenericDoTwo<T2>(T p1, T2 p2)
125126
{
126127
T v1 = p1;
127128
T2 v2 = p2;
128129

129-
Debug.WriteLine($"{nameof(InstanceGenericDoTwo)}<{v2.GetType()}> --> {v1},{v2} is <{v1.GetType()},{v2.GetType()}>");
130+
Console.WriteLine($"{nameof(InstanceGenericDoTwo)}<{v2.GetType()}> --> {v1},{v2} is <{v1.GetType()},{v2.GetType()}>");
130131
}
131132

132133
public void InstanceGenericDoOneOther<T1>(T1 t)
133134
{
134135
T1 v1 = t;
135136

136-
Debug.WriteLine($"{nameof(InstanceGenericDoOneOther)}<{v1.GetType()}> --> {v1} is <{v1.GetType()}>");
137+
Console.WriteLine($"{nameof(InstanceGenericDoOneOther)}<{v1.GetType()}> --> {v1} is <{v1.GetType()}>");
137138
}
138139
}
139140

@@ -148,7 +149,7 @@ public void InstanceGenericDoOne(T t)
148149
{
149150
T v = t;
150151

151-
Debug.WriteLine($"{nameof(InstanceGenericDoOne)} --> {v} is <{typeof(T).FullName}>");
152+
Console.WriteLine($"{nameof(InstanceGenericDoOne)} --> {v} is <{typeof(T).FullName}>");
152153
}
153154

154155
public void InstanceGenericDoTwo<T2>(T p1, T1 p2, T2 p3)
@@ -157,23 +158,23 @@ public void InstanceGenericDoTwo<T2>(T p1, T1 p2, T2 p3)
157158
T1 v2 = p2;
158159
T2 v3 = p3;
159160

160-
Debug.WriteLine($"{nameof(InstanceGenericDoTwo)}<{v3.GetType()}> --> {v1},{v2},{v3} is <{v1.GetType()},{v2.GetType()},{v3.GetType()}>");
161+
Console.WriteLine($"{nameof(InstanceGenericDoTwo)}<{v3.GetType()}> --> {v1},{v2},{v3} is <{v1.GetType()},{v2.GetType()},{v3.GetType()}>");
161162
}
162163

163164
public void InstanceGenericDoOneOther<T2>(T1 p1, T2 p2)
164165
{
165166
T1 v1 = p1;
166167
T2 v2 = p2;
167168

168-
Debug.WriteLine($"{nameof(InstanceGenericDoOneOther)}<{v1.GetType()}> --> {v1},{v2} is <{typeof(T1).FullName},{typeof(T2).FullName}>");
169+
Console.WriteLine($"{nameof(InstanceGenericDoOneOther)}<{v1.GetType()}> --> {v1},{v2} is <{typeof(T1).FullName},{typeof(T2).FullName}>");
169170
}
170171
}
171172

172173
public class GenericClassTests
173174
{
174175
private static void StaticGenericDo<T1, T2>(T1 val, T2 val2) where T1 : IDo where T2 : IDo
175176
{
176-
Debug.WriteLine($">> {nameof(StaticGenericDo)}<{val.GetType()},{val2.GetType()}>");
177+
Console.WriteLine($">> {nameof(StaticGenericDo)}<{val.GetType()},{val2.GetType()}>");
177178

178179
val.Do1();
179180
val.Do2();
@@ -183,7 +184,7 @@ private static void StaticGenericDo<T1, T2>(T1 val, T2 val2) where T1 : IDo wher
183184

184185
private static void StaticGenericDoThisAndThat<T1, T2>(T1 val, T2 val2) where T1 : ClassDoThis, IDo where T2 : ClassDoThatInt
185186
{
186-
Debug.WriteLine($">> {nameof(StaticGenericDoThisAndThat)}<{val.GetType()},{val2.GetType()}>");
187+
Console.WriteLine($">> {nameof(StaticGenericDoThisAndThat)}<{val.GetType()},{val2.GetType()}>");
187188

188189
val.DoThis1();
189190
val.DoThis2();
@@ -193,42 +194,58 @@ private static void StaticGenericDoThisAndThat<T1, T2>(T1 val, T2 val2) where T1
193194

194195
public GenericClassTests()
195196
{
196-
Debug.WriteLine("++++++++++++++++++++");
197-
Debug.WriteLine("++ Generics Tests ++");
198-
Debug.WriteLine("++++++++++++++++++++");
199-
Debug.WriteLine("");
197+
Console.WriteLine("++++++++++++++++++++");
198+
Console.WriteLine("++ Generics Tests ++");
199+
Console.WriteLine("++++++++++++++++++++");
200+
Console.WriteLine("");
200201

201202

203+
Console.WriteLine("++ ClassDoString ++");
204+
202205
var other = new ClassDoString();
203206
other.Do1();
204207
other.Do2();
205208

209+
Console.WriteLine("++ GenericClass<int> ++");
210+
206211
var gc1 = new GenericClass<int>();
207212
gc1.NoGenerics();
208213
gc1.InstanceGenericDoOne(1);
209214
gc1.InstanceGenericDoTwo(1, "TWO");
210215
gc1.InstanceGenericDoOneOther(false);
211216
gc1.GenericField = 10;
212217

218+
Console.WriteLine("++ AnotherGenericClass<byte, bool> ++");
219+
213220
var agc1 = new AnotherGenericClass<byte, bool>();
214221
agc1.InstanceGenericDoOne(22);
215222
agc1.InstanceGenericDoTwo(33, false, "NINE");
216223
agc1.InstanceGenericDoOneOther(true, 44);
217224
agc1.GenericField = 11;
218225
agc1.AnotherGenericField = false;
219226

227+
Console.WriteLine("++ GenericClass<string> ++");
228+
220229
var gc2 = new GenericClass<string>();
221230
gc2.InstanceGenericDoOne("ONE");
222231
gc2.InstanceGenericDoTwo("ONE", "TWO");
223232
gc2.InstanceGenericDoOneOther(33.33);
224233
gc2.GenericField = "TEN";
225234

235+
Console.WriteLine("++ StaticGenericDo Int and String ++");
236+
226237
StaticGenericDo(new ClassDoInt(), new ClassDoString());
227238

239+
Console.WriteLine("++ StaticGenericDo String and Int ++");
240+
228241
StaticGenericDo(new ClassDoString(), new ClassDoInt());
229242

243+
Console.WriteLine("++ StaticGenericDoThisAndThat This and That ++");
244+
230245
StaticGenericDoThisAndThat(new ClassDoThis(), new ClassDoThatInt());
231246

247+
Console.WriteLine("++ StaticGenericDoThisAndThat ThisAndThat and ThatInt ++");
248+
232249
StaticGenericDoThisAndThat(new ClassDoThisAndThat(), new ClassDoThatInt());
233250
}
234251
}

MetadataProcessor.Tests/TestNFApp/Program.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public static void Main()
1717

1818
///////////////////////////////////////////////////////////////////
1919
// referenced class
20-
Debug.WriteLine("++++++++++++++++++++++++++++");
21-
Debug.WriteLine("++ Referenced class tests ++");
22-
Debug.WriteLine("++++++++++++++++++++++++++++");
23-
Debug.WriteLine("");
20+
Console.WriteLine("++++++++++++++++++++++++++++");
21+
Console.WriteLine("++ Referenced class tests ++");
22+
Console.WriteLine("++++++++++++++++++++++++++++");
23+
Console.WriteLine("");
2424

2525
// instantiating a class on another assembly
2626
ClassOnAnotherAssembly anotherClass = new ClassOnAnotherAssembly();
@@ -70,10 +70,11 @@ public static void Main()
7070
switch (messageType)
7171
{
7272
case IAmAClassWithAnEnum.EnumA.Test:
73-
Console.WriteLine("all good");
73+
Console.WriteLine($"Not good... {messageType}");
7474
break;
7575

7676
default:
77+
Console.WriteLine("all good");
7778
break;
7879
}
7980

@@ -100,10 +101,10 @@ private static void MiscelaneousTests()
100101

101102
public static void ReflectionTests()
102103
{
103-
Debug.WriteLine("++++++++++++++++++++++");
104-
Debug.WriteLine("++ Reflection tests ++");
105-
Debug.WriteLine("++++++++++++++++++++++");
106-
Debug.WriteLine("");
104+
Console.WriteLine("++++++++++++++++++++++");
105+
Console.WriteLine("++ Reflection tests ++");
106+
Console.WriteLine("++++++++++++++++++++++");
107+
Console.WriteLine("");
107108

108109
// Get the type of MyClass1.
109110
Type myType = typeof(MyClass1);
@@ -128,16 +129,16 @@ public static void ReflectionTests()
128129
// Get the methods associated with MyClass1.
129130
MemberInfo[] myMethods = myType.GetMethods();
130131

131-
Debug.WriteLine("");
132-
Debug.WriteLine($"'{myType.Name}' type has '{myMethods.Length}' methods");
132+
Console.WriteLine("");
133+
Console.WriteLine($"'{myType.Name}' type has '{myMethods.Length}' methods");
133134

134135
// Display the attributes for each of the methods of MyClass1.
135136
for (int i = 0; i < myMethods.Length; i++)
136137
{
137138
string methodName = myMethods[i].Name;
138139

139-
Debug.WriteLine("");
140-
Debug.WriteLine($"Getting custom attributes for '{methodName}'");
140+
Console.WriteLine("");
141+
Console.WriteLine($"Getting custom attributes for '{methodName}'");
141142

142143
myAttributes = myMethods[i].GetCustomAttributes(true);
143144

@@ -204,12 +205,12 @@ public static void ReflectionTests()
204205
Console.WriteLine($"MaxAttribute value is: 0x{attMax.Max.ToString("X8")}");
205206

206207
AuthorAttribute attAuthor = (AuthorAttribute)myFieldAttributes[1];
207-
Debug.WriteLine("");
208-
Debug.WriteLine($"AuthorAttribute value is: '{attAuthor.Author}'");
208+
Console.WriteLine("");
209+
Console.WriteLine($"AuthorAttribute value is: '{attAuthor.Author}'");
209210

210-
Debug.WriteLine("");
211-
Debug.WriteLine("+++ReflectionTests completed");
212-
Debug.WriteLine("");
211+
Console.WriteLine("");
212+
Console.WriteLine("+++ReflectionTests completed");
213+
Console.WriteLine("");
213214
}
214215
}
215216
}

0 commit comments

Comments
 (0)