Example #1
0
        private void BtnGoClick(object sender, EventArgs e)
        {
            Dumper();

            string outputFolder = this._outputDirectoryTextBox.Text;

            var para = new CodeGeneratorParameters(outputFolder)
            {
                MethodGeneratorLevelOfDetail = MemberVisibility.Internal
            };
            // bg.CustomGeneratorParameters = para;

            /*var bg = new LoadAssemblyWorker(sbs, this.buildData, this)
             * {
             * BrowseInputAssemblyButton = this._browseInputAssemblyButton,
             * BrowseOutputDirectoryButton = this._browseOutputDirectoryButton,
             * GoButton = this._goButton,
             *  Logger = Log,
             * };*/

            Type                 generatorType        = (Type)cbGenerators.SelectedItem;
            string               inputAssemblyPath    = this._inputAssemblyTextBox.Text;
            IList <TreeNode>     mainNodes            = this._assemblyGraphTreeView.Nodes.Cast <TreeNode>().ToList();
            IList <AssemblyName> referencedAssemblies = this._referencedAssemblies;
            //var data = new GeneratorRunnerData(outputFolder, generatorType, inputAssemblyPath, mainNodes.MapToNodes(), referencedAssemblies);
            var data = GeneratorRunnerData.Create(outputFolder, generatorType, inputAssemblyPath, mainNodes.MapToNodes(), referencedAssemblies);


            bg.RunWorkerAsync(data, para);
        }
