public void ErrorMessages()
        {
            var tests = new ListOfTuples <string, string[]>
            {
                { "xa", new[] { "Contains A" } },
                { "xb", new[] { "Contains B (abc, 123)", "Property:Name" } },
                { "xc", new[] { "Contains C (xc, 2)" } },
                { "xdddddd", new[] { "Property 'Simple2-Name' should not contain 'letter D'. The entered text is 'xdddddd', 7 characters long." } },
            };

            foreach (var test in tests)
            {
                using (var scope = TestScope.Create())
                {
                    Console.WriteLine("\r\nInput: " + test.Item1);
                    var simple2 = scope.Resolve <Common.DomRepository>().TestInvalidData.Simple2;
                    simple2.Delete(simple2.Query());
                    var newItem = new TestInvalidData.Simple2 {
                        Name = test.Item1
                    };
                    var error = TestUtility.ShouldFail <Rhetos.UserException>(
                        () => simple2.Insert(newItem),
                        test.Item2);
                    Console.WriteLine("ErrorMessage: " + ExceptionsUtility.MessageForLog(error));
                    Console.WriteLine("Exception: " + error.ToString());
                }
            }
        }
        public static TExpectedException ShouldFail <TExpectedException>(Action action, params string[] expectedErrorContent)
            where TExpectedException : Exception
        {
            Exception exception = null;

            try
            {
                action();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsNotNull(exception, "Expected exception did not happen.");

            string message = exception.GetType().Name + ": " + ExceptionsUtility.MessageForLog(exception);

            if (exception is UserException && ((UserException)exception).SystemMessage != null)
            {
                message += "\r\n  SystemMessage: " + ((UserException)exception).SystemMessage;
            }
            Console.WriteLine("[ShouldFail] " + message);

            if (!(exception is TExpectedException))
            {
                Assert.Fail(string.Format("Unexpected exception type: {0} instead of a {1}.",
                                          exception.GetType().Name,
                                          typeof(TExpectedException).Name));
            }

            AssertContains(message, expectedErrorContent, "Exception message is incorrect: " + message, exception.ToString());

            return((TExpectedException)exception);
        }
示例#3
0
        public static void PrintErrorSummary(Exception ex)
        {
            while ((ex is DependencyResolutionException || ex is AggregateException) &&
                   ex.InnerException != null)
            {
                ex = ex.InnerException;
            }

            Console.WriteLine();
            Console.WriteLine("=============== ERROR SUMMARY ===============");
            Console.WriteLine($"{ex.GetType().Name}: {ExceptionsUtility.MessageForLog(ex)}");
            Console.WriteLine("=============================================");
            Console.WriteLine();
            Console.WriteLine($"See RhetosCli.log for more information on error. Enable TraceLog in '{LoggingConfigurationPath}' for even more details.");
        }
示例#4
0
        public static void PrintErrorSummary(Exception ex)
        {
            while ((ex is DependencyResolutionException || ex is AggregateException) &&
                   ex.InnerException != null)
            {
                ex = ex.InnerException;
            }

            Console.WriteLine();
            Console.WriteLine("=============== ERROR SUMMARY ===============");
            Console.WriteLine(ex.GetType().Name + ": " + ExceptionsUtility.MessageForLog(ex));
            Console.WriteLine("=============================================");
            Console.WriteLine();
            Console.WriteLine("See DeployPackages.log for more information on error. Enable TraceLog in DeployPackages.exe.config for even more details.");
        }
        public void SafeFormatMessage()
        {
            var tests = new ListOfTuples <Exception, string>
            {
                { new Exception("abc"), "abc" },
                { new UserException("abc"), "abc" },
                { new UserException("abc", null, null, null), "abc" },
                { new UserException("abc", new object[] { 123 }, null, null), "abc" },
                { new UserException("a{0}bc", new object[] { 123, 456 }, null, null), "a123bc" },
                { new UserException("a{1}bc", new object[] { 123 }, null, null), "Invalid error message format. Message: \"a{1}bc\", Parameters: \"123\", FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list." },
                { new UserException("a{0}bc", null, null, null), "Invalid error message format. Message: \"a{0}bc\", Parameters: null, FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list." },
            };

            foreach (var test in tests)
            {
                Console.WriteLine("Test: " + test.Item1.ToString());
                string result = ExceptionsUtility.MessageForLog(test.Item1);
                Assert.AreEqual(test.Item2, result);
            }
        }