Ejemplo n.º 1
0
        public void ConstructWithParametersOutputFolderGeneratorTypeInputAssemblyPathMainNodesReferencedAssembliesTest()
        {
            // TODO: Implement unit test for ConstructWithParametersOutputFolderGeneratorTypeInputAssemblyPathMainNodesReferencedAssemblies
            this.outputFolder         = "Value of outputFolder";
            this.generatorType        = typeof(object);
            this.inputAssemblyPath    = "Value of inputAssemblyPath";
            this.mainNodes            = new[] { new TestNode("A", TestNodeType.Class, null), new TestNode("B", TestNodeType.Method, null) };
            this.referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            this.testObject           = new GeneratorRunnerData(
                this.outputFolder, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies);

            Assert.Throws <ArgumentNullException>(() => new GeneratorRunnerData(
                                                      null, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies));
            Assert.Throws <ArgumentException>(() => new GeneratorRunnerData(
                                                  string.Empty, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies));
            Assert.Throws <ArgumentNullException>(() => new GeneratorRunnerData(
                                                      this.outputFolder, null, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies));
            Assert.Throws <ArgumentNullException>(() => new GeneratorRunnerData(
                                                      this.outputFolder, this.generatorType, null, this.mainNodes, this.referencedAssemblies));
            Assert.Throws <ArgumentException>(() => new GeneratorRunnerData(
                                                  this.outputFolder, this.generatorType, string.Empty, this.mainNodes, this.referencedAssemblies));
            Assert.Throws <ArgumentNullException>(() => new GeneratorRunnerData(
                                                      this.outputFolder, this.generatorType, this.inputAssemblyPath, null, this.referencedAssemblies));
            Assert.Throws <ArgumentNullException>(() => new GeneratorRunnerData(
                                                      this.outputFolder, this.generatorType, this.inputAssemblyPath, this.mainNodes, null));
        }
