当前位置: 首页>>代码示例>>C#>>正文


C# TestEnvironment.GetCodePart方法代码示例

本文整理汇总了C#中TestEnvironment.GetCodePart方法的典型用法代码示例。如果您正苦于以下问题:C# TestEnvironment.GetCodePart方法的具体用法?C# TestEnvironment.GetCodePart怎么用?C# TestEnvironment.GetCodePart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TestEnvironment的用法示例。


在下文中一共展示了TestEnvironment.GetCodePart方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            var expected = ((IEnumerable)environment.Expected).Cast<object>().ToArray();
            var actual = ((IEnumerable)environment.Actual).Cast<object>().ToArray();
            var codePart = environment.GetCodePart();
            var expectedFormattedValue = expected.Inspect();

            var missingFromExpected = actual.Where(a => !expected.Any(e => Is.Equal(e, a))).ToArray();
            var missingFromActual = expected.Where(e => !actual.Any(a => Is.Equal(e, a))).ToArray();

            var actualMissingMessage = missingFromActual.Any() ? string.Format("{0} is missing {1}", codePart,
                missingFromActual.Inspect()) : string.Empty;
            var expectedMissingMessage = missingFromExpected.Any() ? string.Format("{0} is missing {1}", expectedFormattedValue,
                missingFromExpected.Inspect()) : string.Empty;

            //"first should be second (ignoring order) but first is missing [4] and second is missing [2]"

            const string format = @"
            {0}
            {1}
            {2} (ignoring order)
            but
            {3}";

            string missingMessage = !string.IsNullOrEmpty(actualMissingMessage) && !string.IsNullOrEmpty(expectedMissingMessage)
                ? string.Format("{0} and {1}", actualMissingMessage, expectedMissingMessage)
                : string.Format("{0}{1}", actualMissingMessage, expectedMissingMessage);
            return string.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), expectedFormattedValue, missingMessage);
        }
开发者ID:vorou,项目名称:shouldly,代码行数:29,代码来源:ShouldBeIgnoringOrderMessageGenerator.cs

示例2: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0}
            should {1}be within
            {2}
            of
            {3}
            but was
            {4}";

            var codePart = environment.GetCodePart();
            var tolerance = environment.Tolerance.Inspect();
            var expectedValue = environment.Expected.Inspect();
            var actualValue = environment.Actual.Inspect();
            var negated = environment.ShouldMethod.Contains("Not") ? "not " : string.Empty;

            var message = string.Format(format, codePart, negated, tolerance, expectedValue, actualValue);

            if (environment.Actual.CanGenerateDifferencesBetween(environment.Expected))
            {
                message += string.Format(@"
            difference
            {0}",
                    environment.Actual.HighlightDifferencesBetween(environment.Expected));
            }

            return message;
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:29,代码来源:ShouldBeWithinRangeMessageGenerator.cs

示例3: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            Dictionary
            ""{0}""
            should 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 = string.Format("but value was \"{0}\"", actualValue.Trim('"'));
                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");
            }
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:26,代码来源:DictionaryShouldContainKeyAndValueMessageGenerator.cs

示例4: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0} should satisfy all the conditions specified, but does not.
            The following errors were found ...
            {1}";

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

            return String.Format(format, codePart, expectedValue);
        }
开发者ID:vorou,项目名称:shouldly,代码行数:12,代码来源:ShouldSatisfyAllConditionsMessageGenerator.cs

示例5: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0}
            {1}
            but {2}
            was duplicated";

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

            return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced(), actual);
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:13,代码来源:ShouldBeUniqueMessageGenerator.cs

示例6: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0}
            {1}";

            var codePart = environment.GetCodePart();

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

            return String.Format(format, codePart, environment.ShouldMethod.PascalToSpaced());
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:14,代码来源:ShouldBeNullOrEmptyMessageGenerator.cs

示例7: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0}
            {1}
            but was {2}";

            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);
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:15,代码来源:ShouldBeEmptyMessageGenerator.cs

示例8: GenerateErrorMessage

        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");
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:17,代码来源:DictionaryShouldOrNotContainKeyMessageGenerator.cs

示例9: GenerateErrorMessage

        public override string GenerateErrorMessage(TestEnvironment environment)
        {
            const string format = @"
            {0}
            should {1}contain
            {2}
            within
            {3}
            but was
            {4}";

            var codePart = environment.GetCodePart();
            var tolerance = environment.Tolerance.Inspect();
            var expectedValue = environment.Expected.Inspect();
            var actualValue = environment.Actual.Inspect();
            var negated = environment.ShouldMethod.Contains("Not") ? "not " : string.Empty;

            return string.Format(format, codePart, negated, expectedValue, tolerance, actualValue);
        }
开发者ID:jmkelly,项目名称:shouldly,代码行数:19,代码来源:ShouldContainWithinRangeMessageGenerator.cs


注:本文中的TestEnvironment.GetCodePart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。