Exemplo n.º 1
0
        public void FailureExcludesOptionalMessageWhenOmitted()
        {
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => true, false, null);

            Assert.IsNotNull(failure);
            Assert.IsNull(failure.Message);
        }
 public void Accept(AssertionFailure failure)
 {
     _inner.Accept(new AssertionFailure(
                       failure,
                       "{0}", new object[] { Render(failure) }
                       ));
 }
Exemplo n.º 3
0
        public void FailureIncludesStackTrace()
        {
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => true, false, null);

            Assert.IsNotNull(failure);
            Assert.Contains(failure.StackTrace.ToString(), "FailureIncludesStackTrace");
        }
Exemplo n.º 4
0
        public void FailureIncludesOptionalMessageWhenProvided()
        {
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => true, false, "Expected {0}", "true");

            Assert.IsNotNull(failure);
            Assert.AreEqual("Expected true", failure.Message);
        }
Exemplo n.º 5
0
 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());
 }
 public void Accept(AssertionFailure failure)
 {
     foreach (var tool in _tools)
     {
         tool.Accept(failure);
     }
 }
        public void AssertionFailure()
        {
            var ex = new AssertionFailure();

            Assert.That(
                () => SerializationHelper.Deserialize(SerializationHelper.Serialize(ex)),
                Throws.Nothing);
        }
Exemplo n.º 8
0
        private void ActiveRunner_OnTestComplete(Test test, AssertionFailure failure)
        {
            var e2etest = test.UserData as E2ETest;

            e2etest.IsCompleted = true;
            completionCount++;
            e2etest.ErrorMessage = failure?.ToString();
            NotifyListeners(test, failure);
        }
 public void Accept(AssertionFailure failure)
 {
     Trace.Write("Assertion Failure - ");
     Trace.WriteLine(failure.Message);
     if (failure.CombinedException != null)
     {
         Trace.WriteLine(failure.CombinedException.ToString());
     }
 }
Exemplo n.º 10
0
        public void FailureDescribesExpectedResultAndConditionAndParameters(bool expectedResult)
        {
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => !expectedResult, expectedResult, null);

            Assert.IsNotNull(failure);
            Assert.AreEqual(String.Format("Expected the condition to evaluate to {0}.", expectedResult.ToString().ToLowerInvariant()), failure.Description);
            Assert.AreElementsEqual(new[] {
                new AssertionFailure.LabeledValue("Condition", "! expectedResult"),
                new AssertionFailure.LabeledValue("expectedResult", Formatter.Instance.Format(expectedResult)),
            }, failure.LabeledValues);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Verifies that a particular condition holds true.
        /// </summary>
        /// <remarks>
        /// <para>
        /// If the condition evaluates to false, the assertion failure message will
        /// describe in detail the intermediate value of relevant sub-expressions within
        /// the condition.  Consequently the assertion failure will include more diagnostic
        /// information than if <see cref="Assert.IsTrue(bool, string, object[])" /> were used instead.
        /// </para>
        /// </remarks>
        /// <param name="condition">The conditional expression to evaluate.</param>
        /// <param name="messageFormat">The custom assertion message format, or null if none.</param>
        /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="condition"/> is null.</exception>
        /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception>
        public static void That(Expression <System.Func <bool> > condition, string messageFormat, params object[] messageArgs)
        {
            if (condition == null)
            {
                throw new ArgumentNullException("condition");
            }

            AssertionFailure failure = AssertionConditionEvaluator.Eval(condition, true, messageFormat, messageArgs);

            AssertionHelper.Fail(failure);
        }
