private void RefactorRenameTest(string projectName, Action <EntityDesignArtifact, CommandProcessorContext, object> test)
        {
            var modelEdmxFilePath = Path.Combine(TestContext.DeploymentDirectory, @"TestData\Model\v3\PubSimple.edmx");
            var dte             = VsIdeTestHostContext.Dte;
            var serviceProvider = VsIdeTestHostContext.ServiceProvider;

            UITestRunner.Execute(
                () =>
            {
                EntityDesignArtifact entityDesignArtifact = null;
                try
                {
                    var project = dte.CreateProject(
                        TestContext.TestRunDirectory,
                        projectName,
                        DteExtensions.ProjectKind.Executable,
                        DteExtensions.ProjectLanguage.CSharp);

                    var projectItem = dte.AddExistingItem(new FileInfo(modelEdmxFilePath).FullName, project);
                    dte.OpenFile(projectItem.FileNames[0]);
                    entityDesignArtifact =
                        (EntityDesignArtifact) new EFArtifactHelper(EFArtifactHelper.GetEntityDesignModelManager(serviceProvider))
                        .GetNewOrExistingArtifact(TestUtils.FileName2Uri(projectItem.FileNames[0]));

                    var editingContext =
                        _package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(entityDesignArtifact.Uri);
                    var cpc = new CommandProcessorContext(
                        editingContext, "DiagramTest" + projectName, "DiagramTestTxn" + projectName, entityDesignArtifact);

                    var programDocData = VSHelpers.GetDocData(
                        serviceProvider, Path.Combine(Path.GetDirectoryName(project.FullName), "Program.cs"));
                    Debug.Assert(programDocData != null, "Could not get DocData for program file");

                    var textLines = VSHelpers.GetVsTextLinesFromDocData(programDocData);
                    Debug.Assert(textLines != null, "Could not get VsTextLines for program DocData");

                    VsUtils.SetTextForVsTextLines(textLines, string.Format(PubSimpleProgramText, projectName));
                    test(entityDesignArtifact, cpc, programDocData);
                }
                catch (Exception ex)
                {
                    TestContext.WriteLine(ex.ToString());
                    throw;
                }
                finally
                {
                    if (entityDesignArtifact != null)
                    {
                        entityDesignArtifact.Dispose();
                    }

                    dte.CloseSolution(false);
                }
            });
        }
Пример #2
0
        private void ChangeEntityTypesFillColorTest(
            string projectName, Color fillColor, Action <EntityDesignArtifact, CommandProcessorContext> runTest)
        {
            var modelPath = Path.Combine(TestContext.DeploymentDirectory, @"TestData\Model\v3\PubSimple.edmx");

            UITestRunner.Execute(TestContext.TestName,
                                 () =>
            {
                EntityDesignArtifact entityDesignArtifact = null;
                Project project = null;
                try
                {
                    project = Dte.CreateProject(
                        TestContext.TestRunDirectory,
                        projectName,
                        DteExtensions.ProjectKind.Executable,
                        DteExtensions.ProjectLanguage.CSharp);

                    var projectItem = Dte.AddExistingItem(modelPath, project);
                    Dte.OpenFile(projectItem.FileNames[0]);

                    entityDesignArtifact =
                        (EntityDesignArtifact) new EFArtifactHelper(EFArtifactHelper.GetEntityDesignModelManager(ServiceProvider))
                        .GetNewOrExistingArtifact(TestUtils.FileName2Uri(projectItem.FileNames[0]));

                    var editingContext =
                        _package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(entityDesignArtifact.Uri);
                    var commandProcessorContext = new CommandProcessorContext(
                        editingContext, "DiagramTest", "DiagramTestTxn", entityDesignArtifact);

                    foreach (var ets in entityDesignArtifact.DesignerInfo.Diagrams.FirstDiagram.EntityTypeShapes)
                    {
                        CommandProcessor.InvokeSingleCommand(
                            commandProcessorContext, new UpdateDefaultableValueCommand <Color>(ets.FillColor, fillColor));
                    }

                    runTest(entityDesignArtifact, commandProcessorContext);
                }
                finally
                {
                    if (entityDesignArtifact != null)
                    {
                        entityDesignArtifact.Dispose();
                    }

                    if (project != null)
                    {
                        Dte.CloseSolution(false);
                    }
                }
            });
        }
Пример #3
0
        private void ExecuteMigrateDiagramNodesTest(string projectName, Action <EntityDesignArtifact, CommandProcessorContext> runTest)
        {
            var modelPath = Path.Combine(TestContext.DeploymentDirectory, @"TestData\Model\v3\PubSimple.edmx");

            UITestRunner.Execute(
                () =>
            {
                EntityDesignArtifact entityDesignArtifact = null;
                Project project = null;

                try
                {
                    project = Dte.CreateProject(
                        TestContext.TestRunDirectory,
                        projectName,
                        DteExtensions.ProjectKind.Executable,
                        DteExtensions.ProjectLanguage.CSharp);

                    var projectItem = Dte.AddExistingItem(modelPath, project);
                    Dte.OpenFile(projectItem.FileNames[0]);

                    entityDesignArtifact =
                        (EntityDesignArtifact) new EFArtifactHelper(EFArtifactHelper.GetEntityDesignModelManager(ServiceProvider))
                        .GetNewOrExistingArtifact(TestUtils.FileName2Uri(projectItem.FileNames[0]));

                    Debug.Assert(entityDesignArtifact != null);
                    var editingContext =
                        _package.DocumentFrameMgr.EditingContextManager.GetNewOrExistingContext(entityDesignArtifact.Uri);

                    // Create TransactionContext to indicate that the transactions are done from first diagram.
                    // This is not used by MigrateDiagramInformationCommand but other commands in the callback methods.
                    var transactionContext = new EfiTransactionContext();
                    transactionContext.Add(
                        EfiTransactionOriginator.TransactionOriginatorDiagramId,
                        new DiagramContextItem(entityDesignArtifact.DesignerInfo.Diagrams.FirstDiagram.Id.Value));

                    var commandProcessorContext =
                        new CommandProcessorContext(
                            editingContext, "MigrateDiagramNodesTest", projectName + "Txn", entityDesignArtifact, transactionContext);
                    MigrateDiagramInformationCommand.DoMigrate(commandProcessorContext, entityDesignArtifact);

                    Debug.Assert(entityDesignArtifact.DiagramArtifact != null);
                    Debug.Assert(
                        entityDesignArtifact.IsDesignerSafe,
                        "Artifact should not be in safe mode after MigrateDiagramInformationCommand is executed.");
                    Debug.Assert(
                        new Uri(entityDesignArtifact.Uri.LocalPath + EntityDesignArtifact.EXTENSION_DIAGRAM)
                        == entityDesignArtifact.DiagramArtifact.Uri);

                    runTest(entityDesignArtifact, commandProcessorContext);
                }
                finally
                {
                    if (entityDesignArtifact != null)
                    {
                        entityDesignArtifact.Dispose();
                    }

                    if (project != null)
                    {
                        Dte.CloseSolution(false);
                    }
                }
            });
        }