Exemple #1
0
 private void LogFailureAccordingToBehavior(AssertionFailure failure)
 {
     if ((assertionFailureBehavior & AssertionFailureBehavior.Log) != 0)
     {
         LogFailure(failure);
     }
 }
Exemple #2
0
 private void SaveFailureAccordingToBehavior(AssertionFailure failure)
 {
     if ((assertionFailureBehavior & AssertionFailureBehavior.Discard) == 0)
     {
         AddSavedFailure(failure);
     }
 }
Exemple #3
0
 private void ThrowFailureAccordingToBehavior(AssertionFailure failure)
 {
     if ((assertionFailureBehavior & AssertionFailureBehavior.Throw) != 0)
     {
         throw new AssertionFailureException(failure, true);
     }
 }
Exemple #4
0
        /// <summary>
        /// Submits an assertion failure.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The behavior of this method depends upon the current setting of
        /// <see cref="AssertionFailureBehavior" />.  Typically this method will
        /// throw an <see cref="AssertionFailureException" /> but it might do
        /// other things.  Do not assume that it will throw an exception!
        /// </para>
        /// </remarks>
        /// <param name="failure">The assertion failure.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="failure"/>
        /// is null.</exception>
        public void SubmitFailure(AssertionFailure failure)
        {
            if (failure == null)
            {
                throw new ArgumentNullException("failure");
            }

            scope.SubmitFailure(failure);
        }
Exemple #5
0
            private void SubmitFailure(AssertionFailure failure, bool noThrow)
            {
                SaveFailureAccordingToBehavior(failure);
                LogFailureAccordingToBehavior(failure);

                if (!noThrow)
                {
                    ThrowFailureAccordingToBehavior(failure);
                }
            }
        /// <summary>
        /// Creates an exception for a given assertion failure.
        /// </summary>
        /// <param name="failure">The assertion failure.</param>
        /// <param name="silent">True if the assertion failure exception should not be logged because
        /// the information it contains has already been conveyed to the user.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="failure"/> is null.</exception>
        public AssertionFailureException(AssertionFailure failure, bool silent)
        {
            if (failure == null)
                throw new ArgumentNullException("failure");

            this.failure = failure;

            if (! silent)
                HasNonDefaultMessage = true;
        }
Exemple #7
0
 private void AddSavedFailure(AssertionFailure failure)
 {
     lock (this)
     {
         if (savedFailures == null)
         {
             savedFailures = new List <AssertionFailure>();
         }
         savedFailures.Add(failure);
     }
 }
        /// <summary>
        /// Adds a nested assertion failure that contributed to the composite assertion failure
        /// described by this instance.
        /// </summary>
        /// <param name="innerFailure">The inner assertion failure to add.</param>
        /// <returns>The builder, to allow for fluent method chaining.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="innerFailure"/> is null.</exception>
        public AssertionFailureBuilder AddInnerFailure(AssertionFailure innerFailure)
        {
            if (innerFailure == null)
            {
                throw new ArgumentNullException("innerFailure");
            }

            if (innerFailures == null)
            {
                innerFailures = new List <AssertionFailure>();
            }
            innerFailures.Add(innerFailure);
            return(this);
        }
        /// <summary>
        /// Creates an exception for a given assertion failure.
        /// </summary>
        /// <param name="failure">The assertion failure.</param>
        /// <param name="silent">True if the assertion failure exception should not be logged because
        /// the information it contains has already been conveyed to the user.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="failure"/> is null.</exception>
        public AssertionFailureException(AssertionFailure failure, bool silent)
        {
            if (failure == null)
            {
                throw new ArgumentNullException("failure");
            }

            this.failure = failure;

            if (!silent)
            {
                HasNonDefaultMessage = true;
            }
        }
