Пример #1
0
            internal TestFailure Lift(string code, string message, bool required = false)
            {
                if (!required && AFailure == null)
                {
                    return(null);
                }

                var testFailure = new TestFailure(code)
                {
                    Message = message
                };

                if (AFailure != null)
                {
                    testFailure.Children.Add(AFailure);
                }
                if (Indexes != null)
                {
                    testFailure.UserData["Indexes"] = TextUtility.Truncate(Indexes);
                }
                string successes = Successes.ToString();

                if (Stopped)
                {
                    successes = ">" + successes;
                }
                testFailure.UserData["ActualCount"] = successes;
                return(testFailure);
            }
Пример #2
0
 public IExpectationBuilder Expect(Action func)
 {
     return(new ExpectationBuilder(() => func(),
                                   false,
                                   TextUtility.FormatArgs(),
                                   Behavior));
 }
Пример #3
0
 public IExpectationBuilder <TResult> Expect <TResult>(Func <TResult> func)
 {
     return(new ExpectationBuilder <TResult>(() => func(),
                                             false,
                                             TextUtility.FormatArgs(),
                                             Behavior));
 }
Пример #4
0
        public static IDisplayActual Create(object value, int depth = 0, ObjectIDGenerator graph = null)
        {
            if (value is null)
            {
                return(Null);
            }
            if (value is string stringValue)
            {
                if (stringValue.Length == 0)
                {
                    return(EmptyString);
                }
                return(new StringDisplayActual(stringValue, depth > 0));
            }
            if (value is Type typeValue)
            {
                return(new BasicDisplayActual(TextUtility.ConvertToSimpleTypeName(typeValue), typeof(Type)));
            }
            if (value is Exception exceptionValue)
            {
                return(Exception(exceptionValue));
            }
            if (value is StringComparer)
            {
                return(new BasicDisplayActual(GetStringComparerText(value), value.GetType()));
            }

            if (depth > 3)
            {
                return(Ellipsis);
            }

            if (graph == null)
            {
                graph = new ObjectIDGenerator();
            }
            graph.GetId(value, out bool first);
            if (!first)
            {
                return(Ellipsis);
            }

            if (value is IDisplayActual da)
            {
                return(da);
            }

            if (value is IEnumerable enumerableValue)
            {
                return(new EnumerableDisplayActual(enumerableValue, depth + 1));
            }

            if (HasToStringOverride(value.GetType()))
            {
                return(new BasicDisplayActual(value.ToString(), value.GetType()));
            }

            return(new DefaultDisplayActual(value, depth, graph));
        }
Пример #5
0
 public static IExpectationBuilder <string> Expect(this GivenExpectationBuilder <TestFixtureData> self, string name)
 {
     return(new ExpectationBuilder <string>(
                () => self.Arg1[name],
                false,
                TextUtility.FormatArgs(),
                self.Behavior
                ));
 }
Пример #6
0
            public string Format(DisplayActualOptions options)
            {
                string formatString = options.ShowType() ? "{0} {{ {1} }}" : "{{ {1} }}";

                // On recursion, no need to display types
                var recursionOptions = options & ~DisplayActualOptions.ShowType;

                return(string.Format(
                           formatString,
                           TextUtility.ConvertToSimpleTypeName(_type),
                           string.Join(", ", _values.Select(v => v.Format(recursionOptions)))
                           ));
            }
Пример #7
0
            public string Format(DisplayActualOptions options)
            {
                var w = Text;

                if (options.ShowWhitespace())
                {
                    w = TextUtility.ShowWhitespace(w);
                }
                if (options.ShowType())
                {
                    var type = TextUtility.ConvertToSimpleTypeName(Type);
                    w += $" ({type})";
                }
                return(w);
            }
Пример #8
0
        public static string FormatArgs(IEnumerable <object> data)
        {
            var  sb        = new StringBuilder();
            bool needComma = false;

            foreach (var s in data)
            {
                if (needComma)
                {
                    sb.Append(", ");
                }
                sb.Append(TextUtility.Truncate(TextUtility.ConvertToString(s)));

                needComma = true;
            }
            return(sb.ToString());
        }
Пример #9
0
        internal static string FormatLocation(object location)
        {
            if (location is Uri url)
            {
                if (url.IsAbsoluteUri)
                {
                    if (url.Scheme == "data")
                    {
                        return(string.Format(
                                   "<(data){0}>",
                                   TextUtility.Escape(TextUtility.Truncate(Uri.UnescapeDataString(url.PathAndQuery)))
                                   ));
                    }
                    if (url.Scheme == "file")
                    {
                        return(url.LocalPath);
                    }
                }
                return(url.ToString());
            }

            return(location.ToString());
        }
Пример #10
0
            public string Format(DisplayActualOptions options)
            {
                var w = _text;

                if (_escape)
                {
                    w = string.Format("\"{0}\"", TextUtility.Escape(w));
                }

                if (options.ShowWhitespace())
                {
                    w = TextUtility.ShowWhitespace(w);
                }
                if (_text.Length == 0)
                {
                    w = "<empty>";
                }

                if (options.ShowType())
                {
                    return(w + " (string)");
                }
                return(w);
            }
Пример #11
0
 public static void AsserterDisabled(this TestLog log, Exception ex)
 {
     log.Warn(SR.AsserterDisabled(TextUtility.ConvertToString(ex)));
 }
Пример #12
0
        IEnumerable <TestData> CoreLoadFixture <TLocation>(
            TLocation location,
            Func <TLocation, TestFixture> fixtureFunc,
            TestTheory rt,
            IEnumerable <KeyValuePair <string, string> > fixturePatternVariables
            )
        {
            TestFixture fixture;

            try {
                fixture = fixtureFunc(location);
            } catch (Exception ex) {
                string message = ex is ParserException
                    ? ex.Message
                    : "parser error";
                return(new [] {
                    new TestData().WithTags(_tags).VerifiableProblem(
                        false,
                        string.Format("Failed to load fixture {0} ({1})", TextUtility.FormatLocation(location), message)
                        )
                });
            }

            var items = fixture.Items;

            if (items.Count == 0)
            {
                return(new [] {
                    new TestData().WithTags(_tags).VerifiableProblem(
                        false,
                        string.Format("Empty fixture {0}", TextUtility.FormatLocation(location))
                        )
                });
            }
            if (fixturePatternVariables != null)
            {
                foreach (var t in items)
                {
                    foreach (var kvp in fixturePatternVariables)
                    {
                        // Variables captured from the fixture pattern should
                        // lose to ones defined in the fixture itself
                        if (!t.Values.ContainsKey(kvp.Key))
                        {
                            t.Values.Add(kvp);
                        }
                    }
                }
            }
            // TODO Assume that the fixture has homogeneous records -- if it doesn't,
            // then we end up with the wrong TestDataBinder
            var keySet  = items[0].Values.Keys;
            var binder  = FixtureTestDataBinder.Create(rt.TestMethod, keySet);
            var results = new List <TestData>(items.Count);

            foreach (var t in items)
            {
                results.Add(
                    new TestData(
                        new TestDataState(Name, Reason, Explicit ? TestUnitFlags.Explicit : TestUnitFlags.None, _tags),
                        binder.Bind(t.Values)
                        )
                    );
            }
            return(results);
        }