user1765862
user1765862

Reputation: 14195

expecting returned exception from mock object method

Inside my test I'm having mock object which should test expected NotImplementedException thrown from MyService.Create method

I'm struggle in this part

var hotelServiceMock = new Mock<HotelService>();
    hotelServiceMock.Setup(x=>x.Create(It.IsAny<HotelToCreateDTO>(), true))
                    .Throws(() => NotImplementedException());

I was think to use Returns instead of thrown (seen somewhere on net for some expected value, not exception) but on intellisense I'm getting only enter image description here

Upvotes: 0

Views: 66

Answers (1)

Ron Beyer
Ron Beyer

Reputation: 11273

I haven't used Moq (I should) but from the Intellisense it looks like it should be:

hotelServiceMock.Setup(x=>x.Create(It.IsAny<HotelToCreateDTO>(), true)).Throws<NotImplementedException>()

Upvotes: 1

Related Questions