예제 #1
0
        public async Task UpdateOutputFilesMovesPreviouslyCreatedItemToTargetProject()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                // Generate output file in the source project
                Project sourceProject = this.input.ContainingProject;
                this.output.Project   = sourceProject.FullName;
                this.output.Directory = this.folder.FileNames[1];
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                // Create a new project in the same directory
                string projectTemplate = Solution.GetProjectTemplate(this.TargetProject.Template, this.TargetProject.Language);
                string projectName     = Path.GetRandomFileName();
                string projectFolder   = Path.GetDirectoryName(sourceProject.FullName);
                Solution.AddFromTemplate(projectTemplate, projectFolder, projectName);
                Project targetProject = Solution.Projects.Cast <Project>().Single(project => project.Name == projectName);

                // Re-generate output in the target project
                this.output.Project = targetProject.FullName;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                // Verify that the output file was moved from the source project to the target project
                Assert.IsFalse(this.folder.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
                ProjectItem targetFolder = targetProject.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.folder.Name);
                Assert.IsTrue(targetFolder.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
 public void TestInitialize()
 {
     UIThreadDispatcher.Invoke(delegate
     {
         this.project  = this.CreateTestProject();
         this.provider = (ITransformationContextProvider)ServiceProvider.GetService(typeof(ITransformationContextProvider));
     });
 }
예제 #3
0
 public async Task UpdateOutputFilesDoesNotStoreNameOfDefaultOutputTwice()
 {
     await UIThreadDispatcher.Invoke <Task>(async delegate
     {
         this.output.File = string.Empty;
         this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
         await this.SimulateCustomTool();
         Assert.AreEqual(string.Empty, this.input.GetItemAttribute(ItemMetadata.LastOutputs));
     });
 }
예제 #4
0
 public async Task UpdateOutputFilesCreatesNewProjectItemInProjectSpecifiedAsPathRelativeToInputFile()
 {
     await UIThreadDispatcher.Invoke <Task>(async delegate
     {
         this.output.Project = FileMethods.GetRelativePath(this.input.FileNames[1], this.project.FullName);
         this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
         await this.SimulateCustomTool();
         Assert.IsTrue(this.project.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
     });
 }
예제 #5
0
        public async Task UpdateOutputFilesCreatesNewProjectItemWithSpecifiedFile()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputItem = this.input.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.output.File);
                Assert.AreEqual(this.output.Content.ToString(), File.ReadAllText(outputItem.FileNames[1]));
            });
        }
예제 #6
0
 public async Task UpdateOutputFilesConfiguresDefaultOutputCreatedAfterTransformation()
 {
     await UIThreadDispatcher.Invoke <Task>(async delegate
     {
         this.output.File     = string.Empty;
         this.output.ItemType = ItemType.Content;
         this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
         ProjectItem outputItem = await this.SimulateCustomTool();
         Assert.AreEqual(this.output.ItemType, outputItem.Properties.Item(ProjectItemProperty.ItemType).Value);
     });
 }
예제 #7
0
        public async Task UpdateOutputFilesCreatesNewProjectItemInDirectorySpecifiedAsPathRelativeToInputFile()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.Directory = Path.GetRandomFileName();
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputFolder = this.folder.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.output.Directory);
                Assert.IsTrue(outputFolder.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
예제 #8
0
        public async Task UpdateOutputFilesConfiguresDefaultOutputItemWithSpecifiedCustomToolNamespace()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.File = string.Empty;
                this.output.CustomToolNamespace = "T4Toolbox";
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });

                ProjectItem outputItem = await this.SimulateCustomTool();
                Assert.AreEqual(this.output.CustomToolNamespace, outputItem.Properties.Item(ProjectItemProperty.CustomToolNamespace).Value);
            });
        }
예제 #9
0
        public async Task UpdateOutputFilesCreatesDefaultOutputItemWithSpecifiedMetadata()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.File = string.Empty;
                this.output.Metadata["Marco"] = "Polo";
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });

                ProjectItem outputItem = await this.SimulateCustomTool();
                Assert.AreEqual("Polo", outputItem.GetItemAttribute("Marco"));
            });
        }
