Exemple #1
0
        private static void BeginProgram(CodeTextWriter writer, IType testSuite)
        {
            writer.WriteLine("using System;");
            //writer.WriteLine("using NUnit.Framework;");
            if (!String.IsNullOrEmpty(testSuite.Namespace))
            {
                writer.WriteLine("using {0};", testSuite.Namespace);
            }
            writer.WriteLine();

            writer.WriteLine("class Program");
            writer.WriteLine("{");
            writer.Indent();
        }
Exemple #2
0
        private static void RunTest(CodeTextWriter writer, TestRunnerGeneratorOptions options, IMethod test)
        {
            var type = test.DeclaringType;

            writer.WriteLine("bool fail = false;");

            if (!test.IsStatic)
            {
                writer.WriteLine("{0} obj = new {0}();", type.Name);
            }

            CallSetUp(writer, test);

            writer.WriteLine();

            string expectedException    = test.GetExpectedException();
            bool   hasExpectedException = !String.IsNullOrEmpty(expectedException);
            bool   hasTry = hasExpectedException || options.Protect;

            if (hasTry)
            {
                writer.WriteLine("try");
                writer.WriteLine("{");
                writer.Indent();
            }

            CallMethod(writer, test);

            if (hasExpectedException)
            {
                writer.WriteLine("fail = true;");
                writer.WriteLine("Console.WriteLine(\"No expected exception: {0}\");", expectedException);
            }

            if (hasTry)
            {
                writer.Unindent();
                writer.WriteLine("}");                 //end of try
            }

            if (hasExpectedException)
            {
                //catch for expected exception
                writer.WriteLine("catch ({0})", expectedException);
                writer.WriteLine("{");
                writer.Indent();
                writer.WriteLine("fail = false;");
                writer.Unindent();
                writer.WriteLine("}");
            }

            if (hasTry)
            {
                writer.WriteLine("catch (Exception e)");
                writer.WriteLine("{");
                writer.Indent();
                writer.WriteLine("fail = true;");
                writer.WriteLine("Console.WriteLine(\"Unexpected exception: \" + e);");
                writer.Unindent();
                writer.WriteLine("}");
            }

            writer.WriteLine();

            string strFail = options.FailString;

            if (String.IsNullOrEmpty(strFail))
            {
                strFail = "fail";
            }

            string strSuccess = options.SuccessString;

            if (String.IsNullOrEmpty(strSuccess))
            {
                strSuccess = "success";
            }

            writer.WriteLine("Console.WriteLine(fail ? \"{0}\" : \"{1}\");", strFail, strSuccess);
        }
Exemple #3
0
 private static void BeginMethod(CodeTextWriter writer, string name)
 {
     writer.WriteLine("static void {0}()", name);
     writer.WriteLine("{");
     writer.Indent();
 }