コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the ExpectedExceptionTypeMessageVerifier class.
        /// </summary>
        /// <param name="innerExpectedException">The expected inner exception.</param>
        /// <param name="messagePattern">A string holding a regex pattern to match against exception messages.</param>
        public ExpectedExceptionTypeMessageVerifier(ExpectedExceptionVerifier innerExpectedException, string messagePattern)
            : base(innerExpectedException)
        {
            if (messagePattern == null)
            {
                messagePattern = string.Empty;
            }

            this.MessageRegex = new Regex(stringFormatPattern.Replace(messagePattern, ".*"));
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the ExpectedExceptions class.
        /// </summary>
        /// <param name="expectedException">The expected exception.</param>
        /// <param name="ignoredExceptions">The ignored exceptions.</param>
        public ExpectedExceptions(ExpectedExceptionVerifier expectedException, params ExpectedExceptionVerifier[] ignoredExceptions)
            : base(null)
        {
            ExceptionUtilities.Assert(expectedException != null || ignoredExceptions != null, "There must be at least one ExpectedException.");

            if (ignoredExceptions == null)
            {
                ignoredExceptions = new ExpectedExceptionVerifier[] { };
            }

            this.ExpectedException = expectedException;
            this.IgnoredExceptions = new List <ExpectedExceptionVerifier>(ignoredExceptions);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the ExpectedExceptions class.
        /// </summary>
        /// <param name="expectedException">The expected exception.</param>
        /// <param name="ignoredExceptions">The ignored exceptions.</param>
        public ExpectedExceptions(ExpectedExceptionVerifier expectedException, params ExpectedExceptionVerifier[] ignoredExceptions)
            : base(null)
        {
            ExceptionUtilities.Assert(expectedException != null || ignoredExceptions != null, "There must be at least one ExpectedException.");

            if (ignoredExceptions == null)
            {
                ignoredExceptions = new ExpectedExceptionVerifier[] { };
            }

            this.ExpectedException = expectedException;
            this.IgnoredExceptions = new List<ExpectedExceptionVerifier>(ignoredExceptions);
        }
コード例 #4
0
        /// <summary>
        /// Verifies whether the actual exception matches the expected exception.
        /// </summary>
        /// <param name="expectedException">The expected exception.</param>
        /// <param name="exception">The actual exception.</param>
        /// <returns>Whether the <paramref name="actualException"/> matches the <paramref name="expectedException"/>.</returns>
        internal static bool Verify(ExpectedExceptionVerifier expectedException, Exception exception)
        {
            if (!expectedException.VerifyException(exception))
            {
                return(false);
            }

            if (expectedException.InnerExpectedException != null)
            {
                return(Verify(expectedException.InnerExpectedException, exception.InnerException));
            }

            return(true);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the ExpectedExceptionVerifier class.
 /// </summary>
 /// <param name="innerExpectedException">The expected inner exception.</param>
 protected ExpectedExceptionVerifier(ExpectedExceptionVerifier innerExpectedException)
 {
     this.InnerExpectedException = innerExpectedException;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the ExpectedExceptions class.
 /// </summary>
 /// <param name="expectedException">The expected exception.</param>
 public ExpectedExceptions(ExpectedExceptionVerifier expectedException)
     : this(expectedException, null)
 {
 }
コード例 #7
0
        /// <summary>
        /// Verifies whether the actual exception matches the expected exception.
        /// </summary>
        /// <param name="expectedException">The expected exception.</param>
        /// <param name="exception">The actual exception.</param>
        /// <returns>Whether the <paramref name="actualException"/> matches the <paramref name="expectedException"/>.</returns>
        internal static bool Verify(ExpectedExceptionVerifier expectedException, Exception exception)
        {
            if (!expectedException.VerifyException(exception))
            {
                return false;
            }

            if (expectedException.InnerExpectedException != null)
            {
                return Verify(expectedException.InnerExpectedException, exception.InnerException);
            }

            return true;
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the ExpectedExceptions class.
 /// </summary>
 /// <param name="expectedException">The expected exception.</param>
 public ExpectedExceptions(ExpectedExceptionVerifier expectedException)
     : this(expectedException, null)
 {
 }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of the ExpectedExceptionVerifier class.
 /// </summary>
 /// <param name="innerExpectedException">The expected inner exception.</param>
 protected ExpectedExceptionVerifier(ExpectedExceptionVerifier innerExpectedException) 
 {
     this.InnerExpectedException = innerExpectedException;
 }