public void InitTestContext() { ruleT1 = new TestRuleT1(); ruleT2 = new TestRuleT2(); ruleTN = new TestRuleTN(); baseT1 = new BaseTestRuleT1(); baseT2 = new BaseTestRuleT2(); baseTN = new BaseTestRuleTN(); transformation = new TestTransformation(this); }
//[DataRow(@"SdkProject\")] public async Task Plugin012CanProduceCodeFileCompileTrgetProjectsAndUnitTestThem(string prType) { var slnFolder = @"..\..\..\..\TestApps\" + prType; var slnPath = slnFolder + "Solution.sln"; var cfgPath = slnFolder + "test1.vcfg"; var prjFolder = slnFolder + @"ConsoleApp1\"; var prjPath = prjFolder + "ConsoleApp1.csproj"; var genFolder = prjFolder + @"Generated\"; var genFile = "test_file.cs"; var vm = new MainPageVM(false); vm.OnFormLoaded(); vm.Compose(MainPageVM.GetvSharpStudioPluginsPath()); vm.Config.Name = "test1"; var gr = vm.Config.Model.GroupConstantGroups.AddGroupConstants("Gr"); var c1 = gr.NodeAddNewSubNode(); var c2 = gr.NodeAddNewSubNode(); vm.CommandConfigSaveAs.Execute(cfgPath); vm.Compose(MainPageVM.GetvSharpStudioPluginsPath()); var pluginNode = (from p in vm.Config.GroupPlugins.ListPlugins where p.VPlugin is vPlugin.Sample.SamplePlugin select p).Single(); var genDb = (IvPluginDbGenerator)(from p in pluginNode.ListGenerators where p.Generator is vPlugin.Sample.GeneratorDbSchema select p).Single().Generator; var genDbAccess = (IvPluginGenerator)(from p in pluginNode.ListGenerators where p.Generator is vPlugin.Sample.GeneratorDbAccess select p).Single().Generator; var sln = (AppSolution)vm.Config.GroupAppSolutions.NodeAddNewSubNode(); sln.RelativeAppSolutionPath = slnPath; Assert.AreEqual("Solution.sln", sln.RelativeAppSolutionPath); var prj = (AppProject)sln.NodeAddNewSubNode(); prj.RelativeAppProjectPath = prjPath; Assert.AreEqual(@"ConsoleApp1\ConsoleApp1.csproj", prj.RelativeAppProjectPath); var gen = (AppProjectGenerator)prj.NodeAddNewSubNode(); gen.PluginGuid = pluginNode.Guid; gen.PluginGeneratorGuid = genDbAccess.Guid; gen.RelativePathToGenFolder = genFolder; Assert.AreEqual(@"Generated\", gen.RelativePathToGenFolder); gen.GenFileName = genFile; string fpath = prj.GetCombinedPath(gen.GetGenerationFilePath()); File.WriteAllText(fpath, "namespace Test {}"); sln.Validate(); prj.Validate(); gen.Validate(); Assert.AreEqual(0, sln.ValidationCollection.Count); Assert.AreEqual(0, prj.ValidationCollection.Count); Assert.AreEqual(0, gen.ValidationCollection.Count); var prms = (vPlugin.Sample.GeneratorDbAccessSettings)gen.DynamicGeneratorSettings; prms.IsAccessParam1 = true; prms.IsAccessParam2 = false; prms.AccessParam3 = "test"; vm.CommandConfigSave.Execute(null); var genFilePath = genFolder + genFile; if (File.Exists(genFilePath)) { File.Delete(genFilePath); } // Can recognize not valid Config, SolutionPath is empty #region not valid Config // valid vm.Config.ValidateSubTreeFromNode(vm.Config); Assert.IsTrue(vm.Config.CountErrors == 0); // not valid sln.RelativeAppSolutionPath = null; vm.Config.ValidateSubTreeFromNode(); Assert.IsTrue(vm.Config.CountErrors > 0); //// valid //sln.RelativeAppSolutionPath = slnPath; //vm.Config.ValidateSubTreeFromNode(); //Assert.IsTrue(vm.Config.CountErrors == 0); TestTransformation tt = new TestTransformation(); tt.IsThrowExceptionOnBuildValidated = true; await vm.CommandConfigCurrentUpdate.ExecuteAsync(tt); Assert.IsTrue(vm.ProgressVM.Exception != null); Assert.IsTrue(vm.Config.CountErrors > 0); #endregion not valid Config #region valid Config sln.RelativeAppSolutionPath = slnPath; tt = new TestTransformation(); tt.IsThrowExceptionOnConfigValidated = true; await vm.CommandConfigCurrentUpdate.ExecuteAsync(tt); Assert.IsTrue(vm.ProgressVM.Exception != null); Assert.IsTrue(vm.ProgressVM.Exception.Message == nameof(tt.IsThrowExceptionOnConfigValidated)); Assert.IsTrue(vm.Config.CountErrors == 0); #endregion valid Config #region compilable code tt = new TestTransformation(); await vm.CommandConfigCurrentUpdate.ExecuteAsync(tt); Assert.IsTrue(vm.ProgressVM.Exception == null); #endregion compilable code // Can recognize exception before rename #region not compilable code tt = new TestTransformation(); tt.IsThrowExceptionOnBuildValidated = true; await vm.CommandConfigCurrentUpdate.ExecuteAsync(tt); Assert.IsTrue(vm.ProgressVM.Exception != null); Assert.IsTrue(vm.ProgressVM.Exception.Message == nameof(tt.IsThrowExceptionOnBuildValidated)); #endregion not compilable code // Exclude compilation process if there are no renames #region not compilable code tt = new TestTransformation(); File.WriteAllText(fpath, "wrong c# code"); await vm.CommandConfigCurrentUpdate.ExecuteAsync(tt); Assert.IsTrue(vm.ProgressVM.Exception == null); #endregion not compilable code // Include compilation process if there are renames #region not compilable code tt = new TestTransformation(); tt.IsThrowExceptionOnBuildValidated = true; await vm.CommandConfigCurrentUpdate.ExecuteAsync(tt); Assert.IsTrue(vm.ProgressVM.Exception != null); Assert.IsTrue(vm.ProgressVM.Exception.Message == nameof(tt.IsThrowExceptionOnBuildValidated)); #endregion not compilable code // Can rename // Can roll back if rename is fault //Assert.IsTrue(File.Exists(genFilePath)); // Can generate code //#region generate valid code //if (File.Exists(genFilePath)) // File.Delete(genFilePath); //prms.IsGenerateNotValidCode = false; ////vm.CommandConfigCurrentUpdate.ExecuteWithException(null); //vm.CommandConfigCurrentUpdate.Execute(null); //Assert.IsTrue(File.Exists(genFolder + genFile)); //#endregion generate valid code // Can recognize errors when compiling generated code // Can compile generated code // Can run unit test for generated code #region generate not valid code #endregion generate not valid code //Assert.IsTrue(false); }