예제 #10
0
        public async Task UpdateOutputFilesReportsErrorWhenReferenceCannotBeAdded()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.References.Add("InvalidAssemblyName");
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ErrorItem error = IntegrationTest.ErrorItems.Single(item => item.FileName == this.input.FileNames[1]);
                StringAssert.Contains(error.Description, this.output.References.Single());
            });
        }
예제 #11
0
        public async Task UpdateOutputFilesConfiguresDefaultOutputItemWithSpecifiedCopyToOutputDirectory()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.File = string.Empty;
                this.output.CopyToOutputDirectory = CopyToOutputDirectory.CopyAlways;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });

                ProjectItem outputItem = await this.SimulateCustomTool();
                Assert.AreEqual((uint)this.output.CopyToOutputDirectory, outputItem.Properties.Item(ProjectItemProperty.CopyToOutputDirectory).Value);
            });
        }
예제 #12
0
        public async Task UpdateOutputFilesCreatesProjectItemWithSpecifiedCustomToolNamespace()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.CustomToolNamespace = "T4Toolbox";
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputItem = this.input.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.output.File);
                Assert.AreEqual(this.output.CustomToolNamespace, outputItem.Properties.Item(ProjectItemProperty.CustomToolNamespace).Value);
            });
        }
예제 #13
0
        public async Task UpdateOutputFilesCreatesProjectItemWithSpecifiedCopyToOutputDirectory()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.CopyToOutputDirectory = CopyToOutputDirectory.CopyAlways;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputItem = this.input.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.output.File);
                Assert.AreEqual((uint)this.output.CopyToOutputDirectory, outputItem.Properties.Item(ProjectItemProperty.CopyToOutputDirectory).Value);
            });
        }
예제 #14
0
 public async Task UpdateOutputFilesDoesNotGenerateWarningWhenDefaultOutputFileIsEmpty() // Because there may be nothing developer can do about it
 {
     await UIThreadDispatcher.Invoke <Task>(async delegate
     {
         this.output.File = string.Empty;
         this.output.Content.Clear();
         this.output.Content.Append(WhiteSpaceText);
         this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
         await this.SimulateCustomTool();
         Assert.IsFalse(ErrorItems.Any(item => item.FileName == this.input.FileNames[1]));
     });
 }
예제 #15
0
 public async Task UpdateOutputFilesGeneratesWarningWhenAdditionalOutputFileIsEmpty() // To encourage developer to cleanup their code generator
 {
     await UIThreadDispatcher.Invoke <Task>(async delegate
     {
         this.output.Content.Clear();
         this.output.Content.Append(WhiteSpaceText);
         this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
         await this.SimulateCustomTool();
         ErrorItem warning = ErrorItems.Single(item => item.FileName == this.input.FileNames[1]);
         StringAssert.Contains(warning.Description, this.output.Path);
         Assert.AreEqual(vsBuildErrorLevel.vsBuildErrorLevelMedium, warning.ErrorLevel);
     });
 }
예제 #16
0
        public async Task UpdateOutputFilesDeletesPreviouslyCreatedFileThatWasNotRecreated()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                this.provider.UpdateOutputFiles(this.input.FileNames[1], new OutputFile[0]);
                await this.SimulateCustomTool();

                Assert.IsFalse(this.input.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
        public TemplateErrorReporterTest()
        {
            UIThreadDispatcher.Invoke(delegate
            {
                var componentModel = (IComponentModel)ServiceProvider.GetService(typeof(SComponentModel));

                // Use Text content type to test in isolation from TemplateErrorTaggerProvider
                var contentTypeRegistry = componentModel.DefaultExportProvider.GetExportedValue <IContentTypeRegistryService>();
                this.textContentType    = contentTypeRegistry.GetContentType("Text");

                this.documentFactory = componentModel.DefaultExportProvider.GetExportedValue <ITextDocumentFactoryService>();
            });
        }
예제 #18
0
        public async Task UpdateOutputFilesStoresRelativePathsOfGeneratedFiles()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.Directory = Path.GetRandomFileName();
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                string lastGenOutput = this.input.GetItemAttribute(ItemMetadata.LastOutputs);
                Assert.AreEqual(this.output.Path, lastGenOutput.TrimStart('.', '\\'));
                Assert.IsFalse(Path.IsPathRooted(lastGenOutput));
            });
        }
