diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 25fd687..8e38e8b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -27,6 +27,8 @@ jobs: 5.0.x 6.0.x 7.0.x + 8.0.x + 9.0.x include-prerelease: true - name: Restore dependencies run: dotnet restore diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe8de6f..b247c77 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -30,6 +30,8 @@ jobs: 5.0.x 6.0.x 7.0.x + 8.0.x + 9.0.x include-prerelease: true - name: Restore dependencies run: dotnet restore diff --git a/FastGenericNew.sln b/FastGenericNew.sln index 95c847e..43c6dd1 100644 --- a/FastGenericNew.sln +++ b/FastGenericNew.sln @@ -14,14 +14,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Root", "Root", "{F142034C-8 Benchmark_ReferenceType.png = Benchmark_ReferenceType.png Benchmark_ValueType.png = Benchmark_ValueType.png FastGenericNew.Shared.props = FastGenericNew.Shared.props + .github\workflows\publish.yml = .github\workflows\publish.yml README.md = README.md + .github\workflows\tests.yml = .github\workflows\tests.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGenericNew.Tests", "src\FastGenericNew.Tests\FastGenericNew.Tests.csproj", "{7A750C15-4CF3-4F5B-BFA8-AFBB98827770}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGenericNew.Benchmarks", "src\FastGenericNew.Benchmarks\FastGenericNew.Benchmarks.csproj", "{24108B29-8FAD-4080-90B4-0A6A19CE06BE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastGenericNew.SourceGenerator.InternalGenerator", "src\FastGenericNew.SourceGenerator.InternalGenerator\FastGenericNew.SourceGenerator.InternalGenerator.csproj", "{33032C07-28EF-4AD6-BE00-32303BB9DA7B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastGenericNew.SourceGenerator.InternalGenerator", "src\FastGenericNew.SourceGenerator.InternalGenerator\FastGenericNew.SourceGenerator.InternalGenerator.csproj", "{33032C07-28EF-4AD6-BE00-32303BB9DA7B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/FastGenericNew.Tests/FastGenericNew.Tests.csproj b/src/FastGenericNew.Tests/FastGenericNew.Tests.csproj index c4867f1..1ffcb1a 100644 --- a/src/FastGenericNew.Tests/FastGenericNew.Tests.csproj +++ b/src/FastGenericNew.Tests/FastGenericNew.Tests.csproj @@ -1,7 +1,7 @@ - + - net6.0;net8.0 + net6.0;net8.0;net9.0 $(TargetFrameworks);net48 10 enable diff --git a/src/FastGenericNew.Tests/TestData.cs b/src/FastGenericNew.Tests/TestData.cs index 3196e31..10fc9ce 100644 --- a/src/FastGenericNew.Tests/TestData.cs +++ b/src/FastGenericNew.Tests/TestData.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.Data.SqlTypes; +using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -35,6 +38,11 @@ public static class TestData typeof(nint), typeof(nuint), +#if NET8_0_OR_GREATER + typeof(Int128), + typeof(UInt128), +#endif + #endregion typeof(DateTime), diff --git a/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ExceptionsTest.cs b/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ExceptionsTest.cs index 71ee87b..f85ca51 100644 --- a/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ExceptionsTest.cs +++ b/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ExceptionsTest.cs @@ -6,12 +6,13 @@ public class ExceptionsTest [Test()] public void ExceptionInterface() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); try { ClrAllocator.CreateInstance(); Assert.Fail("The expected exception is not thrown."); } - catch (MissingMethodException e) + catch (Exception e) { Assert.IsTrue(e.Message.StartsWith("Cannot create an instance of an interface")); } @@ -20,6 +21,7 @@ public void ExceptionInterface() [Test()] public void ExceptionAbstract() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); try { ClrAllocator.CreateInstance(); @@ -34,6 +36,7 @@ public void ExceptionAbstract() [Test()] public void ExceptionPLString() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); try { ClrAllocator.CreateInstance(); @@ -49,6 +52,7 @@ public void ExceptionPLString() [Test()] public void ExceptionNotFoundNoParameter() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); try { ClrAllocator.CreateInstance(); diff --git a/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ReferenceTypes.cs b/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ReferenceTypes.cs index e6ad16f..aeb2180 100644 --- a/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ReferenceTypes.cs +++ b/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ReferenceTypes.cs @@ -8,6 +8,7 @@ public class ReferenceTypes [Test] public void Object() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); var expected = Activator.CreateInstance(); var actual = ClrAllocator.CreateInstance(); Assert.IsTrue(expected.GetType() == actual.GetType()); @@ -17,6 +18,7 @@ public void Object() [Parallelizable(ParallelScope.All)] public void CommonTypes() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); var expected = Activator.CreateInstance(); var actual = ClrAllocator.CreateInstance(); Assert.AreEqual(expected, actual); @@ -26,6 +28,7 @@ public void CommonTypes() [Parallelizable(ParallelScope.All)] public void ParallelNew() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); const int count = 512; T[] array = new T[count]; Parallel.For(0, count, new ParallelOptions() { MaxDegreeOfParallelism = count }, i => diff --git a/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ValueType.cs b/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ValueType.cs index 92caaed..ea30135 100644 --- a/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ValueType.cs +++ b/src/FastGenericNew.Tests/Units/ClrAllocatorTests/ValueType.cs @@ -7,6 +7,7 @@ public class ValueTypes [Parallelizable(ParallelScope.All)] public void CommonTypes() { + if (!ClrAllocator.IsSupported) Assert.Ignore("Unsupported"); var expected = Activator.CreateInstance(); var actual = FastNew.CompiledDelegate(); Assert.AreEqual(expected, actual); diff --git a/src/FastGenericNew.Tests/Units/GetFastNewTests/ExceptionsTest.cs b/src/FastGenericNew.Tests/Units/GetFastNewTests/ExceptionsTest.cs new file mode 100644 index 0000000..557001f --- /dev/null +++ b/src/FastGenericNew.Tests/Units/GetFastNewTests/ExceptionsTest.cs @@ -0,0 +1,74 @@ +namespace FastGenericNew.Tests.Units.GetFastNewTests; + +public class ExceptionsTest +{ + [Test()] + public void ExceptionInterface() + { + try + { + FastNew.GetCreateInstance(typeof(IEnumerable))(); + Assert.Fail("The expected exception is not thrown."); + } + catch (MissingMethodException e) + { + Assert.IsTrue(e.Message.StartsWith("Cannot create an instance of an interface")); + } + } + + [Test()] + public void ExceptionAbstract() + { + try + { + FastNew.GetCreateInstance(typeof(Stream))(); + Assert.Fail("The expected exception is not thrown."); + } + catch (MissingMethodException e) + { + Assert.IsTrue(e.Message.StartsWith("Cannot create an abstract class")); + } + } + + [Test()] + public void ExceptionPLString() + { + try + { + FastNew.GetCreateInstance(typeof(string))(); + Assert.Fail("The expected exception is not thrown."); + } + catch (MissingMethodException e) + { + Assert.IsTrue(e.Message.StartsWith("No match constructor found in type")); + } + } + + [Test()] + public void ExceptionNotFoundNoParameter() + { + try + { + FastNew.GetCreateInstance(typeof(DemoClassNoParamlessCtor))(); + Assert.Fail("The expected exception is not thrown."); + } + catch (MissingMethodException e) + { + Assert.IsTrue(e.Message.StartsWith("No match constructor found in type")); + } + } + + [Test()] + public void ExceptionNotFoundWithParameter() + { + try + { + FastNew.GetCreateInstance(typeof(DemoClass), typeof(DBNull))(DBNull.Value); + Assert.Fail("The expected exception is not thrown."); + } + catch (MissingMethodException e) + { + Assert.IsTrue(e.Message.StartsWith("No match constructor found in type")); + } + } +} diff --git a/src/FastGenericNew.Tests/Units/GetFastNewTests/ValueType.cs b/src/FastGenericNew.Tests/Units/GetFastNewTests/ValueType.cs new file mode 100644 index 0000000..880dfff --- /dev/null +++ b/src/FastGenericNew.Tests/Units/GetFastNewTests/ValueType.cs @@ -0,0 +1,13 @@ +namespace FastGenericNew.Tests.Units.GetFastNewTests; + +public class ValueTypes +{ + [TestCaseSourceGeneric(typeof(TestData), nameof(TestData.CommonValueTypes))] + [Parallelizable(ParallelScope.All)] + public void CommonTypes() + { + var expected = Activator.CreateInstance(); + var actual = FastNew.GetCreateInstance(typeof(T))(); + Assert.AreEqual(expected, actual); + } +}