Пример #1
0
        public void AfterMethodRun(Runner runner, FID id, MethodInfo method, RunAttribute attr, Exception error)
        {
            Console.ForegroundColor = ConsoleColor.Gray;

            //check for Aver.Throws()
            if (!runner.Emulate)
            {
                try
                {
                    var aversThrows = Aver.ThrowsAttribute.CheckMethodError(method, error);
                    if (aversThrows)
                    {
                        error = null;
                    }
                }
                catch (Exception err)
                {
                    error = err;
                }
            }

            var o = m_RunnableNode;

            if (o != null)
            {
                var nrun = o.AddChildNode("run", method.Name);
                nrun.AddAttributeNode("id", id);
                nrun.AddAttributeNode("now-loc", App.LocalizedTime);
                nrun.AddAttributeNode("now-utc", App.TimeSource.UTCNow);
                nrun.AddAttributeNode("OK", error == null);

                if (runner.Emulate)
                {
                    nrun.AddAttributeNode("emulated", true);
                }

                if (attr.Message.IsNotNullOrWhiteSpace())
                {
                    nrun.AddAttributeNode("message", attr.Message);
                }

                nrun.AddAttributeNode("run-name", attr.Name);
                nrun.AddAttributeNode("run-explicit", attr.ExplicitName);
                nrun.AddAttributeNode("run-config", attr.ConfigContent);

                outError(nrun, error);
            }


            var wasF = Console.ForegroundColor;

            if (error == null)
            {
                m_TotalOKs++;
                if (runner.Emulate)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.Write("[Emulated]");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("[OK]");
                }
            }
            else
            {
                m_TotalErrors++;
                writeError(error);
            }

            Console.ForegroundColor = wasF;
            Console.WriteLine();
        }
Пример #2
0
        public void BeforeMethodRun(Runner runner, FID id, MethodInfo method, RunAttribute attr)
        {
            if (m_RunnableHeader != null)
            {
                Console.WriteLine(m_RunnableHeader);
                m_RunnableHeader = null;
            }
            m_HadRunnableMethods = true;
            m_TotalMethods++;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Write("  - {0} ".Args(method.Name));
            if (attr.Name.IsNotNullOrWhiteSpace())
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.Write("::");
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("'{0}'".Args(attr.Name));
            }


            if (attr.ConfigContent.IsNotNullOrWhiteSpace())
            {
                try
                {
                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.Write(" {0} ".Args(attr.Config.ToLaconicString(CodeAnalysis.Laconfig.LaconfigWritingOptions.Compact)
                                               .Remove(0, 1)
                                               .TakeFirstChars(128, "...")));
                }
                catch
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("<bad config>");
                }
            }

            if (method.Name == m_PriorMethodName)
            {
                m_PriorMethodCount++;
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("[{0}] ".Args(m_PriorMethodCount));
            }
            else
            {
                m_PriorMethodCount = 0;
            }

            m_PriorMethodName = method.Name;

            if (attr.Message.IsNotNullOrWhiteSpace())
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.DarkYellow;
                Console.WriteLine("Message:");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("  ");
                Console.WriteLine(attr.Message);
            }

            Console.ForegroundColor = ConsoleColor.DarkGray;
        }