Assert an Exception using XUnit

前端 未结 3 1308
天涯浪人
天涯浪人 2020-12-08 00:03

I am a newbie to XUnit and Moq. I have a method which takes string as an argument.How to handle an exception using XUnit.

[Fact]
public void ProfileRepositor         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 00:23

    You could consider something like this if you want to stick to AAA:

    // Act 
    Task act() => handler.Handle(request);
    
    // Assert
    await Assert.ThrowsAsync(act);
    

提交回复
热议问题