Пример #1
0
        public TestCase ToTestCase(Type exceptionThrown, bool printPlanToString, string className)
        {
            // Create imports list.
            Collection<string> imports = new Collection<string>();
            foreach (string nameSpace in GetNameSpaces())
                imports.Add("using " + nameSpace + ";");

            // Create test code list.
            Collection<string> testCode = new Collection<string>();
            foreach (string codeLine in CodeGenerator.AsCSharpCode(this))
            {
                testCode.Add(codeLine);
            }

            if (printPlanToString)
            {
                testCode.Add("/*");
                testCode.Add(this.ToString());
                testCode.Add("*/");
            }

            // Create assemblies list.
            Collection<string> assemblies = GetAssemblies();

            // Create LastAction.
            TestCase.LastAction lastAction =
                new TestCase.LastAction(TestCase.LastAction.LASTACTION_MARKER
                + this.transformer.ToString());

            // Create exception.
            TestCase.ExceptionDescription exception;
            if (exceptionThrown == null)
                exception = TestCase.ExceptionDescription.NoException();
            else
                exception = TestCase.ExceptionDescription.GetDescription(exceptionThrown);

            // Put everything together, return TestCase.
            return new TestCase(lastAction, exception, imports, assemblies, className, testCode);
        }
Пример #2
0
        public TestCase ToTestCase(Type exceptionThrown, bool printPlanToString, string className)
        {
            // Create imports list.
            Collection<string> imports = new Collection<string>();
            foreach (string nameSpace in GetNameSpaces())
                imports.Add("using " + nameSpace + ";");

            // Create test code list.
            Collection<string> testCode = new Collection<string>();
            foreach (string codeLine in CodeGenerator.AsCSharpCode(this))
            {
                testCode.Add(codeLine);
            }

            if (printPlanToString)
            {
                testCode.Add("/*");
                testCode.Add(this.ToString());
                testCode.Add("*/");
            }

            // Create assemblies list.
            Collection<string> assemblies = GetAssemblies();

            // Create LastAction.
            ////[email protected] changes for capture last return value -- start 
            //string last_ret_val = "null";
            //string last_ret_type = "null";
            //if (this.transformer.ReturnValue.Count != 0)  //actions other than "MethodCall" do not have ReturnValue
            //{
            //   if (this.transformer.ReturnValue[this.transformer.ReturnValue.Count-1] != null)
            //    {
            //        last_ret_val = this.transformer.ReturnValue[this.transformer.ReturnValue.Count - 1].ToString().Replace("\n", "\\n").Replace("\r", "\\r");
            //        last_ret_type = this.transformer.ReturnValue[this.transformer.ReturnValue.Count - 1].GetType().ToString();
            //    }
            //}
            ////[email protected] changes for capture last return value -- end

            TestCase.LastAction lastAction =
                new TestCase.LastAction(TestCase.LastAction.LASTACTION_MARKER
            //    + this.transformer.ToString() //[email protected] changes for capture last return value
            //    + " type: " + last_ret_type
            //    + " val: " + last_ret_val);
            + this.transformer.ToString()); 

            // Create exception.
            TestCase.ExceptionDescription exception;
            if (exceptionThrown == null)
                exception = TestCase.ExceptionDescription.NoException();
            else
                exception = TestCase.ExceptionDescription.GetDescription(exceptionThrown);

            // Put everything together, return TestCase.
            return new TestCase(lastAction, exception, imports, assemblies, className, testCode);
        }