Exemple #10
0
 /// <summary>
 /// Submits a failure if the assertion failure object is non-null.
 /// </summary>
 /// <param name="failure">Failure to be submited, or null if none.</param>
 public static void Fail(AssertionFailure failure)
 {
     if (failure != null)
     {
         AssertionContext context = AssertionContext.CurrentContext;
         if (context != null)
         {
             context.SubmitFailure(failure);
         }
         else
         {
             throw new AssertionFailureException(failure, false);
         }
     }
 }
        private void AddLabeledValueImpl(AssertionFailure.LabeledValue labeledValue)
        {
            if (labeledValues == null)
                labeledValues = new List<AssertionFailure.LabeledValue>();

            labeledValues.Add(labeledValue);
        }
 /// <summary>
 /// Adds a labeled value.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The order in which this method is called determines the order in which this
 /// value will appear relative to other labeled values.
 /// </para>
 /// </remarks>
 /// <param name="labeledValue">The labeled value.</param>
 /// <returns>The builder, to allow for fluent method chaining.</returns>
 public AssertionFailureBuilder AddLabeledValue(AssertionFailure.LabeledValue labeledValue)
 {
     AddLabeledValueImpl(labeledValue);
     return this;
 }
        /// <summary>
        /// Adds a nested assertion failure that contributed to the composite assertion failure
        /// described by this instance.
        /// </summary>
        /// <param name="innerFailure">The inner assertion failure to add.</param>
        /// <returns>The builder, to allow for fluent method chaining.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="innerFailure"/> is null.</exception>
        public AssertionFailureBuilder AddInnerFailure(AssertionFailure innerFailure)
        {
            if (innerFailure == null)
                throw new ArgumentNullException("innerFailure");

            if (innerFailures == null)
                innerFailures = new List<AssertionFailure>();
            innerFailures.Add(innerFailure);
            return this;
        }
 /// <summary>
 /// Submits a failure if the assertion failure object is non-null.
 /// </summary>
 /// <param name="failure">Failure to be submited, or null if none.</param>
 public static void Fail(AssertionFailure failure)
 {
     if (failure != null)
     {
         AssertionContext context = AssertionContext.CurrentContext;
         if (context != null)
         {
             context.SubmitFailure(failure);
         }
         else
         {
             throw new AssertionFailureException(failure, false);
         }
     }
 }
        /// <summary>
        /// Submits an assertion failure.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The behavior of this method depends upon the current setting of
        /// <see cref="AssertionFailureBehavior" />.  Typically this method will
        /// throw an <see cref="AssertionFailureException" /> but it might do
        /// other things.  Do not assume that it will throw an exception!
        /// </para>
        /// </remarks>
        /// <param name="failure">The assertion failure.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="failure"/>
        /// is null.</exception>
        public void SubmitFailure(AssertionFailure failure)
        {
            if (failure == null)
                throw new ArgumentNullException("failure");

            scope.SubmitFailure(failure);
        }
 private void SaveFailureAccordingToBehavior(AssertionFailure failure)
 {
     if ((assertionFailureBehavior & AssertionFailureBehavior.Discard) == 0)
         AddSavedFailure(failure);
 }
 public void SubmitFailure(AssertionFailure failure)
 {
     SubmitFailure(failure, false);
 }
 private void AddSavedFailure(AssertionFailure failure)
 {
     lock (this)
     {
         if (savedFailures == null)
             savedFailures = new List<AssertionFailure>();
         savedFailures.Add(failure);
     }
 }
 /// <summary>
 /// Creates an exception from serialization info.
 /// </summary>
 /// <param name="info">The serialization info.</param>
 /// <param name="context">The streaming context.</param>
 protected AssertionFailureException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     failure = (AssertionFailure)info.GetValue(AssertionFailureKey, typeof(AssertionFailure));
 }
 private void LogFailure(AssertionFailure failure)
 {
     failure.WriteTo(context.testContext.LogWriter.Failures);
 }
 private void ThrowFailureAccordingToBehavior(AssertionFailure failure)
 {
     if ((assertionFailureBehavior & AssertionFailureBehavior.Throw) != 0)
         throw new AssertionFailureException(failure, true);
 }
            private void SubmitFailure(AssertionFailure failure, bool noThrow)
            {
                SaveFailureAccordingToBehavior(failure);
                LogFailureAccordingToBehavior(failure);

                if (! noThrow)
                    ThrowFailureAccordingToBehavior(failure);
            }
 private static void AssertCommonFailureLabeledValues(AssertionFailure failure, string target, string attribute)
 {
     Assert.AreEqual("Target Object", failure.LabeledValues[0].Label);
     Assert.AreEqual("MbUnit.Tests.Framework.AssertTest_HasAttribute." + target, failure.LabeledValues[0].FormattedValue.ToString());
     Assert.AreEqual("Attribute Type", failure.LabeledValues[1].Label);
     Assert.AreEqual("MbUnit.Tests.Framework.AssertTest_HasAttribute." + attribute, failure.LabeledValues[1].FormattedValue.ToString());
 }
Exemple #24
0
 private void LogFailure(AssertionFailure failure)
 {
     failure.WriteTo(context.testContext.LogWriter.Failures);
 }
 private void LogFailureAccordingToBehavior(AssertionFailure failure)
 {
     if ((assertionFailureBehavior & AssertionFailureBehavior.Log) != 0)
         LogFailure(failure);
 }
 /// <summary>
 /// Creates an exception from serialization info.
 /// </summary>
 /// <param name="info">The serialization info.</param>
 /// <param name="context">The streaming context.</param>
 protected AssertionFailureException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     failure = (AssertionFailure) info.GetValue(AssertionFailureKey, typeof(AssertionFailure));
 }
Exemple #27
0
 public void SubmitFailure(AssertionFailure failure)
 {
     SubmitFailure(failure, false);
 }