Skip to content

Commit 121db8d

Browse files
authored
Merge 1a17b03 into 3bad831
2 parents 3bad831 + 1a17b03 commit 121db8d

7 files changed

+96
-88
lines changed

Tests/NFUnitTestTypes/NFUnitTestTypes.nfproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<RunSettingsFilePath>$(MSBuildProjectDirectory)\nano.runsettings</RunSettingsFilePath>
2828
</PropertyGroup>
2929
<ItemGroup>
30+
<Compile Include="UnitTestSubTypeTests.cs" />
3031
<Compile Include="UnitTestValueArrayTypess.cs" />
3132
<Compile Include="Properties\AssemblyInfo.cs" />
3233
<Compile Include="UnitTestValueDefultConstTests.cs" />
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
using nanoFramework.TestFramework;
8+
using System;
9+
using System.Diagnostics;
10+
11+
namespace NFUnitTestTypes
12+
{
13+
[TestClass]
14+
class UnitTestSubTypeTests
15+
{
16+
// Class1 and SubClass1 used for testing type def of inherited classes
17+
class Class1
18+
{
19+
public class SubClass1
20+
{
21+
void Method1()
22+
{
23+
24+
}
25+
}
26+
27+
public SubClass1 Sc1ClassRef = new SubClass1();
28+
29+
}
30+
[TestMethod]
31+
// Test sub-class in the string for GetType(string). a "+" is used for sub-classes within a class.
32+
public void SubClassGetTypeValid()
33+
{
34+
const string subClass1FullName = "NFUnitTestTypes.UnitTestSubTypeTests+Class1+SubClass1";
35+
Class1 c1 = new Class1();
36+
string className = c1.Sc1ClassRef.GetType().FullName;
37+
Assert.Equal(className, subClass1FullName, "The object FullName was not correct");
38+
Type testType = Type.GetType(subClass1FullName);
39+
Assert.NotNull(testType, $"The Type for {subClass1FullName} could not be parsed");
40+
Assert.Equal(testType.Name, "SubClass1");
41+
Assert.Equal(testType.FullName, subClass1FullName);
42+
43+
}
44+
[TestMethod]
45+
// Test sub-class in the string for GetType(string). a "+" is used for sub-classes within a class.
46+
public void SubClassGetTypeInvalid()
47+
{
48+
Class1 c1 = new Class1();
49+
Type testType = Type.GetType("UnitTestSubTypeTests+Class1+SubClass1"); // test without the namespace. This should NOT work
50+
Assert.Null(testType, "The Type for UnitTestSubTypeTests+Class1+SubClass1 should not parse");
51+
52+
}
53+
54+
}
55+
}

Tests/NFUnitTestTypes/UnitTestValueArrayTypess.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,96 +115,97 @@ public class ValueArrayTestClass01
115115
public static void testMethod()
116116
{
117117
byte[] b = { 0 };
118-
Assert.IsType(b.GetType(), Type.GetType("System.Byte[]"));
118+
Type compareType = Type.GetType("System.Byte[]");
119+
Assert.IsType(compareType, b, $"The type {compareType.Name} is not equal to {b.GetType().Name}");
119120
}
120121
}
121122
public class ValueArrayTestClass02
122123
{
123124
public static void testMethod()
124125
{
125126
char[] c = { 'a' };
126-
Assert.IsType(c.GetType(), Type.GetType("System.Char[]"));
127+
Assert.IsType(Type.GetType("System.Char[]"), c);
127128
}
128129
}
129130
public class ValueArrayTestClass03
130131
{
131132
public static void testMethod()
132133
{
133134
short[] s = { 0 };
134-
Assert.IsType(s.GetType(), Type.GetType("System.Int16[]"));
135+
Assert.IsType(Type.GetType("System.Int16[]"), s);
135136
}
136137
}
137138
public class ValueArrayTestClass04
138139
{
139140
public static void testMethod()
140141
{
141142
int[] i = { 0 };
142-
Assert.IsType(i.GetType(), Type.GetType("System.Int32[]"));
143+
Assert.IsType(Type.GetType("System.Int32[]"), i);
143144
}
144145
}
145146
public class ValueArrayTestClass05
146147
{
147148
public static void testMethod()
148149
{
149150
long[] l = { 0L };
150-
Assert.IsType(l.GetType(), Type.GetType("System.Int64[]"));
151+
Assert.IsType(Type.GetType("System.Int64[]"), l);
151152
}
152153
}
153154
public class ValueArrayTestClass06
154155
{
155156
public static void testMethod()
156157
{
157158
float[] f = { 0.0f };
158-
Assert.IsType(f.GetType(), Type.GetType("System.Single[]"));
159+
Assert.IsType(Type.GetType("System.Single[]"), f);
159160
}
160161
}
161162
public class ValueArrayTestClass07
162163
{
163164
public static void testMethod()
164165
{
165166
double[] d = { 0.0d };
166-
Assert.IsType(d.GetType(), Type.GetType("System.Double[]"));
167+
Assert.IsType(Type.GetType("System.Double[]"), d);
167168
}
168169
}
169170
public class ValueArrayTestClass09
170171
{
171172
public static void testMethod()
172173
{
173174
bool[] b = { true };
174-
Assert.IsType(b.GetType(), Type.GetType("System.Boolean[]"));
175+
Assert.IsType(Type.GetType("System.Boolean[]"), b);
175176
}
176177
}
177178

178179
public class ValueArrayTestClass12
179180
{
180181
public static void testMethod()
181182
{
182-
string[] b = { "string" };
183-
Assert.IsType(b.GetType(), Type.GetType("System.String[]"));
183+
string[] strArray = { "string" };
184+
Assert.IsType(Type.GetType("System.String[]"), strArray);
184185
}
185186
}
186187
public class ValueArrayTestClass13
187188
{
188189
public static void testMethod()
189190
{
190-
sbyte[] b = { 0 };
191-
Assert.IsType(b.GetType(), Type.GetType("System.SByte[]"));
191+
sbyte[] sb = { 0 };
192+
Assert.IsType(Type.GetType("System.SByte[]"), sb);
192193
}
193194
}
194195
public class ValueArrayTestClass14
195196
{
196197
public static void testMethod()
197198
{
198-
ushort[] s = { 0 };
199-
Assert.IsType(s.GetType(), Type.GetType("System.UInt16[]"));
199+
ushort[] us = { 0 };
200+
Assert.IsType(Type.GetType("System.UInt16[]"), us);
200201
}
201202
}
202203
public class ValueArrayTestClass15
203204
{
204205
public static void testMethod()
205206
{
206-
uint[] i = { 0 };
207-
Assert.IsType(i.GetType(), Type.GetType("System.UInt32[]"));
207+
uint[] ui = { 0 };
208+
Assert.IsType(Type.GetType("System.UInt32[]"), ui);
208209
}
209210
}
210211
}

Tests/NFUnitTestTypes/UnitTestValueDefultConstTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,10 @@ public static void testMethod()
199199

200200
struct MyStruct
201201
{
202+
#pragma warning disable CS0649 // variable not initialized
202203
public int I;
203204
public Object MyObj;
205+
#pragma warning restore CS0649
204206
}
205207

206208
public class ValueDefault_ConstTestClass12

0 commit comments

Comments
 (0)