예제 #19
0
        public async Task UpdateOutputFilesConfiguresReferencesOfOutputItem()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.References.Add("System.Web");
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                var project         = (VSProject)this.project.Object;
                Reference reference = project.References.Find(this.output.References.Single());
                Assert.IsNotNull(reference);
                reference.Remove();
            });
        }
예제 #20
0
        public async Task UpdateOutputFilesDoesNotDeletePreviouslyCreatedFileWhenPreserveExistingFileIsTrue()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.PreserveExistingFile = true;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                this.provider.UpdateOutputFiles(this.input.FileNames[1], new OutputFile[0]);
                await this.SimulateCustomTool();

                Assert.IsTrue(this.input.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
예제 #21
0
        public async Task UpdateOutputFilesCreatesProjectItemWithSpecifiedEncoding()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                this.output.Encoding = Encoding.UTF32;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputItem = this.input.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.output.File);
                byte[] preamble        = this.output.Encoding.GetPreamble();
                byte[] contents        = File.ReadAllBytes(outputItem.FileNames[1]);
                Assert.IsTrue(preamble.Length > 0);
                CollectionAssert.AreEqual(preamble, contents.Take(preamble.Length).ToArray());
            });
        }
예제 #22
0
        public async Task UpdateOutputFilesCreatesNewProjectItemInAbsoluteDirectoryOfTargetProject()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                string directoryName  = Path.GetRandomFileName();
                this.output.Directory = Path.Combine(Path.GetDirectoryName(this.project.FullName), directoryName);
                this.output.Project   = this.project.FullName;

                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputFolder = this.project.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == directoryName);
                Assert.IsTrue(outputFolder.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
예제 #23
0
        public async Task UpdateOutputFilesDoesNotOverwriteExistingFileWhenPreserveExistingFileIsTrue()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                const string ExistingContent = "Existing Content";
                string outputFilePath        = Path.Combine(Path.GetDirectoryName(this.input.FileNames[1]), this.output.File);
                File.WriteAllText(outputFilePath, ExistingContent);

                this.output.PreserveExistingFile = true;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                ProjectItem outputItem = this.input.ProjectItems.Cast <ProjectItem>().Single(item => item.Name == this.output.File);
                Assert.AreEqual(ExistingContent, File.ReadAllText(outputItem.FileNames[1]));
            });
        }
예제 #24
0
        public async Task UpdateOutputFilesMovesPreviouslyCreatedItemToTheSpecifiedDirectory()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                // Create output file nested under the input file
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                // Now regenerate the file, this time specifying Directory
                this.output.Directory = Path.GetDirectoryName(this.input.FileNames[1]);
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                // The output file path hasn't changed, however, it should be moved from the input's collection to the folder's collection
                Assert.IsTrue(this.folder.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
예제 #25
0
        public async Task UpdateOutputFilesConfiguresDefaultOutputCreatedBeforeTransformation()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                // Default output was created by previous transformation
                ProjectItem outputItem = await this.SimulateCustomTool();

                // New transformation generates the file with the same extension
                this.SimulateTransformation();
                this.output.File     = string.Empty;
                this.output.ItemType = ItemType.EmbeddedResource;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                // Verify that output item was configured
                Assert.AreEqual(this.output.ItemType, outputItem.Properties.Item(ProjectItemProperty.ItemType).Value);
            });
        }
