Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up unit tests for CoreLibrary and complete tests for Type.GetType #143

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Tests/NFUnitTestTypes/NFUnitTestTypes.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<RunSettingsFilePath>$(MSBuildProjectDirectory)\nano.runsettings</RunSettingsFilePath>
</PropertyGroup>
<ItemGroup>
<Compile Include="UnitTestSubTypeTests.cs" />
<Compile Include="UnitTestValueArrayTypess.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitTestValueDefultConstTests.cs" />
Expand Down
55 changes: 55 additions & 0 deletions Tests/NFUnitTestTypes/UnitTestSubTypeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

using nanoFramework.TestFramework;
using System;
using System.Diagnostics;

namespace NFUnitTestTypes
{
[TestClass]
class UnitTestSubTypeTests
{
// Class1 and SubClass1 used for testing type def of inherited classes
class Class1
{
public class SubClass1
{
void Method1()
{

}
}

public SubClass1 Sc1ClassRef = new SubClass1();

}
[TestMethod]
// Test sub-class in the string for GetType(string). a "+" is used for sub-classes within a class.
public void SubClassGetTypeValid()
{
const string subClass1FullName = "NFUnitTestTypes.UnitTestSubTypeTests+Class1+SubClass1";
Class1 c1 = new Class1();
string className = c1.Sc1ClassRef.GetType().FullName;
Assert.Equal(className, subClass1FullName, "The object FullName was not correct");
Type testType = Type.GetType(subClass1FullName);
Assert.NotNull(testType, $"The Type for {subClass1FullName} could not be parsed");
Assert.Equal(testType.Name, "SubClass1");
Assert.Equal(testType.FullName, subClass1FullName);

}
[TestMethod]
// Test sub-class in the string for GetType(string). a "+" is used for sub-classes within a class.
public void SubClassGetTypeInvalid()
{
Class1 c1 = new Class1();
Type testType = Type.GetType("UnitTestSubTypeTests+Class1+SubClass1"); // test without the namespace. This should NOT work
Assert.Null(testType, "The Type for UnitTestSubTypeTests+Class1+SubClass1 should not parse");

}

}
}
33 changes: 17 additions & 16 deletions Tests/NFUnitTestTypes/UnitTestValueArrayTypess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,96 +115,97 @@ public class ValueArrayTestClass01
public static void testMethod()
{
byte[] b = { 0 };
Assert.IsType(b.GetType(), Type.GetType("System.Byte[]"));
Type compareType = Type.GetType("System.Byte[]");
Assert.IsType(compareType, b, $"The type {compareType.Name} is not equal to {b.GetType().Name}");
}
}
public class ValueArrayTestClass02
{
public static void testMethod()
{
char[] c = { 'a' };
Assert.IsType(c.GetType(), Type.GetType("System.Char[]"));
Assert.IsType(Type.GetType("System.Char[]"), c);
}
}
public class ValueArrayTestClass03
{
public static void testMethod()
{
short[] s = { 0 };
Assert.IsType(s.GetType(), Type.GetType("System.Int16[]"));
Assert.IsType(Type.GetType("System.Int16[]"), s);
}
}
public class ValueArrayTestClass04
{
public static void testMethod()
{
int[] i = { 0 };
Assert.IsType(i.GetType(), Type.GetType("System.Int32[]"));
Assert.IsType(Type.GetType("System.Int32[]"), i);
}
}
public class ValueArrayTestClass05
{
public static void testMethod()
{
long[] l = { 0L };
Assert.IsType(l.GetType(), Type.GetType("System.Int64[]"));
Assert.IsType(Type.GetType("System.Int64[]"), l);
}
}
public class ValueArrayTestClass06
{
public static void testMethod()
{
float[] f = { 0.0f };
Assert.IsType(f.GetType(), Type.GetType("System.Single[]"));
Assert.IsType(Type.GetType("System.Single[]"), f);
}
}
public class ValueArrayTestClass07
{
public static void testMethod()
{
double[] d = { 0.0d };
Assert.IsType(d.GetType(), Type.GetType("System.Double[]"));
Assert.IsType(Type.GetType("System.Double[]"), d);
}
}
public class ValueArrayTestClass09
{
public static void testMethod()
{
bool[] b = { true };
Assert.IsType(b.GetType(), Type.GetType("System.Boolean[]"));
Assert.IsType(Type.GetType("System.Boolean[]"), b);
}
}

public class ValueArrayTestClass12
{
public static void testMethod()
{
string[] b = { "string" };
Assert.IsType(b.GetType(), Type.GetType("System.String[]"));
string[] strArray = { "string" };
Assert.IsType(Type.GetType("System.String[]"), strArray);
}
}
public class ValueArrayTestClass13
{
public static void testMethod()
{
sbyte[] b = { 0 };
Assert.IsType(b.GetType(), Type.GetType("System.SByte[]"));
sbyte[] sb = { 0 };
Assert.IsType(Type.GetType("System.SByte[]"), sb);
}
}
public class ValueArrayTestClass14
{
public static void testMethod()
{
ushort[] s = { 0 };
Assert.IsType(s.GetType(), Type.GetType("System.UInt16[]"));
ushort[] us = { 0 };
Assert.IsType(Type.GetType("System.UInt16[]"), us);
}
}
public class ValueArrayTestClass15
{
public static void testMethod()
{
uint[] i = { 0 };
Assert.IsType(i.GetType(), Type.GetType("System.UInt32[]"));
uint[] ui = { 0 };
Assert.IsType(Type.GetType("System.UInt32[]"), ui);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/NFUnitTestTypes/UnitTestValueDefultConstTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ public static void testMethod()

struct MyStruct
{
#pragma warning disable CS0649 // variable not initialized
public int I;
public Object MyObj;
#pragma warning restore CS0649
}

public class ValueDefault_ConstTestClass12
Expand Down
Loading