Пример #1
0
 public ShouldlyMessage(object expected, object actual, object key)
 {
     _testEnvironment = GetStackFrameForOriginatingTestMethod(expected, actual);
     _testEnvironment.Key = key;
     _testEnvironment.HasActual = true;
     _testEnvironment.HasKey = true;
 }
        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            Dictionary
            ""{0}""
            should not contain key
            ""{1}""
            with value
            ""{2}""
            {3}";

            var codePart = environment.GetCodePart();
            var expectedValue = environment.Expected.Inspect();
            var actualValue = environment.Actual.Inspect();
            var keyValue = environment.Key.Inspect();

            if (environment.HasKey)
            {
                var valueString = "but does";
                return String.Format(format, codePart, keyValue.Trim('"'), expectedValue.Trim('"'), valueString);
            }
            else
            {
                return String.Format(format, codePart, actualValue.Trim('"'), expectedValue.Trim('"'), "but the key does not exist");
            }
        }
Пример #3
0
 public ExpectedActualKeyShouldlyMessage(object expected, object actual, object key)
 {
     TestEnvironment = new TestEnvironment(expected, actual);
     TestEnvironment.Key = key;
     TestEnvironment.HasActual = true;
     TestEnvironment.HasKey = true;
 }
        protected static string GetCodePart(TestEnvironment environment)
        {
            var codePart = "The provided expression";

            if (environment.DeterminedOriginatingFrame)
            {
                var codeLines = String.Join("\n",
                                            File.ReadAllLines(environment.FileName)
                                                .Skip(environment.LineNumber).ToArray());

                codePart = codeLines.Substring(0, codeLines.IndexOf(environment.ShouldMethod) - 1).Trim();
            }
            return codePart;
        }
        public override string GenerateErrorMessage(TestEnvironment environment, object expected)
        {
            var format = @"
            {0}
            {1} {2}
            {3}
            but does {4}";

            var codePart = GetCodePart(environment);
            var isNegatedAssertion = environment.ShouldMethod.Contains("Not");

            const string elementSatifyingTheConditionString = "an element satisfying the condition";
            return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), expected is BinaryExpression ? elementSatifyingTheConditionString : "", expected.Inspect(), isNegatedAssertion ? "" : "not");
        }
Пример #6
0
        public override string GenerateErrorMessage(TestEnvironment environment, object actual)
        {
            const string format = @"
            {0}
            {1}";

            var codePart = GetCodePart(environment);
            var actualValue = actual.Inspect();

            var isNegatedAssertion = environment.ShouldMethod.Contains("Not");
            if (isNegatedAssertion)
                return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), actual == null ? "null" : "");

            return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), actualValue);
        }
Пример #7
0
        private static string CreateActualVsExpectedMessage(object actual, object expected, TestEnvironment environment, string codePart)
        {
            string message = string.Format(@"{0}
            {1}
            {2}
            but was
            {3}",
                codePart, environment.ShouldMethod.PascalToSpaced(), expected.Inspect(), actual.Inspect());

            if (actual.CanCompareAgainst(expected)) {
                message += string.Format(@"
            difference
            {0}",
                actual.HighlightDifferencesFrom(expected));
            }
            return message;
        }
Пример #8
0
 public ShouldlyMessage(object expected)
 {
     _testEnvironment = GetStackFrameForOriginatingTestMethod(expected);
     _testEnvironment.HasActual = false;
 }
 public abstract string GenerateErrorMessage(TestEnvironment environment, object expected);
Пример #10
0
        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format =  @"
            Dynamic object
            ""{0}""
            should contain property
            {1}
            but does not.";

            var testFileName = environment.OriginatingFrame.GetFileName();
            var assertionLineNumber = environment.OriginatingFrame.GetFileLineNumber();

            var codeLine = string.Join("", File.ReadAllLines(testFileName).ToArray().Skip(assertionLineNumber - 1).Select(s => s.Trim()));
            var dynamicObjectName = DynamicObjectNameExtractor.Match(codeLine).Groups["dynamicObjectName"];
            var propertyName = DynamicObjectNameExtractor.Match(codeLine).Groups["propertyName"];

            return String.Format(format, dynamicObjectName, propertyName);
        }
Пример #11
0
 public ExpectedActualToleranceShouldlyMessage(object expected, object actual, object tolerance)
 {
     TestEnvironment = new TestEnvironment(expected, actual);
     TestEnvironment.Tolerance = tolerance;
     TestEnvironment.HasActual = true;
 }
 public override bool CanProcess(TestEnvironment environment)
 {
     return true;
 }
Пример #13
0
 public abstract string GenerateErrorMessage(TestEnvironment environment);
Пример #14
0
        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0}
            {1}";

            var codePart = environment.GetCodePart();
            var expectedValue = environment.Expected.Inspect();

            if (environment.IsNegatedAssertion)
                return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), environment.Expected == null ? "null" : "");

            return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), expectedValue);
        }
 public override bool CanProcess(TestEnvironment environment)
 {
     return Validator.IsMatch(environment.ShouldMethod);
 }
Пример #16
0
 public ExpectedActualShouldlyMessage(object expected, object actual)
 {
     TestEnvironment = new TestEnvironment(expected, actual);
     TestEnvironment.HasActual = true;
 }
 public abstract bool CanProcess(TestEnvironment environment);
Пример #18
0
 public ExpectedShouldlyMessage(object expected)
 {
     TestEnvironment = new TestEnvironment(expected);
 }
Пример #19
0
        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            Dictionary
            ""{0}""
            {1}
            ""{2}""
            but does {3}";

            var codePart = environment.GetCodePart();
            var expectedValue = environment.Expected.Inspect();

            if (environment.IsNegatedAssertion)
                return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), environment.Expected, "");

            return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), expectedValue.Trim('"'), "not");
        }