예제 #26
0
        public async Task UpdateOutputFilesAutomaticallyReloadsOpenDocumentsFromDisk()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                // Output file already exists and it is opened in text editor
                string outputFilePath  = Path.Combine(Path.GetDirectoryName(this.input.FileNames[1]), this.output.File);
                ProjectItem outputItem = IntegrationTest.CreateTestProjectItemFromFile(this.input.ProjectItems, outputFilePath);
                Window window          = outputItem.Open(Constants.vsViewKindTextView);

                // Code generation occurs
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();

                // Verify that document text has been reloads generated document from disk
                var textDocument = (TextDocument)window.Document.Object();
                textDocument.Selection.StartOfDocument(Extend: true);
                textDocument.Selection.EndOfDocument(Extend: true);
                Assert.AreEqual(this.output.Content.ToString(), textDocument.Selection.Text);
            });
        }
예제 #27
0
        public void TestInitialize()
        {
            UIThreadDispatcher.Invoke(delegate
            {
                this.templatingService = (ITextTemplating)ServiceProvider.GetService(typeof(STextTemplating));
                this.templatingHost    = (ITextTemplatingEngineHost)this.templatingService;
                this.provider          = (ITransformationContextProvider)ServiceProvider.GetService(typeof(ITransformationContextProvider));

                this.project = this.CreateTestProject();
                this.folder  = this.project.ProjectItems.AddFolder(Path.GetRandomFileName());
                this.input   = this.CreateTestProjectItem(this.folder.ProjectItems, TextFileItemTemplate);

                this.output = new OutputFile {
                    File = Path.GetRandomFileName() + ".txt"
                };
                this.output.Content.Append(TestText);

                this.SimulateTransformation();
            });
        }
예제 #28
0
        public async Task UpdateOutputFilesConfiguresDefaultOutputRecreatedAfterTransformation()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                // Default output was created by previous transformation
                await this.SimulateCustomTool();

                // New transformation changes extension of the default output
                this.SimulateTransformation();
                this.templatingHost.SetFileExtension("new");

                this.output.File     = string.Empty;
                this.output.ItemType = ItemType.Content;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                ProjectItem outputItem = await this.SimulateCustomTool();

                // Verify that output item was configured
                Assert.AreEqual(this.output.ItemType, outputItem.Properties.Item(ProjectItemProperty.ItemType).Value);
            });
        }
예제 #29
0
        public async Task UpdateOutputFilesCreatesNewProjectItemInTargetProjectLocatedInSolutionFolder()
        {
            await UIThreadDispatcher.Invoke <Task>(async delegate
            {
                // Create a new solution folder
                Project solutionFolderProject = Solution.AddSolutionFolder(Path.GetRandomFileName());
                var solutionFolder            = (SolutionFolder)solutionFolderProject.Object;

                // Create a new project in the solution folder
                string projectTemplate = Solution.GetProjectTemplate(this.TargetProject.Template, this.TargetProject.Language);
                string projectName     = Path.GetRandomFileName();
                string projectFolder   = Path.Combine(SolutionDirectory, projectName);
                solutionFolder.AddFromTemplate(projectTemplate, projectFolder, projectName);
                Project project = solutionFolderProject.ProjectItems.Item(1).SubProject;

                // Generate output file in the new project
                this.output.Project = project.FullName;
                this.provider.UpdateOutputFiles(this.input.FileNames[1], new[] { this.output });
                await this.SimulateCustomTool();
                Assert.IsTrue(project.ProjectItems.Cast <ProjectItem>().Any(item => item.Name == this.output.File));
            });
        }
예제 #30
0
            public void InvokeUIThread(DispatcherPriority priority, Action action)
            {
                if (this.CancellationPending)
                {
                    return;
                }
                UIThreadDispatcher dispatcher = this.UIThreadDispatcher;

                if (dispatcher == null)
                {
                    return;
                }
                dispatcher.Invoke(priority, (Action)(() =>
                {
                    dispatcher = this.UIThreadDispatcher;
                    if (dispatcher == null || this.CancellationPending)
                    {
                        return;
                    }
                    action();
                }));
            }