-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from zacharylayne/unit-tests
First Commit of ConstTypeArgs.Core Tests
- Loading branch information
Showing
3 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.TestTypes.cs
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,75 @@ | ||
namespace ConstTypeArgs.Core.Tests; | ||
|
||
public partial class ConstTypeArgInterfaceTests | ||
{ | ||
public readonly struct IntConstTypeArg : IConstTypeArg<int, IntConstTypeArg> | ||
{ public static int Value => 42; } | ||
|
||
public readonly struct UintConstTypeArg : IConstTypeArg<uint, UintConstTypeArg> | ||
{ public static uint Value => 42u; } | ||
|
||
public readonly struct FloatConstTypeArg : IConstTypeArg<float, FloatConstTypeArg> | ||
{ public static float Value => 42.0f; } | ||
|
||
public readonly struct StringArg : IConstTypeArg<string, StringArg> | ||
{ public static string Value => "Hello, World!"; } | ||
|
||
public readonly struct IntArrayArg : K_Array<int> | ||
{ public static int[] Value => [1, 2, 3]; } | ||
|
||
public readonly struct StringArrayArg : K_Array<string> | ||
{ public static string[] Value => ["A", "B", "C"]; } | ||
|
||
public readonly struct StringClassArg : K_Class<string> | ||
{ public static string Value => "Class String!"; } | ||
|
||
public readonly struct ObjectClassArg : K_Class<object> | ||
{ public static object Value => new(); } | ||
|
||
public readonly struct ActionDelegateArg : K_Delegate<Action> | ||
{ public static Action Value => () => Console.WriteLine("Action delegate executed!"); } | ||
|
||
public readonly struct FuncDelegateArg : K_Delegate<Func<int>> | ||
{ public static Func<int> Value => () => 42; } | ||
|
||
public enum TestEnum { A, B, C } | ||
|
||
public readonly struct EnumArg : K_Enum<TestEnum> | ||
{ public static TestEnum Value => TestEnum.B; } | ||
|
||
public readonly struct MulticastDelegateArg : K_MulticastDelegate<Action> | ||
{ public static Action Value => () => Console.WriteLine("Multicast delegate executed!"); } | ||
|
||
public readonly struct IntNumberArg : K_Number<int> | ||
{ public static int Value => 10; } | ||
|
||
public readonly struct FloatNumberArg : K_Number<float> | ||
{ public static float Value => 3.14f; } | ||
|
||
public readonly struct StringReadOnlyMemoryArg : K_ReadOnlyMemory<string> | ||
{ public static ReadOnlyMemory<string> Value => new[] { "Hello", "World" }; } | ||
|
||
public readonly struct StringReadOnlyMemoryArrayArg : K_ReadOnlyMemoryArray<string> | ||
{ | ||
public static ReadOnlyMemory<string>[][] Value => | ||
[ | ||
[ new ReadOnlyMemory<string>(["Hello", "World"]) ], | ||
[ new ReadOnlyMemory<string>(["World", "Hello"]) ] | ||
]; | ||
} | ||
|
||
public readonly struct StringReadOnlyMemoryTArrayArg : K_ReadOnlyMemoryT_Array<string> | ||
{ public static ReadOnlyMemory<string[]> Value => new[] { new[] { "Hello", "World" } }; } | ||
|
||
public readonly struct PointStructArg : K_Struct<(int X, int Y)> | ||
{ public static (int X, int Y) Value => (10, 20); } | ||
|
||
public readonly struct RectangleStructArg : K_Struct<(int Width, int Height)> | ||
{ public static (int Width, int Height) Value => (100, 200); } | ||
|
||
public readonly struct IntUnmanagedArg : K_Unmanaged<int> | ||
{ public static int Value => 100; } | ||
|
||
public readonly struct FloatUnmanagedArg : K_Unmanaged<float> | ||
{ public static float Value => 1.23f; } | ||
} |
55 changes: 55 additions & 0 deletions
55
Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.cs
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,55 @@ | ||
using FluentAssertions; | ||
|
||
namespace ConstTypeArgs.Core.Tests; | ||
|
||
public partial class ConstTypeArgInterfaceTests | ||
{ | ||
[Fact] | ||
public void IConstTypeArgT_ShouldImplement_IConstTypeArg() | ||
{ | ||
// Arrange | ||
var type = typeof(IConstTypeArg<int>); | ||
|
||
// Act & Assert | ||
type.Should().Implement<IConstTypeArg>(); | ||
} | ||
|
||
[Fact] | ||
public void IntConstTypeArg_ShouldImplement_IConstTypeArgT() | ||
{ | ||
// Arrange | ||
var type = typeof(IntConstTypeArg); | ||
|
||
// Act | ||
var implementsInterface = typeof(IConstTypeArg<int>).IsAssignableFrom(type); | ||
|
||
// Assert | ||
implementsInterface.Should().BeTrue("IntConstTypeArg should implement IConstTypeArg<int>"); | ||
} | ||
|
||
[Fact] | ||
public void FakeConstTypeArg_ShouldImplement_IConstTypeArgT() | ||
{ | ||
// Arrange | ||
var type = typeof(IntConstTypeArg); | ||
|
||
// Act | ||
var implementsInterface = typeof(IConstTypeArg<int>).IsAssignableFrom(type); | ||
|
||
// Assert | ||
implementsInterface.Should().BeTrue("FakeConstTypeArg should implement IConstTypeArg<int>"); | ||
} | ||
|
||
[Fact] | ||
public void IntConstTypeArg_Value_ShouldReturnExpectedValue() | ||
{ | ||
// Arrange | ||
const int expectedValue = 42; | ||
|
||
// Act | ||
var value = IntConstTypeArg.Value; | ||
|
||
// Assert | ||
value.Should().Be(expectedValue, "IntConstTypeArg.Value should return 42"); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Tests/ConstTypeArgs.Core.Tests/ConstTypeArgs.Core.Tests.csproj
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |