你好,我不能用约束测试对象类型,但经典断言仍然有效
enum TestEnum : ushort
{
one = 0x01,
two = 0x02
}
// test is okay
Assert.AreEqual(typeof(ushort), typeof(TestEnum).GetEnumUnderlyingType());
// test failed
//
// Expected: <System.Uint16>
// But was: <System.RuntimeType>
//
Assert.That(typeof(TestEnum).GetEnumUnderlyingType(), Is.TypeOf<ushort>());
请问什么平台和什么nunit版本?
嗨@TobiasSekan。 我会说这是意料之中的。 在经典断言中,您只是在比较两种类型。 约束“_tests 实际值是作为参数提供的类型还是派生类型。_”并且值typeof(TestEnum).GetEnumUnderlyingType()
是System.RuntimeType
。
类似的以下内容也会失败(具有相同类型的消息)
Assert.That(typeof(string), Is.TypeOf<string>());
然而
Assert.That("", Is.TypeOf<string>());
会工作。 您始终可以将约束重新表述为Assert.That(typeof(TestEnum).GetEnumUnderlyingType(), Is.EqualTo(typeof(ushort)));
好收获@mikkelbu。 我将把它作为not a bug
关闭。 @TobiasSekan我可以看到混乱,但实际上你的第一个参数是TypeOf<Type>
而不是ushort
。
好的,谢谢你的信息
最有用的评论
嗨@TobiasSekan。 我会说这是意料之中的。 在经典断言中,您只是在比较两种类型。 约束“_tests 实际值是作为参数提供的类型还是派生类型。_”并且值
typeof(TestEnum).GetEnumUnderlyingType()
是System.RuntimeType
。类似的以下内容也会失败(具有相同类型的消息)
然而
会工作。 您始终可以将约束重新表述为
Assert.That(typeof(TestEnum).GetEnumUnderlyingType(), Is.EqualTo(typeof(ushort)));