-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using NUnit.Framework; | ||
|
||
namespace FastGenericNew.Tests | ||
{ | ||
public class ConstructorOfTests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
#region Reference Types | ||
[Test] | ||
public void CO_Class() | ||
{ | ||
var value = ConstructorOf<TClass>.value; | ||
Assert.NotNull(value); | ||
} | ||
|
||
[Test] | ||
public void CO_Class_PrivateConstructor() | ||
{ | ||
var value = ConstructorOf<TClassPrivateConstructor, int, string>.value; | ||
Assert.NotNull(value); | ||
} | ||
|
||
[Test] | ||
public void CO_Class_Parameters() | ||
{ | ||
var value = ConstructorOf<TClassWithParam, int, string>.value; | ||
Assert.NotNull(value); | ||
} | ||
#endregion | ||
|
||
#region Value Types | ||
[Test] | ||
public void CO_Struct_IsNull() | ||
{ | ||
var value = ConstructorOf<TStruct>.value; | ||
Assert.IsNull(value); | ||
} | ||
|
||
[Test] | ||
public void CO_Struct_PrivateConstructor() | ||
{ | ||
var value = ConstructorOf<TStructPrivateConstructor, int, string>.value; | ||
Assert.NotNull(value); | ||
} | ||
|
||
[Test] | ||
public void CO_Struct_Parameters() | ||
{ | ||
var value = ConstructorOf<TStructWithParam, int, string>.value; | ||
Assert.NotNull(value); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NUnit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FastGenericNew\FastGenericNew.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using NUnit.Framework; | ||
|
||
namespace FastGenericNew.Tests | ||
{ | ||
public class FastNewTests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
#region ReferenceType FastNew Tests | ||
[Test] | ||
public void FN_Object() | ||
{ | ||
var value = FastNew<object>.CreateInstance(); | ||
Assert.NotNull(value); | ||
} | ||
|
||
[Test] | ||
public void FN_Class() | ||
{ | ||
var value = FastNew<TClass>.CreateInstance(); | ||
Assert.NotNull(value); | ||
} | ||
|
||
[Test] | ||
public void FN_Class_Parameters() | ||
{ | ||
const int expectedNum = int.MaxValue; | ||
const string expectedText = "test"; | ||
var value = FastNew<TClassWithParam, int, string>.CreateInstance(expectedNum, expectedText); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.NotNull(value); | ||
Assert.AreEqual(expectedNum, value.i); | ||
Assert.AreEqual(expectedText, value.text); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void FN_Class_PrivateConstructor() | ||
{ | ||
const int expectedNum = int.MaxValue; | ||
const string expectedText = "test"; | ||
var value = FastNew<TClassPrivateConstructor, int, string>.CreateInstance(expectedNum, expectedText); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.NotNull(value); | ||
Assert.AreEqual(expectedNum, value.i); | ||
Assert.AreEqual(expectedText, value.text); | ||
}); | ||
} | ||
#endregion | ||
|
||
#region ValueType FastNew Tests | ||
[Test] | ||
public void FN_Struct() | ||
{ | ||
var value = FastNew<TStruct>.CreateInstance(); | ||
Assert.AreEqual(default(TStruct), value); | ||
} | ||
|
||
[Test] | ||
public void FN_Struct_Parameters() | ||
{ | ||
const int expectedNum = int.MaxValue; | ||
const string expectedText = "test"; | ||
var value = FastNew<TStructWithParam, int, string>.CreateInstance(expectedNum, expectedText); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.AreEqual(expectedNum, value.i); | ||
Assert.AreEqual(expectedText, value.text); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void FN_Struct_PrivateConstructor() | ||
{ | ||
const int expectedNum = int.MaxValue; | ||
const string expectedText = "test"; | ||
var value = FastNew<TStructPrivateConstructor, int, string>.CreateInstance(expectedNum, expectedText); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.AreEqual(expectedNum, value.i); | ||
Assert.AreEqual(expectedText, value.text); | ||
}); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace FastGenericNew.Tests | ||
{ | ||
public interface TInterface { } | ||
|
||
public class TClass { } | ||
|
||
public sealed class TClassPrivateConstructor | ||
{ | ||
public int i; | ||
public string text; | ||
private TClassPrivateConstructor(int i, string text) | ||
{ | ||
this.i = i; | ||
this.text = text; | ||
} | ||
} | ||
|
||
public class TClassWithParam | ||
{ | ||
public int i; | ||
public string text; | ||
public TClassWithParam(int i, string text) | ||
{ | ||
this.i = i; | ||
this.text = text; | ||
} | ||
} | ||
|
||
public abstract class TAbstractClass { } | ||
|
||
public sealed class TDerivedClass : TAbstractClass { } | ||
|
||
public struct TStruct { } | ||
|
||
public struct TStructWithParam | ||
{ | ||
public int i; | ||
public string text; | ||
public TStructWithParam(int i, string text) | ||
{ | ||
this.i = i; | ||
this.text = text; | ||
} | ||
} | ||
|
||
public struct TStructPrivateConstructor | ||
{ | ||
public int i; | ||
public string text; | ||
public TStructPrivateConstructor(int i, string text) | ||
{ | ||
this.i = i; | ||
this.text = text; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using NUnit.Framework; | ||
|
||
namespace FastGenericNew.Tests | ||
{ | ||
public class TypeNewTests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
} | ||
|
||
#region Object | ||
[Test] | ||
public void TN_Object() | ||
{ | ||
var createInstance = TypeNew.GetCreateInstance(typeof(object)); | ||
Assert.NotNull(createInstance); | ||
} | ||
|
||
[Test] | ||
public void TN_Object_Generic() | ||
{ | ||
var createInstance = TypeNew.GetCreateInstance<object>(typeof(object)); | ||
Assert.NotNull(createInstance); | ||
} | ||
#endregion | ||
|
||
|
||
#region Reference Types | ||
[Test] | ||
public void TN_Class() | ||
{ | ||
var createInstance = TypeNew.GetCreateInstance(typeof(TClass)); | ||
Assert.NotNull(createInstance()); | ||
} | ||
|
||
[Test] | ||
public void TN_Class_Parameters() | ||
{ | ||
const int expectedNum = int.MaxValue; | ||
const string expectedText = "test"; | ||
var createInstance = TypeNew.GetCreateInstance<object, int, string>(typeof(TClassWithParam), typeof(int), typeof(string)); | ||
Assert.Multiple(() => | ||
{ | ||
var obj = createInstance(expectedNum, expectedText); | ||
var value = obj as TClassWithParam; | ||
Assert.IsInstanceOf<TClassWithParam>(obj); | ||
Assert.NotNull(value); | ||
Assert.AreEqual(expectedNum, value.i); | ||
Assert.AreSame(expectedText, value.text); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void TN_Class_Generic() | ||
{ | ||
var createInstance = TypeNew.GetCreateInstance<TClass>(typeof(TClass)); | ||
Assert.NotNull(createInstance()); | ||
} | ||
|
||
[Test] | ||
public void TN_Class_Generic_DerivedClass() | ||
{ | ||
var createInstance = TypeNew.GetCreateInstance<TAbstractClass>(typeof(TDerivedClass)); | ||
Assert.NotNull(createInstance()); | ||
} | ||
#endregion | ||
|
||
#region Reference Types | ||
[Test] | ||
public void TN_Struct() | ||
{ | ||
|
||
var createInstance = TypeNew.GetCreateInstance(typeof(TStruct)); | ||
Assert.NotNull(createInstance()); | ||
} | ||
|
||
[Test] | ||
public void TN_Struct_Generic() | ||
{ | ||
var createInstance = TypeNew.GetCreateInstance<TStruct>(typeof(TStruct)); | ||
Assert.NotNull(createInstance()); | ||
} | ||
|
||
|
||
#endregion | ||
} | ||
} |