Files
RobustToolbox/Robust.Shared.IntegrationTests/Toolshed/ToolshedTypesTest.cs
PJB3005 788e9386fd Split up test project
Robust.UnitTesting was both ALL tests for RT, and also API surface for content tests.

Tests are now split into separate projects as appropriate, and the API side has also been split off.
2025-12-16 01:36:53 +01:00

51 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Robust.UnitTesting.Shared.Toolshed;
[TestFixture]
internal sealed partial class ToolshedTypesTest : ToolshedTest
{
// Assert that T -> IEnumerable<T> holds.
[Test]
public void EnumerableAutoCast()
{
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(IEnumerable<int>)));
var l = Expression
.Lambda<Func<IEnumerable<int>>>(
Toolshed.GetTransformer(typeof(int), typeof(IEnumerable<int>), Expression.Constant(1))
)
.Compile();
Assert.That(l(), Is.Not.Empty);
}
// Assert that T -> IEnumerable<T'> where T: T' holds.
[Test]
public void EnumerableSubtypeAutocast()
{
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(IEnumerable<IComparable>)));
var l = Expression
.Lambda<Func<IEnumerable<IComparable>>>(
Toolshed.GetTransformer(typeof(int), typeof(IEnumerable<IComparable>), Expression.Constant(1))
)
.Compile();
Assert.That(l(), Is.Not.Empty);
}
// Assert that T -> object.
[Test]
public void CastToObject()
{
Assert.That(Toolshed.IsTransformableTo(typeof(int), typeof(object)));
var l = Expression
.Lambda<Func<object>>(
Toolshed.GetTransformer(typeof(int), typeof(object), Expression.Constant(1))
)
.Compile();
Assert.That(l(), Is.TypeOf<int>());
}
}