Ejemplo n.º 2
0
        public void ConstructWithParametersOutputFolderGeneratorTypeInputAssemblyPathMainNodesReferencedAssembliesTest()
        {
            // TODO: Implement unit test for ConstructWithParametersOutputFolderGeneratorTypeInputAssemblyPathMainNodesReferencedAssemblies
            this.outputFolder = "Value of outputFolder";
            this.generatorType = typeof(object);
            this.inputAssemblyPath = "Value of inputAssemblyPath";
            this.mainNodes = new[] { new TestNode("A", TestNodeType.Class, null), new TestNode("B", TestNodeType.Method, null) };
            this.referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            this.testObject = new GeneratorRunnerData(
                this.outputFolder, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies);

            Assert.Throws<ArgumentNullException>(() => new GeneratorRunnerData(
                null, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies));
            Assert.Throws<ArgumentException>(() => new GeneratorRunnerData(
                string.Empty, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies));
            Assert.Throws<ArgumentNullException>(() => new GeneratorRunnerData(
                this.outputFolder, null, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies));
            Assert.Throws<ArgumentNullException>(() => new GeneratorRunnerData(
                this.outputFolder, this.generatorType, null, this.mainNodes, this.referencedAssemblies));
            Assert.Throws<ArgumentException>(() => new GeneratorRunnerData(
                this.outputFolder, this.generatorType, string.Empty, this.mainNodes, this.referencedAssemblies));
            Assert.Throws<ArgumentNullException>(() => new GeneratorRunnerData(
                this.outputFolder, this.generatorType, this.inputAssemblyPath, null, this.referencedAssemblies));
            Assert.Throws<ArgumentNullException>(() => new GeneratorRunnerData(
                this.outputFolder, this.generatorType, this.inputAssemblyPath, this.mainNodes, null));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void SetUp()
 {
     // ToDo: Implement SetUp logic here
     this.outputFolder         = "Value of outputFolder";
     this.generatorType        = typeof(object);
     this.inputAssemblyPath    = "Value of inputAssemblyPath";
     this.mainNodes            = new[] { new TestNode("A", TestNodeType.Class, null), new TestNode("B", TestNodeType.Method, null) };
     this.referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
     this.testObject           = new GeneratorRunnerData(
         this.outputFolder, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies);
 }
Ejemplo n.º 5
0
        public void GenerateWithTwoEmptyAssemblies()
        {
            //expected = false;
            var  outputFolder       = "Value of outputFolder";
            var  generatorType      = typeof(object);
            var  inputAssemblyPath  = "Value of inputAssemblyPath";
            char directorySeparator = '\\';
            var  firstAssemblyName  = "TheTestNode";
            var  secondAssemblyName = "AnotherModule";
            var  isGetFileNameUsed  = "amIused";

            var mainNodes = new[]
            {
                new TestNode(firstAssemblyName + ".dll", TestNodeType.Module, null),
                new TestNode(secondAssemblyName + ".dll", TestNodeType.Module, null),
                //new TestNode("C", TestNodeType.Method, null),
            };
            var referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData           = new GeneratorRunnerData(
                outputFolder, generatorType, inputAssemblyPath, mainNodes, referencedAssemblies);

            Expect.Call(sbs.DirectorySeparatorChar).Return(directorySeparator).Repeat.AtLeastOnce();
            // The return value of GetFileNameWithoutExtension: Add isGetFileNameUsed as indicator, that the return value is
            // used in further processing.
            Expect.Call(sbs.GetFileNameWithoutExtension(firstAssemblyName + ".dll")).Return(firstAssemblyName + isGetFileNameUsed);
            Expect.Call(sbs.GetFileNameWithoutExtension(secondAssemblyName + ".dll")).Return(secondAssemblyName + isGetFileNameUsed);
            // Well, here it should be used, when requesting to create a directory.
            Expect.Call(sbs.CreateDirectory(outputFolder + directorySeparator + firstAssemblyName + isGetFileNameUsed + ".Tests")).Return(null);
            Expect.Call(sbs.CreateDirectory(outputFolder + directorySeparator + secondAssemblyName + isGetFileNameUsed + ".Tests")).Return(null);

            //var prjReferencedAssemblies = referencedAssemblies.ToList();
            var prjReferencedAssemblies = new List <AssemblyName>();

            Expect.Call(projectGenerator.ReferencedAssemblies).Return(prjReferencedAssemblies).Repeat.Any();
            Expect.Call(projectGenerator.GenerateProjectFile).Repeat.Twice();

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

            mocks.ReplayAll();

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

            // Todo: where is the test assembly in the project? seems like the project generator has his problems with assembly refs.
            // Assert.Contains(prjReferencedAssemblies.Select(e => e.Name), firstModuleName + ".dll");
            // Assert.Contains(prjReferencedAssemblies.Select(e => e.Name), secondModuleName + ".dll");


            mocks.VerifyAll();
        }
Ejemplo n.º 6
0
        public void GenerateOnMissingDirectoryThrows()
        {
            //expected = false;
            var  outputFolder       = "Value ? of ou$tputFol*der";
            var  generatorType      = typeof(object);
            var  inputAssemblyPath  = "Value of inputAssemblyPath";
            char directorySeparator = '\\';
            var  firstAssemblyName  = "TheTestNode";
            var  moduleName         = "The.Namespace.VeryPrettyFactory";

            var assemblyNode = new TestNode(firstAssemblyName + ".dll", TestNodeType.Module, null);
            var moduleNode   = new TestNode(moduleName, TestNodeType.Class, null);

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

            var referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData           = new GeneratorRunnerData(
                outputFolder, generatorType, inputAssemblyPath, mainNodes, referencedAssemblies);

            Expect.Call(sbs.DirectorySeparatorChar).Return(directorySeparator).Repeat.Any();
            Expect.Call(sbs.GetFileNameWithoutExtension(firstAssemblyName + ".dll")).Return(firstAssemblyName).Repeat.Any();
            Expect.Call(sbs.CreateDirectory(outputFolder + directorySeparator + firstAssemblyName + ".Tests")).Return(null);

            // return false = Directory non existant.
            Expect.Call(sbs.DirectoryExists(outputFolder + directorySeparator + firstAssemblyName + ".Tests")).Return(false);

            var prjReferencedAssemblies = new List <AssemblyName>();

            Expect.Call(projectGenerator.ReferencedAssemblies).Return(prjReferencedAssemblies).Repeat.Any();
            Expect.Call(projectGenerator.GenerateProjectFile).Repeat.Any();

            var codeGenerator = mocks.StrictMock <ICodeGenerator>();

            Expect.Call(createGeneratorCallback(sbs, null, null)).IgnoreArguments().Return(codeGenerator);

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

            Assert.Throws <System.IO.DirectoryNotFoundException>(() => testObject.GenerateTests(runnerData));

            mocks.VerifyAll();
        }
Ejemplo n.º 7
0
        public void GenerateOnMissingDirectoryThrows()
        {
            //expected = false;
            var outputFolder = "Value ? of ou$tputFol*der";
            var generatorType = typeof(object);
            var inputAssemblyPath = "Value of inputAssemblyPath";
            char directorySeparator = '\\';
            var firstAssemblyName = "TheTestNode";
            var moduleName = "The.Namespace.VeryPrettyFactory";

            var assemblyNode = new TestNode(firstAssemblyName + ".dll", TestNodeType.Module, null);
            var moduleNode = new TestNode(moduleName, TestNodeType.Class, null);
            assemblyNode.Nodes.Add(moduleNode);
            var mainNodes = new[] { assemblyNode };

            var referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData = new GeneratorRunnerData(
                outputFolder, generatorType, inputAssemblyPath, mainNodes, referencedAssemblies);

            Expect.Call(sbs.DirectorySeparatorChar).Return(directorySeparator).Repeat.Any();
            Expect.Call(sbs.GetFileNameWithoutExtension(firstAssemblyName + ".dll")).Return(firstAssemblyName).Repeat.Any();
            Expect.Call(sbs.CreateDirectory(outputFolder + directorySeparator + firstAssemblyName + ".Tests")).Return(null);

            // return false = Directory non existant.
            Expect.Call(sbs.DirectoryExists(outputFolder + directorySeparator + firstAssemblyName + ".Tests")).Return(false);

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

            var codeGenerator = mocks.StrictMock<ICodeGenerator>();
            Expect.Call(createGeneratorCallback(sbs, null, null)).IgnoreArguments().Return(codeGenerator);

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

            Assert.Throws<System.IO.DirectoryNotFoundException>(() => testObject.GenerateTests(runnerData));

            mocks.VerifyAll();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Runs the worker asynchronous.
        /// </summary>
        /// <param name="runnerData">The runner data.</param>
        public void RunWorkerAsync(
            GeneratorRunnerData runnerData, ICodeGeneratorSetup codegeneratorSetup)
        {
            // Dumper();
            // GenerateTests();
            this.BeforeGenerateTests();

            var bg = new BackgroundWorker();

            bg.DoWork             += this.WorkerDoWork;
            bg.RunWorkerCompleted += this.BgRunWorkerCompleted;

            // Type generatorType = (Type)cbGeneratorsSelectedItem;
            // IList<TreeNode> mainNodes = assemblyGraph.Nodes.Cast<TreeNode>().ToList();
            // var runnerData = new GeneratorRunnerData(outputFolder, generatorType, inputAssemblyPath, mainNodes.MapToNodes(), referencedAssemblies);

            var parameters = new object[] { runnerData, codegeneratorSetup };

            bg.RunWorkerAsync(parameters);
        }
Ejemplo n.º 9
0
 public void TearDown()
 {
     // ToDo: Implement TearDown logic here
     this.testObject = null;
 }
Ejemplo n.º 10
0
 public void SetUp()
 {
     // ToDo: Implement SetUp logic here
     this.outputFolder = "Value of outputFolder";
     this.generatorType = typeof(object);
     this.inputAssemblyPath = "Value of inputAssemblyPath";
     this.mainNodes = new[] { new TestNode("A", TestNodeType.Class, null), new TestNode("B", TestNodeType.Method, null) };
     this.referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
     this.testObject = new GeneratorRunnerData(
         this.outputFolder, this.generatorType, this.inputAssemblyPath, this.mainNodes, this.referencedAssemblies);
 }
Ejemplo n.º 11
0
        public void GenerateWithAssemblyAndModule()
        {
            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 assemblyNode = new TestNode(firstModuleName + ".dll", TestNodeType.Assembly, null) { Checked = true };
            var moduleNode = new TestNode(firstModuleName + ".dll", TestNodeType.Module, firstModuleTag) { Checked = true };
            assemblyNode.Nodes.Add(moduleNode);
            var mainNodes = new[] { assemblyNode };

            var referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData = new GeneratorRunnerData(
                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 codeGenerator = mocks.StrictMock<ICodeGenerator>();

            Expect.Call(createGeneratorCallback(sbs, null, null))
                //.Constraints(Is.Same(sbs), Is.TypeOf<CodeGeneratorParameters>(), Is.TypeOf<CodeNamespace>())
                .Constraints(
                Is.Same(sbs),
                Is.TypeOf<CodeGeneratorParameters>() && Property.Value("OutputDirectory", expectedDirectory),
                Is.TypeOf<CodeNamespace>())
                .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(prjReferencedAssemblies);

            mocks.VerifyAll();
        }
Ejemplo n.º 12
0
        public void GenerateWithTwoEmptyAssemblies()
        {
            //expected = false;
            var outputFolder = "Value of outputFolder";
            var generatorType = typeof(object);
            var inputAssemblyPath = "Value of inputAssemblyPath";
            char directorySeparator = '\\';
            var firstAssemblyName = "TheTestNode";
            var secondAssemblyName = "AnotherModule";
            var isGetFileNameUsed = "amIused";

            var mainNodes = new[]
            {
                new TestNode(firstAssemblyName + ".dll", TestNodeType.Module, null),
                new TestNode(secondAssemblyName + ".dll", TestNodeType.Module, null),
                //new TestNode("C", TestNodeType.Method, null),
            };
            var referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData = new GeneratorRunnerData(
                outputFolder, generatorType, inputAssemblyPath, mainNodes, referencedAssemblies);

            Expect.Call(sbs.DirectorySeparatorChar).Return(directorySeparator).Repeat.AtLeastOnce();
            // The return value of GetFileNameWithoutExtension: Add isGetFileNameUsed as indicator, that the return value is
            // used in further processing.
            Expect.Call(sbs.GetFileNameWithoutExtension(firstAssemblyName + ".dll")).Return(firstAssemblyName + isGetFileNameUsed);
            Expect.Call(sbs.GetFileNameWithoutExtension(secondAssemblyName + ".dll")).Return(secondAssemblyName + isGetFileNameUsed);
            // Well, here it should be used, when requesting to create a directory.
            Expect.Call(sbs.CreateDirectory(outputFolder + directorySeparator + firstAssemblyName + isGetFileNameUsed + ".Tests")).Return(null);
            Expect.Call(sbs.CreateDirectory(outputFolder + directorySeparator + secondAssemblyName + isGetFileNameUsed + ".Tests")).Return(null);

            //var prjReferencedAssemblies = referencedAssemblies.ToList();
            var prjReferencedAssemblies = new List<AssemblyName>();
            Expect.Call(projectGenerator.ReferencedAssemblies).Return(prjReferencedAssemblies).Repeat.Any();
            Expect.Call(projectGenerator.GenerateProjectFile).Repeat.Twice();

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

            mocks.ReplayAll();

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

            // Todo: where is the test assembly in the project? seems like the project generator has his problems with assembly refs.
            // Assert.Contains(prjReferencedAssemblies.Select(e => e.Name), firstModuleName + ".dll");
            // Assert.Contains(prjReferencedAssemblies.Select(e => e.Name), secondModuleName + ".dll");

            mocks.VerifyAll();
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
0
 public void TearDown()
 {
     // ToDo: Implement TearDown logic here
     this.testObject = null;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Runs the worker asynchronous.
        /// </summary>
        /// <param name="runnerData">The runner data.</param>
        public void RunWorkerAsync(
            GeneratorRunnerData runnerData, ICodeGeneratorSetup codegeneratorSetup)
        {
            // Dumper();
            // GenerateTests();
            this.BeforeGenerateTests();

            var bg = new BackgroundWorker();
            bg.DoWork += this.WorkerDoWork;
            bg.RunWorkerCompleted += this.BgRunWorkerCompleted;

            // Type generatorType = (Type)cbGeneratorsSelectedItem;
            // IList<TreeNode> mainNodes = assemblyGraph.Nodes.Cast<TreeNode>().ToList();
            // var runnerData = new GeneratorRunnerData(outputFolder, generatorType, inputAssemblyPath, mainNodes.MapToNodes(), referencedAssemblies);

            var parameters = new object[] { runnerData, codegeneratorSetup};
            bg.RunWorkerAsync(parameters);
        }
Ejemplo n.º 16
0
        public void GenerateWithAssemblyAndModuleAndClassNotChecked()
        {
            //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 = false
            };
            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(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData           = new GeneratorRunnerData(
                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           codeGenerator          = mocks.StrictMock <ICodeGenerator>();
            CodeNamespace generatorCodeNamespace = null;

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

                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(prjReferencedAssemblies);

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

            mocks.VerifyAll();
        }
Ejemplo n.º 17
0
        public void GenerateWithAssemblyAndModuleAndClass()
        {
            //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  className1         = "The.Namespace.VeryPrettyFactory";
            var  classTag           = "ClassTag";

            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(className1, TestNodeType.Class, classTag)
            {
                Checked = true
            };

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

            var referencedAssemblies = typeof(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData           = new GeneratorRunnerData(
                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>();

            Expect.Call(createGeneratorCallback(sbs, null, null))
            //.Constraints(Is.Same(sbs), Is.TypeOf<CodeGeneratorParameters>(), Is.TypeOf<CodeNamespace>())
            .Constraints(
                Is.Same(sbs),
                Is.TypeOf <CodeGeneratorParameters>() && Property.Value("OutputDirectory", expectedDirectory),
                Is.TypeOf <CodeNamespace>())
            .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(prjReferencedAssemblies);
            Assert.IsNotEmpty(classFilesList);

            mocks.VerifyAll();
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Generates the tests.
 /// </summary>
 /// <param name="data">The data that is necessary for test building.</param>
 public void GenerateTests(GeneratorRunnerData data)
 {
     Guard.NotNull(() => data, data);
     this.GenerateTests(
         data.OutputFolder, data.GeneratorType, data.InputAssemblyPath, data.RootNodes, data.ReferencedAssemblies);
 }
Ejemplo n.º 19
0
        public void GenerateWithAssemblyAndModuleAndClassNotChecked()
        {
            //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 = false };
            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(GeneratorRunnerDataTest).Assembly.GetReferencedAssemblies();
            var runnerData = new GeneratorRunnerData(
                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 codeGenerator = mocks.StrictMock<ICodeGenerator>();
            CodeNamespace generatorCodeNamespace = null;

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

                    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(prjReferencedAssemblies);

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

            mocks.VerifyAll();
        }