The NStub type represents the container class which manages the generation of testing code for the supplied System.CodeDom.CodeNamespace using the supplied implementation of NStub.Core.ICodeGenerator. The resulting files are output to the given directory.
Пример #1
0
        /*
         *      private CodeNamespace CreateNamespace(TestNode treeNode)
         *      {
         *          return null;
         *      }
         */

        /// <summary>
        /// Writes the test file.
        /// </summary>
        /// <param name="calculatedOutputDirectory">The calculated output directory.</param>
        /// <param name="codeNamespace">The code namespace.</param>
        private void WriteTestFile(
            string calculatedOutputDirectory, CodeNamespace codeNamespace)
        {
            // Now write the test file
            // NStubCore nStub =
            // new NStubCore(codeNamespace, outputDirectory,
            // new CSharpCodeGenerator(codeNamespace, outputDirectory));
            // NStubCore nStub =
            // new NStubCore(codeNamespace, outputDirectory,
            // new CSharpMbUnitCodeGenerator(codeNamespace, outputDirectory));
            // var nStub =
            // new NStubCore(
            // codeNamespace,
            // outputDirectory,
            // new CSharpMbUnitRhinoMocksCodeGenerator(codeNamespace, outputDirectory));

            // var testBuilders = new TestBuilderFactory(new PropertyBuilder(), new EventBuilder(), new MethodBuilder());

            ICodeGeneratorParameters configuration = null;

            if (this.CustomGeneratorParameters == null)
            {
                configuration = new CodeGeneratorParameters(calculatedOutputDirectory);
            }
            else
            {
                configuration = new CodeGeneratorParameters(this.CustomGeneratorParameters, calculatedOutputDirectory);
            }


            // var testBuilders = new TestBuilderFactory();
            // var codeGenerator = (ICodeGenerator)Activator.CreateInstance(generatorType, new object[]
            // {
            // sbs, codeNamespace, testBuilders, configuration
            // });
            var buildSystem   = this.sbs;
            var codeGenerator = this.OnCreateCodeGenerator(codeNamespace, configuration, buildSystem);

            // codeNamespace.Dump(3);
            var nstub = new NStubCore(buildSystem, codeNamespace, calculatedOutputDirectory, codeGenerator);

            nstub.GenerateCode();

            // Add all of our classes to the project
            foreach (CodeTypeDeclaration codeType in nstub.CodeNamespace.Types)
            {
                string fileName = codeType.Name;
                fileName  = fileName.Remove(0, fileName.LastIndexOf(".") + 1);
                fileName += ".cs";
                this.csharpProjectGenerator.ClassFiles.Add(fileName);
                Thread.Sleep(1);
                if (this.logger != null)
                {
                    this.logger("Writing '" + fileName + "'");
                }
            }
        }
Пример #2
0
        /*
                private CodeNamespace CreateNamespace(TestNode treeNode)
                {
                    return null;
                }
        */
        /// <summary>
        /// Writes the test file.
        /// </summary>
        /// <param name="calculatedOutputDirectory">The calculated output directory.</param>
        /// <param name="codeNamespace">The code namespace.</param>
        private void WriteTestFile(
            string calculatedOutputDirectory, CodeNamespace codeNamespace)
        {
            // Now write the test file
            // NStubCore nStub =
            // new NStubCore(codeNamespace, outputDirectory,
            // new CSharpCodeGenerator(codeNamespace, outputDirectory));
            // NStubCore nStub =
            // new NStubCore(codeNamespace, outputDirectory,
            // new CSharpMbUnitCodeGenerator(codeNamespace, outputDirectory));
            // var nStub =
            // new NStubCore(
            // codeNamespace,
            // outputDirectory,
            // new CSharpMbUnitRhinoMocksCodeGenerator(codeNamespace, outputDirectory));

            // var testBuilders = new TestBuilderFactory(new PropertyBuilder(), new EventBuilder(), new MethodBuilder());

            ICodeGeneratorParameters configuration = null;
            if (this.CustomGeneratorParameters == null)
            {
                configuration = new CodeGeneratorParameters(calculatedOutputDirectory);
            }
            else
            {
                configuration = new CodeGeneratorParameters(this.CustomGeneratorParameters, calculatedOutputDirectory);
            }

            // var testBuilders = new TestBuilderFactory();
            // var codeGenerator = (ICodeGenerator)Activator.CreateInstance(generatorType, new object[]
            // {
            // sbs, codeNamespace, testBuilders, configuration
            // });
            var buildSystem = this.sbs;
            var codeGenerator = this.OnCreateCodeGenerator(codeNamespace, configuration, buildSystem);

            // codeNamespace.Dump(3);
            var nstub = new NStubCore(buildSystem, codeNamespace, calculatedOutputDirectory, codeGenerator);
            nstub.GenerateCode();

            // Add all of our classes to the project
            foreach (CodeTypeDeclaration codeType in nstub.CodeNamespace.Types)
            {
                string fileName = codeType.Name;
                fileName = fileName.Remove(0, fileName.LastIndexOf(".") + 1);
                fileName += ".cs";
                this.csharpProjectGenerator.ClassFiles.Add(fileName);
                Thread.Sleep(1);
                if (this.logger != null)
                {
                    this.logger("Writing '" + fileName + "'");
                }
            }
        }