Beispiel #1
0
        public static void ShouldFail(Action action, string errorWithSource, string errorWithoutSource, Func <string, string> messageScrubber = null)
        {
            if (messageScrubber == null)
            {
                messageScrubber = v => MatchGetHashCode.Replace(v, "(000000)");
            }
            else
            {
                var scrubber = messageScrubber;
                messageScrubber = v => MatchGetHashCode.Replace(scrubber(v), "(000000)");
            }

            action
            .ShouldSatisfyAllConditions(
                () =>
            {         //TODO: this is currently a hack this shoudld be compared with an error qualified with source
                using (ShouldlyConfiguration.DisableSourceInErrors())
                {
                    var msg = Should.Throw <ShouldAssertException>(action).Message;
                    var sourceDisabledExceptionMsg = messageScrubber(msg);
                    string expectedNearly          = CheckMessage(sourceDisabledExceptionMsg, errorWithoutSource);
                    sourceDisabledExceptionMsg.ShouldBe(expectedNearly, "Source not available", StringCompareShould.IgnoreLineEndings);
                }
            });
        }
Beispiel #2
0
        public static void ShouldFail(Action action, string errorWithSource, string errorWithoutSource, Func <string, string> messageScrubber = null)
        {
            if (messageScrubber == null)
            {
                messageScrubber = v => MatchGetHashCode.Replace(v, "(000000)");
            }
            else
            {
                var scrubber = messageScrubber;
                messageScrubber = v => MatchGetHashCode.Replace(scrubber(v), "(000000)");
            }
#if PORTABLE
            // Portable does not have source
            var portableExceptionMessage = MatchGetHashCode.Replace(Should.Throw <ShouldAssertException>(action).Message, "(000000)");
            portableExceptionMessage.ShouldBe(errorWithoutSource, "Source available", StringCompareShould.IgnoreLineEndings);
#else
            action
            .ShouldSatisfyAllConditions(
                () =>
            {
                using (ShouldlyConfiguration.DisableSourceInErrors())
                {
                    var sourceDisabledExceptionMsg = messageScrubber(Should.Throw <ShouldAssertException>(action).Message);
                    sourceDisabledExceptionMsg.ShouldBe(errorWithoutSource, "Source not available", StringCompareShould.IgnoreLineEndings);
                }
            },
                () =>
            {
                var sourceEnabledExceptionMsg = messageScrubber(Should.Throw <ShouldAssertException>(action).Message);
                sourceEnabledExceptionMsg.ShouldBe(errorWithSource, "Source available", StringCompareShould.IgnoreLineEndings);
            });
#endif
        }
 public string?GetCodeText(object?actual, StackTrace?stackTrace)
 {
     if (ShouldlyConfiguration.IsSourceDisabledInErrors())
     {
         return(actual.ToStringAwesomely());
     }
     ParseStackTrace(stackTrace);
     return(GetCodePart());
 }
Beispiel #4
0
        private static string FormatPath(IShouldlyAssertionContext context)
        {
            var result = new StringBuilder(ShouldlyConfiguration.IsSourceDisabledInErrors() ? DefaultRootValue : context.CodePart);

            if (context.Path != null)
            {
                var i = 0;
                foreach (var part in context.Path)
                {
                    result.Append(new string(' ', i++ *IndentSize));
                    result.AppendLine(part);
                }
            }

            return(result.ToString().TrimEnd());
        }
Beispiel #5
0
        public static void ShouldFail(Action action, string errorWithSource, string errorWithoutSource, Func <string, string> messageScrubber = null)
        {
            if (messageScrubber == null)
            {
                messageScrubber = v =>
                {
                    var msg = MatchGetHashCode.Replace(v, "(000000)");
                    return(msg);
                }
            }
            ;
            else
            {
                var scrubber = messageScrubber;
                messageScrubber = v =>
                {
                    var msg = scrubber(v);
                    var res = MatchGetHashCode.Replace(msg, "(000000)");
                    return(res);
                };
            }

            action
            .ShouldSatisfyAllConditions(
                () =>
            {
                using (ShouldlyConfiguration.DisableSourceInErrors())
                {
                    var sourceDisabledExceptionMsg = messageScrubber(Should.Throw <ShouldAssertException>(action).Message);
                    sourceDisabledExceptionMsg.ShouldBe(errorWithoutSource, "Source not available", StringCompareShould.IgnoreLineEndings);
                }
            },
                () =>
            {
                var sourceEnabledExceptionMsg = messageScrubber(Should.Throw <ShouldAssertException>(action).Message);
                sourceEnabledExceptionMsg.ShouldBe(errorWithSource, "Source available", StringCompareShould.IgnoreLineEndings);
            });
        }