Exceptions
var mock = new Mock<IService>();
mock.Setup(p => p.DoSomething())
.Callback(() => throw new Exception());mock.Setup(p => p.DoSomething())
.Throws(new Exception("My custom exception"));
mock.Setup(p => p.DoSomethingAsync())
.ThrowsAsync(new Exception("My custom exception"));mock.Setup(p => p.DoSomething())
.Throws<Exception>();mock.SetupSequence(p => p.GetSomeValue())
.Returns(1)
.Throws<Exception>();
mock.SetupSequence(p => p.GetSomeValueAsync())
.ReturnsAsync(1)
.ThrowsAsync(new Exception());Throwing exceptions aware of incoming parameters
Last updated
Was this helpful?