Exemplo n.º 12
0
        public void FailureMessageIgnoresValueOfTopLevelNotExpression()
        {
            int x = 42;
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => !(x.ToString() == "42"), true, null);

            Assert.IsNotNull(failure);

            Assert.AreElementsEqual(new[] {
                new AssertionFailure.LabeledValue("Condition", "! (x.ToString() == \"42\")"),
                new AssertionFailure.LabeledValue("x.ToString()", "\"42\""),
                new AssertionFailure.LabeledValue("x", "42"),
            }, failure.LabeledValues);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Notifies all listeners of a test update
        /// </summary>
        /// <param name="test">The test to notify for, or null to indicate that all tests have completed</param>
        /// <param name="failure">The failure (or null if the test succeeded)</param>
        private static void NotifyListeners(Test test, AssertionFailure failure)
        {
            List <TaskCompletionSource <Tuple <Test, AssertionFailure> > > list = null;

            lock (listeners)
            {
                list = listeners.ToList();
                listeners.Clear();
            }
            foreach (var listener in list)
            {
                listener.SetResult(new Tuple <Test, AssertionFailure>(test, failure));
            }
        }
Exemplo n.º 14
0
        public void FailureDescribesException()
        {
            object           x       = null;
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => x.Equals(null), true, null);

            Assert.IsNotNull(failure);
            Assert.AreEqual("Expected the condition to evaluate to true but it threw an exception.", failure.Description);
            Assert.AreElementsEqual(new[] {
                new AssertionFailure.LabeledValue("Condition", "x.Equals(null)"),
                new AssertionFailure.LabeledValue("x", "null"),
            }, failure.LabeledValues);
            Assert.Count(1, failure.Exceptions);
            Assert.Contains(failure.Exceptions[0].ToString(), "NullReferenceException");
        }
Exemplo n.º 15
0
        public void FailureMessageIgnoresRepeatedOccurrencesOfAVariable()
        {
            int x = 42;
            AssertionFailure failure = AssertionConditionEvaluator.Eval(() => x * 2 == x + 1, true, null);

            Assert.IsNotNull(failure);

            Assert.AreElementsEqual(new[] {
                new AssertionFailure.LabeledValue("Condition", "x * 2 == x + 1"),
                new AssertionFailure.LabeledValue("x * 2", "84"),
                new AssertionFailure.LabeledValue("x + 1", "43"),
                new AssertionFailure.LabeledValue("x", "42")
            }, failure.LabeledValues);
        }
        public void TruncatesDiffContextWhenTooLong()
        {
            string expectedValue = "z" + new string('x', AssertionFailure.MaxFormattedValueLength) + "z";
            string actualValue   = "Z" + new string('x', AssertionFailure.MaxFormattedValueLength) + "Z";

            AssertionFailureBuilder builder = new AssertionFailureBuilder("description");

            builder.AddRawExpectedAndActualValuesWithDiffs(expectedValue, actualValue);
            AssertionFailure failure = builder.ToAssertionFailure();

            TestLog.Write(failure);

            int split = AssertionFailureBuilder.CompressedDiffContextLength / 2;

            Assert.AreEqual("\"z" + new string('x', split) + "..." + new string('x', split) + "z\"",
                            failure.LabeledValues[0].FormattedValue.ToString());
            Assert.AreEqual("\"Z" + new string('x', split) + "..." + new string('x', split) + "Z\"",
                            failure.LabeledValues[1].FormattedValue.ToString());
        }
Exemplo n.º 17
0
        public void Accept(AssertionSuccess assertionSuccess)
        {
            var inverted = new AssertionFailure(assertionSuccess);

            _inner.Accept(inverted);
        }
Exemplo n.º 18
0
        public void Accept(AssertionFailure failure)
        {
            var inverted = new AssertionSuccess(failure);

            _inner.Accept(inverted);
        }
Exemplo n.º 19
0
 public void Accept(AssertionFailure failure)
 {
 }
        public void Accept(AssertionFailure failure)
        {
            var next = Dequeue(failure);

            next.Check(_inner, failure);
        }
Exemplo n.º 21
0
 public void Accept(AssertionFailure failure)
 {
     _inner.Accept(failure);
 }
Exemplo n.º 22
0
 public void Accept(AssertionFailure failure)
 {
     throw new Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException(failure.Message, failure.CombinedException);
 }
 public void Accept(AssertionFailure failure)
 {
     _memory.Add(failure);
     failureCount++;
 }