ExpectedException xunit .net 核心

ExpectedException xunit .net core

我正在为 核心 应用程序编写单元测试。我正在尝试检查我的 class 是否抛出异常。但是 ExpectedException 属性抛出编译异常:

Error CS0246 The type or namespace name 'ExpectedException' could not be found (are you missing a using directive or an assembly reference?) EventMessagesBroker.Logic.UnitTests..NETCoreApp,Version=v1.0

我的代码:

[Fact]
[ExpectedException(typeof(MessageTypeParserException))]
public void TestMethod1_Error_twoMathces()
{
    var message = "some text";
    var parser = new MessageTypeParser();
    var type = parser.GetType(message);
    Assert.Equal(MessageType.RaschetStavkiZaNalichnye, type);
}

那么,有什么正确的方法可以实现吗?

在预期异常的代码上使用 Assert.Throws

[Fact]
public void TestMethod1_Error_twoMathces()
{
    var message = "some text";
    var parser = new MessageTypeParser();
    Assert.Throws<MessageTypeParserException>(() => parser.GetType(message));
}