Example #2
0
        public void GenerateWithAssemblyAndModuleAndClassesAndMethod()
        {
            //expected = false;
            var  outputFolder        = "Value ? of ou$tputFol*der";
            var  generatorType       = typeof(object);
            var  inputAssemblyPath   = "Value of inputAssemblyPath";
            char directorySeparator  = '\\';
            var  firstModuleName     = "TheTestNode";
            var  firstModuleTag      = "FirstModule";
            var  className1Namespace = "The.Namespace";
            var  className1          = "VeryPrettyFactory";
            var  className1FullName  = className1Namespace + "." + className1;
            var  classTag            = this.GetType();
            var  methodName          = "MyMethod";
            var  methodTag           = this.GetType().GetMethod("FakeMethod");

            var assemblyNode = new TestNode(firstModuleName + ".dll", TestNodeType.Assembly, null)
            {
                Checked = true
            };
            var moduleNode = new TestNode(firstModuleName + ".dll", TestNodeType.Module, firstModuleTag)
            {
                Checked = true
            };
            var classNode = new TestNode(className1FullName, TestNodeType.Class, classTag)
            {
                Checked = true
            };
            var methodNode = new TestNode(methodName, TestNodeType.Method, methodTag)
            {
                Checked = true
            };

            assemblyNode.Nodes.Add(moduleNode);
            moduleNode.Nodes.Add(classNode);
            classNode.Nodes.Add(methodNode);
            var mainNodes = new[] { assemblyNode };

            var referencedAssemblies = typeof(CSharpTestProjectBuilderTest).Assembly.GetReferencedAssemblies();
            var para       = new CodeGeneratorParameters(outputFolder);
            var runnerData = GeneratorRunnerData.Create(
                outputFolder, generatorType, inputAssemblyPath, mainNodes, referencedAssemblies);

            Expect.Call(sbs.DirectorySeparatorChar).Return(directorySeparator).Repeat.Any();
            Expect.Call(sbs.GetFileNameWithoutExtension(firstModuleName + ".dll")).Return(firstModuleName);
            var expectedDirectory = outputFolder + directorySeparator + firstModuleName + ".Tests";

            Expect.Call(sbs.CreateDirectory(expectedDirectory)).Return(null);
            Expect.Call(sbs.DirectoryExists(expectedDirectory)).Return(true);

            var prjReferencedAssemblies = new List <AssemblyName>();

            Expect.Call(projectGenerator.ReferencedAssemblies).Return(prjReferencedAssemblies).Repeat.Any();
            Expect.Call(projectGenerator.GenerateProjectFile).Repeat.Once();
            var classFilesList = new List <string>();

            Expect.Call(projectGenerator.ClassFiles).Return(classFilesList).Repeat.Once();

            var                  codeGenerator          = mocks.StrictMock <ICodeGenerator>();
            CodeNamespace        generatorCodeNamespace = null;
            IBuildDataDictionary generatorBuildData     = null;

            Expect.Call(createGeneratorCallback(sbs, null, null, null))
            //.Constraints(Is.Same(sbs), Is.TypeOf<CodeGeneratorParameters>(), Is.TypeOf<CodeNamespace>())
            .Constraints(
                Is.Same(sbs),
                Is.TypeOf <IBuildDataDictionary>() && Is.NotNull(),
                Is.TypeOf <CodeGeneratorParameters>() && Property.Value("OutputDirectory", expectedDirectory),
                Is.TypeOf <CodeNamespace>())
            //.Return(codeGenerator)
            .Do((Func <IBuildSystem, IBuildDataDictionary, ICodeGeneratorParameters, CodeNamespace, ICodeGenerator>)
                delegate(IBuildSystem buildSys, IBuildDataDictionary data, ICodeGeneratorParameters cgp, CodeNamespace cn)
            {
                Assert.AreEqual(expectedDirectory, cgp.OutputDirectory);
                Assert.IsFalse(cgp.UseSetupAndTearDown);

                generatorBuildData     = data;
                generatorCodeNamespace = cn;
                return(codeGenerator);
            });

            Expect.Call(codeGenerator.CodeNamespace   = null).PropertyBehavior();
            Expect.Call(codeGenerator.OutputDirectory = expectedDirectory);
            Expect.Call(codeGenerator.GenerateCode);

            // logging
            Expect.Call(delegate { this.logger(null); }).Constraints(Is.NotNull()).Repeat.AtLeastOnce();
            Expect.Call(projectGenerator.ProjectName).Return(firstModuleName).Repeat.Any();

            mocks.ReplayAll();

            testObject.GenerateTests(runnerData);
            //Assert.AreEqual(expected, actual);

            Assert.IsNotEmpty(generatorBuildData);
            Assert.Count(1, generatorBuildData);
            Assert.IsTrue(generatorBuildData.Contains(this.buildDataItem));

            Assert.IsNotEmpty(prjReferencedAssemblies);
            Assert.IsNotEmpty(classFilesList);

            Assert.IsEmpty(generatorCodeNamespace.Comments);
            Assert.IsEmpty(generatorCodeNamespace.Imports);
            Assert.AreEqual(className1Namespace, generatorCodeNamespace.Name);
            Assert.IsNotEmpty(generatorCodeNamespace.Types);
            Assert.IsEmpty(generatorCodeNamespace.UserData);

            var classDefinition1 = generatorCodeNamespace.Types[0];

            Assert.AreEqual(MemberAttributes.Private | MemberAttributes.Final, classDefinition1.Attributes);
            Assert.IsEmpty(classDefinition1.BaseTypes);
            Assert.IsEmpty(classDefinition1.Comments);
            Assert.IsEmpty(classDefinition1.CustomAttributes);

            Assert.AreEqual(className1FullName, classDefinition1.Name);
            Assert.IsTrue(classDefinition1.IsClass);
            Assert.IsEmpty(classDefinition1.StartDirectives);
            Assert.IsEmpty(classDefinition1.TypeParameters);

            Assert.IsNotEmpty(classDefinition1.UserData);
            Assert.Count(1, classDefinition1.UserData);
            Assert.AreEqual(classTag, classDefinition1.UserData[NStubConstants.UserDataClassTypeKey]);

            Assert.IsNotEmpty(classDefinition1.Members);
            var class1Members = classDefinition1.Members;

            // Todo: More checks on the generated types.
            mocks.VerifyAll();
        }