Пример #1
0
        /// <summary>
        /// Converts <paramref name="result"/> instance to <see cref="EvaluatedValues"/>.
        /// </summary>
        public static EvaluatedValues NoErrors(this TestResultBase result)
        {
            if (result.HasError)
            {
                string failures = string.Join(Environment.NewLine, result.Diagnostics.Select(e => e.FullMessage));
                throw new InvalidOperationException(
                          I($"Evaluation failed. Errors: {failures}"));
            }

            return(EvaluatedValues.Empty);
        }
Пример #2
0
        /// <nodoc />
        public static void ExpectErrors(this TestResultBase testResult, int count)
        {
            Contract.Requires(testResult != null);
            Contract.Requires(count >= 0);

            XAssert.AreEqual(
                count,
                testResult.ErrorCount,
                "Errors: {0}",
                string.Join(Environment.NewLine, testResult.Diagnostics.Where(e => e.Level.IsError()).Select(x => x.FullMessage)));
        }
Пример #3
0
        /// <nodoc />
        public static void ExpectErrorCode(this TestResultBase testResult, int code, int count, string prefix = "DS")
        {
            Contract.Requires(testResult != null);
            Contract.Requires(count >= 0);

            int found = testResult.Diagnostics.Count(dsError => code == dsError.ErrorCode);

            var diagnostics = string.Join(Environment.NewLine, testResult.Diagnostics.Select(e => e.FullMessage));

            Assert.True(count == found,
                        I($"Expect error code '{code}' to occur {count} time(s), but only occur {found} time(s). Available errors:\r\n{diagnostics}"));
        }
Пример #4
0
        /// <nodoc />
        public static void ExpectErrorMessageSubstrings(this TestResultBase testResult, string[] messages, bool useFullMessage = false)
        {
            Contract.Requires(testResult != null);
            Contract.Requires(messages != null);
            Contract.RequiresForAll(messages, m => m != null);

            foreach (var message in messages)
            {
                bool found =
                    testResult.Diagnostics.Any(dsError => !useFullMessage ? dsError.Message.Contains(message) : dsError.FullMessage.Contains(message));
                var diagnostics = string.Join(Environment.NewLine, testResult.Diagnostics.Select(e => e.Message));

                Assert.True(found,
                            I($"Expect error messages to contain '{message}'. All errors: \r\n{diagnostics}"));
            }
        }
Пример #5
0
        /// <nodoc />
        public static Diagnostic[] ExpectCheckerDiagnostic(this TestResultBase result, TypeScript.Net.Diagnostics.IDiagnosticMessage expected, params string[] args)
        {
            var checkerDiagnostics = result.Errors.Where(e => s_checkerErrorCodes.Contains(e.ErrorCode)).ToArray();

            if (!checkerDiagnostics.Any())
            {
                var msg = string.Join(", ", s_checkerErrors.Select(e => $"'{e}'"));
                XAssert.Fail($"Didn't find any checher errors.  Expected one of: {msg}.  Actual: {result}");
            }

            var formatted = string.Format(expected.Message, args);

            if (!checkerDiagnostics.Any(e => e.FullMessage.Contains(formatted)))
            {
                var foundErrors = string.Join(", ", checkerDiagnostics);
                XAssert.Fail($"None of the found errors contains '{formatted}'.  Found errors: {foundErrors}");
            }

            return(checkerDiagnostics);
        }
Пример #6
0
 /// <nodoc />
 public static void ExpectNoError(this TestResultBase testResult)
 {
     Contract.Requires(testResult != null);
     ExpectErrors(testResult, count: 0);
 }