public void DeleteABook_ThrowsException() { //Arrange var mock2 = new Mock <IConfiguration>(); var mock = new Mock <ILibService>(); mock.Setup(a => a.DeleteABook(null, "")).Throws(new ValidationException("Test Exception", ""));; BookController controller = new BookController(mock.Object, mock2.Object); //Act ContentResult result = controller.DeleteABook("") as ContentResult; //Assert Assert.That(() => mock.Object.DeleteABook(null, ""), Throws.Exception); }
public void DeleteABook_VerifyOnce() { //Arrange var mock2 = new Mock <IConfiguration>(); string bookname = "Книга"; var mock = new Mock <ILibService>(); mock.Setup(x => x.DeleteABook(bookname, "")); BookController controller = new BookController(mock.Object, mock2.Object); //Act controller.DeleteABook(bookname); //Assert mock.Verify(x => x.DeleteABook(bookname, ""), Times.Once); }