Example #1
0
        /// <summary>
        /// Reports an assertion failure.
        /// </summary>
        /// <param name="testContext"></param>
        /// <param name="testInfoData"></param>
        /// <param name="testStepResult"></param>
        public void Run(ITestContext testContext, TestInfoData testInfoData, TestStepResult testStepResult)
        {
            if (testStepResult.TestOutcome == TestOutcome.Failed)
            {
                MbUnitCppAssertionFailure failure = testStepResult.Failure;
                var builder = new AssertionFailureBuilder(failure.Description);

                if (failure.HasExpectedValue && failure.HasActualValue && failure.Diffing)
                {
                    builder.AddRawExpectedAndActualValuesWithDiffs(failure.ExpectedValue, failure.ActualValue);
                }
                else if (failure.HasUnexpectedValue && failure.HasActualValue && failure.Diffing)
                {
                    builder.AddRawLabeledValuesWithDiffs("Unexpected Value", failure.UnexpectedValue, "Actual Value", failure.ActualValue);
                }
                else
                {
                    if (failure.HasExpectedValue)
                    {
                        builder.AddRawExpectedValue(failure.ExpectedValue);
                    }

                    if (failure.HasActualValue)
                    {
                        builder.AddRawActualValue(failure.ActualValue);
                    }

                    if (failure.HasUnexpectedValue)
                    {
                        builder.AddRawLabeledValue("Unexpected Value", failure.UnexpectedValue);
                    }
                }

                foreach (var extra in failure.ExtraLabeledValues)
                {
                    builder.AddRawLabeledValue(extra.First, extra.Second);
                }

                if (failure.Message.Length > 0)
                {
                    builder.SetMessage(failure.Message);
                }

                builder.SetStackTrace(testInfoData.GetStackTraceData(failure.Line));
                builder.ToAssertionFailure().WriteTo(testContext.LogWriter.Failures);
            }
        }
        public void ShowsLabeledValuesWithDiffs_Difference()
        {
            AssertionFailureBuilder builder = new AssertionFailureBuilder("description");

            builder.AddRawLabeledValuesWithDiffs("Left", "acde", "Right", "bcef");

            DiffSet diffSet = DiffSet.GetDiffSet("\"acde\"", "\"bcef\"").Simplify();
            StructuredTextWriter expectedValueWriter = new StructuredTextWriter();

            diffSet.WriteTo(expectedValueWriter, DiffStyle.LeftOnly);
            StructuredTextWriter actualValueWriter = new StructuredTextWriter();

            diffSet.WriteTo(actualValueWriter, DiffStyle.RightOnly);

            Assert.AreElementsEqual(new[]
            {
                new AssertionFailure.LabeledValue("Left", expectedValueWriter.ToStructuredText()),
                new AssertionFailure.LabeledValue("Right", actualValueWriter.ToStructuredText())
            }, builder.ToAssertionFailure().LabeledValues);
        }
        public void AddRawLabeledValuesWithDiffsThrowsIfRightLabelIsNull()
        {
            AssertionFailureBuilder builder = new AssertionFailureBuilder("Description");

            Assert.Throws <ArgumentNullException>(() => builder.AddRawLabeledValuesWithDiffs("xxx", "abc", null, "def"));
        }