ofCase doesn't support generic union type
wenLiangcan opened this issue · comments
尹良灿 commented
Description
Checking case of generic union type throws System.InvalidCastException
.
Repro steps
type MyCase<'T> =
| Case1 of 'T
| Case2
let intCase1 = Case1 1
intCase1 |> should be (ofCase <@ Case1 @>)
Expected behavior
The testing should be passed.
Actual behavior
The following exception is throwed.
Failed Test [49 ms]
Error Message:
System.InvalidCastException : Unable to cast object of type 'Case1[System.Int32]' to type 'MyCase`1[System.Object]'.
Stack Trace:
at lambda_method34(Closure , Object )
at FsUnit.Common.isOfCase@50.Invoke(a x)
at FsUnit.CustomConstraints.OfSameCaseConstraint.ApplyTo[TActual](TActual actual)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression)
at FsUnit.TopLevelOperators.should[a,a](FSharpFunc`2 f, a x, Object y)
Known workarounds
None.
Related information
- Windows 11
- FsUnit 4.0.6
- .NET 5
Sergey Tihon commented
尹良灿 commented
@sergey-tihon Thanks, did not know this way to specify the concrete type for a case before.