Example #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, ".*"));
        }
Example #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);
        }
Example #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);
        }
        /// <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);
        }
 /// <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;
 }
Example #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)
 {
 }
        /// <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;
        }
Example #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)
 {
 }
 /// <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;
 }