コード例 #1
0
 public void ThrowOnEmpty_EmptyBag_ThrowCustomException()
 {
     Assert.ThrowsDelegateWithReturn func = () =>
     {
         Option <int> empty = Option <int> .Empty;
         return(empty.ThrowOnEmpty <int, NullReferenceException>());
     };
     Assert.Throws(typeof(NullReferenceException), func);
 }
コード例 #2
0
 /// <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);
     }
 }
コード例 #3
0
ファイル: AssertHelpers.cs プロジェクト: modulexcite/NToml
        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);
        }
コード例 #4
0
        public void ThrowOnEmpty_EmptyBag_ThrowException()
        {
            Assert.ThrowsDelegateWithReturn func = () => Option <int> .Empty.ThrowOnEmpty(() => new NullReferenceException());

            Assert.Throws(typeof(NullReferenceException), func);
        }
コード例 #5
0
 public static Exception ShouldThrow(this Assert.ThrowsDelegateWithReturn testCode, Type exceptionType)
 {
     return(Assert.Throws(exceptionType, testCode));
 }
コード例 #6
0
 public static T ShouldThrow <T>(this Assert.ThrowsDelegateWithReturn testCode) where T : Exception
 {
     return(Assert.Throws <T>(testCode));
 }
コード例 #7
0
 public void Constructor_ThrowsArgumentNullException(Assert.ThrowsDelegateWithReturn constructorDelegate)
 {
     Assert.Throws(typeof(ArgumentNullException), constructorDelegate);
 }
コード例 #8
0
 public void Constructor_ThrowsInvalidEnumArgumentException(Assert.ThrowsDelegateWithReturn constructorDelegate)
 {
     Assert.Throws(typeof(InvalidEnumArgumentException), constructorDelegate);
 }
コード例 #9
0
ファイル: Assertions.cs プロジェクト: paynetechnologies/xunit
 public Exception Throws(Type exceptionType, Assert.ThrowsDelegateWithReturn testCode)
 {
     return(Assert.Throws(exceptionType, testCode));
 }
コード例 #10
0
ファイル: Assertions.cs プロジェクト: paynetechnologies/xunit
 public T Throws <T>(Assert.ThrowsDelegateWithReturn testCode)
     where T : Exception
 {
     return(Assert.Throws <T>(testCode));
 }