public void ThrowOnEmpty_EmptyBag_ThrowCustomException() { Assert.ThrowsDelegateWithReturn func = () => { Option <int> empty = Option <int> .Empty; return(empty.ThrowOnEmpty <int, NullReferenceException>()); }; Assert.Throws(typeof(NullReferenceException), func); }
/// <summary> /// Records any exception which is thrown by the given code that has /// a return value. Generally used for testing property accessors. /// </summary> /// <param name="code">The code which may thrown an exception.</param> /// <returns>Returns the exception that was thrown by the code; null, otherwise.</returns> public static Exception Exception(Assert.ThrowsDelegateWithReturn code) { try { code(); return(null); } catch (Exception ex) { return(ex); } }
public static T ThrowsDerived <T>(Assert.ThrowsDelegateWithReturn testCode) where T : Exception { Exception exception = null; try { testCode(); } catch (Exception e) { exception = e; } if (!(exception is T)) { throw new AssertException(String.Format("Expected exception of type {0} (or subclass), but got {1}", typeof(T), exception.GetType())); } return((T)exception); }
public void ThrowOnEmpty_EmptyBag_ThrowException() { Assert.ThrowsDelegateWithReturn func = () => Option <int> .Empty.ThrowOnEmpty(() => new NullReferenceException()); Assert.Throws(typeof(NullReferenceException), func); }
public static Exception ShouldThrow(this Assert.ThrowsDelegateWithReturn testCode, Type exceptionType) { return(Assert.Throws(exceptionType, testCode)); }
public static T ShouldThrow <T>(this Assert.ThrowsDelegateWithReturn testCode) where T : Exception { return(Assert.Throws <T>(testCode)); }
public void Constructor_ThrowsArgumentNullException(Assert.ThrowsDelegateWithReturn constructorDelegate) { Assert.Throws(typeof(ArgumentNullException), constructorDelegate); }
public void Constructor_ThrowsInvalidEnumArgumentException(Assert.ThrowsDelegateWithReturn constructorDelegate) { Assert.Throws(typeof(InvalidEnumArgumentException), constructorDelegate); }
public Exception Throws(Type exceptionType, Assert.ThrowsDelegateWithReturn testCode) { return(Assert.Throws(exceptionType, testCode)); }
public T Throws <T>(Assert.ThrowsDelegateWithReturn testCode) where T : Exception { return(Assert.Throws <T>(testCode)); }