public void ThrowsOfT_GivenActionThrowingNotT_ThrowsException() { try { // act AssertExtension.Throws <ArgumentException>(() => { throw new NotImplementedException(); }); } catch (AssertFailedException ex) { // assert var expectedMessage = "AssertExtension.Throws<T> failed. Expected:<ArgumentException>. Actual:<NotImplementedException>."; Assert.AreEqual(expectedMessage, ex.Message); throw; } }
public void ThrowsOfT_GivenMessageAndActionNotThrowingAtAll_ThrowsException() { // arrange var obj = new object(); try { // act AssertExtension.Throws <Exception>(() => { obj = null; }, "some mess{0}.", "age"); } catch (AssertFailedException ex) { // assert var expectedMessage = "AssertExtension.Throws<T> failed. No exception thrown. some message."; Assert.AreEqual(expectedMessage, ex.Message); throw; } }
public void ThrowsOfT_GivenActionThrowingT_Passes() { // act / assert AssertExtension.Throws <ArgumentException>(() => { throw new ArgumentException("somearg"); }); }
public void ThrowsOfT_GivenNullAction_ThrowsException() { // act / assert AssertExtension.Throws <NotImplementedException>(null); }