示例#1
0
        protected override void DoExecute(string playground)
        {
            TestLocaldb.Execute("sqllocaldb.exe", "stop v11.0");
            TestLocaldb.Execute("sqllocaldb.exe", "start v11.0");

            var dbName = "Northwind-" + Guid.NewGuid();

            mDatabaseFileName    = Path.Combine(playground, dbName + ".mdf");
            mDatabaseLogFileName = Path.Combine(playground, dbName + "_log.ldf");
            mTemplatesPath       = Path.Combine(playground, "Templates");

            // setup database
            NorthwindUtility.Create(dbName, mDatabaseFileName, mDatabaseLogFileName);
            var gettingStartedPath = Path.Combine(playground, "Pack");

            Directory.CreateDirectory(gettingStartedPath);

            // unpack sapmle pack to <Playground>\GettingStartedPack
            SamplePacksUtility.ExtractSampleCSharpSQLServerXmlTo(gettingStartedPath);
            var templateBaseDir = Path.Combine(playground, "Pack", "Sample_CSharp_SQLServer_MySQL_Xml", "Templates", "CSharp_VS2012");

            var solutionDesigner = new DesignerViewModel();
            var builder          = new BuilderViewModel();

            var solutionVM = NewSolution(builder,
                                         solutionDesigner,
                                         "TestSolution",
                                         "TestNamespace",
                                         "TestSolution.sln",
                                         "TestCompany",
                                         "TestProduct",
                                         "0.1",
                                         Path.Combine(playground, "TestSolution.xml"),
                                         Path.Combine(templateBaseDir, "SolutionFile.mpt"));

            NewDatabaseSource(builder,
                              solutionDesigner,
                              solutionVM,
                              @"(localdb)\v11.0",
                              mDatabaseFileName,
                              Path.Combine(gettingStartedPath, @"Sample_CSharp_SQLServer_MySQL_Xml\Specifications\SQLServer\MDLSqlModel.mps"));

            Assert.AreEqual(1, solutionVM.Solution.DatabaseSourceList.Count);

            var efbllProj = CreateNewProject(solutionVM,
                                             solutionDesigner,
                                             "EFBLL",
                                             "EFBLL",
                                             null,
                                             null,
                                             Path.Combine(templateBaseDir, "Project", "EntityFramework.mpt"),
                                             "BLL");

            Assert.AreEqual(1, solutionVM.Solution.DatabaseSourceList.Count);
            Assert.AreEqual(1, solutionVM.Solution.ProjectList.Count);

            var efdsProj = CreateNewProject(solutionVM,
                                            solutionDesigner,
                                            "EFDataServices",
                                            "EFDataServices",
                                            null,
                                            null,
                                            Path.Combine(templateBaseDir, "Project", "EFDataServices.mpt"),
                                            "DS");

            ReferenceProjects(solutionVM, efdsProj,
                              efbllProj.ProjectID);

            Assert.AreEqual(1, solutionVM.Solution.DatabaseSourceList.Count);
            Assert.AreEqual(2, solutionVM.Solution.ProjectList.Count);


            var vmProj = CreateNewProject(solutionVM,
                                          solutionDesigner,
                                          "ViewModels",
                                          "ViewModels",
                                          null,
                                          null,
                                          Path.Combine(templateBaseDir, "Project", "VMEFDS.mpt"),
                                          "VM");

            ReferenceProjects(solutionVM, vmProj,
                              efbllProj.ProjectID);

            Assert.AreEqual(1, solutionVM.Solution.DatabaseSourceList.Count);
            Assert.AreEqual(3, solutionVM.Solution.ProjectList.Count);

            var shellProj = CreateNewProject(solutionVM,
                                             solutionDesigner,
                                             "Shell",
                                             "Shell",
                                             null,
                                             null,
                                             Path.Combine(templateBaseDir, "Project", "WPFUI.mpt"),
                                             null);

            ReferenceProjects(solutionVM, shellProj,
                              vmProj.ProjectID);

            Assert.AreEqual(1, solutionVM.Solution.DatabaseSourceList.Count);
            Assert.AreEqual(4, solutionVM.Solution.ProjectList.Count);

            UpdateOutputSolution(solutionVM);

            Assert.IsTrue(File.Exists(Path.Combine(playground, "TestSolution.sln")), "Solution file has not been created!");
            Console.WriteLine("Calling MSBuild now");
            MSBuildUtility.Execute(Path.Combine(playground, "TestSolution.sln"),
                                   multiThreaded: true);
            Console.WriteLine("TEst finished for now");
        }
        protected override void DoExecute(string playground)
        {
            TestLocaldb.Execute("sqllocaldb.exe", "stop v11.0");
            TestLocaldb.Execute("sqllocaldb.exe", "start v11.0");

            var dbName = "Northwind-" + Guid.NewGuid();

            mDatabaseFileName    = Path.Combine(playground, dbName + ".mdf");
            mDatabaseLogFileName = Path.Combine(playground, dbName + "_log.ldf");
            mTemplatesPath       = Path.Combine(playground, "Templates");

            // setup database
            NorthwindUtility.Create(dbName, mDatabaseFileName, mDatabaseLogFileName);
            var gettingStartedPath = Path.Combine(playground, "GettingStartedPack");

            Directory.CreateDirectory(gettingStartedPath);

            // unpack sapmle pack to <Playground>\GettingStartedPack
            SamplePacksUtility.ExtractGettingStartedTo(gettingStartedPath);

            var solutionDesigner = new DesignerViewModel();
            var builder          = new BuilderViewModel();
            var solutionVM       = NewSolution(builder,
                                               solutionDesigner,
                                               "TestSolution",
                                               "TestNamespace",
                                               "TestSolution.sln",
                                               "TestCompany",
                                               "TestProduct",
                                               "0.1",
                                               Path.Combine(playground, "TestSolution.xml"),
                                               Path.Combine(playground, Path.Combine(playground, "NorthwindSolutionFile.mpt")));

            solutionVM.Solution.OutputRequested += SolutionOnOutputRequested;

            #region create solution template
            if (solutionVM.CodeTemplatesFolder == null)
            {
                throw new InvalidOperationException("Couldn't find CodeTemplatesFolder");
            }

            solutionVM.CodeTemplatesFolder.ProcessNewCodeTemplateCommand();
            var newSolTpl        = new CodeTemplateViewModel();
            var solutionTemplate = solutionDesigner.SelectedItem as CodeTemplateViewModel ?? newSolTpl;
            Assert.AreNotSame(solutionTemplate, newSolTpl, "Couldn't find template!");

            solutionTemplate.TemplateName       = "NorthwindSolutionFile";
            solutionTemplate.IsTopLevelTemplate = true;
            solutionTemplate.TemplateOutput     = "<%%=Solution.SolutionDirectory%%><%%-\\%%><%%=Solution.OutputSolutionFileName%%>\r\n" +
                                                  "<%%:\r\n" +
                                                  "    update(Path)\r\n" +
                                                  "%%>";
            solutionTemplate.TemplateContent = "<%%-Entities:\r\n" +
                                               "%%><%%:\r\n" +
                                               "foreach(Entity)\r\n" +
                                               "{\r\n" +
                                               "    <%%- - %%><%%=Feature.FeatureName%%><%%--%%><%%=Entity.EntityName%%><%%-\r\n" +
                                               "%%>\r\n" +
                                               "}%%>";
            solutionTemplate.Update();
            solutionVM.TemplatePath = Path.Combine(playground, Path.Combine(playground, "NorthwindSolutionFile.mpt"));
            SaveSolution(solutionVM);
            solutionVM.CodeTemplatesFolder.LoadTemplates(solutionVM.Solution);

            #endregion create solution template

            NewDatabaseSource(builder,
                              solutionDesigner,
                              solutionVM,
                              @"(localdb)\v11.0",
                              mDatabaseFileName,
                              Path.Combine(gettingStartedPath, @"GettingStarted\Specifications\SQLServer\MDLSqlModel.mps"));

            BuildSolution(solutionVM);

            UpdateOutputSolution(solutionVM);

            var expectedOutput = "Entities:\r\n" +
                                 " - Domain-Category\r\n" +
                                 " - Domain-CustomerCustomerDemo\r\n" +
                                 " - Domain-CustomerDemographic\r\n" +
                                 " - Domain-Customer\r\n" +
                                 " - Domain-Employee\r\n" +
                                 " - Domain-EmployeeTerritory\r\n" +
                                 " - Domain-OrderDetail\r\n" +
                                 " - Domain-Order\r\n" +
                                 " - Domain-Product\r\n" +
                                 " - Domain-Region\r\n" +
                                 " - Domain-Shipper\r\n" +
                                 " - Domain-Supplier\r\n" +
                                 " - Domain-Territory\r\n";
            var output = File.ReadAllText(Path.Combine(playground, "TestSolution.sln"));
            Assert.AreEqual(expectedOutput, output);
        }