public void DeleteAnAuthor_ThrowsException() { //Arrange var mock2 = new Mock <IConfiguration>(); var mock = new Mock <ILibService>(); mock.Setup(a => a.DeleteAnAuthor(null, "")).Throws(new ValidationException("Test Exception", "")); AuthorController controller = new AuthorController(mock.Object, mock2.Object); //Act ContentResult result = controller.DeleteAnAuthor("") as ContentResult; //Assert Assert.That(() => mock.Object.DeleteAnAuthor(null, ""), Throws.Exception); }
public void DeleteAnAuthor_VerifyOnce() { //Arrange var mock2 = new Mock <IConfiguration>(); string authorname = "Автор"; var mock = new Mock <ILibService>(); mock.Setup(x => x.DeleteAnAuthor(authorname, "")); AuthorController controller = new AuthorController(mock.Object, mock2.Object); //Act controller.DeleteAnAuthor(authorname); //Assert mock.Verify(x => x.DeleteAnAuthor(authorname, ""), Times.Once); }