public async Task CreateFile_NullParentNode_ThrowsArgumentNull()
        {
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Create();
            var service           = new CreateFileFromTemplateService(projectVsServices);

            await Assert.ThrowsAsync <ArgumentNullException>("parentNode", async() =>
            {
                await service.CreateFileAsync("SomeFile", null, null);
            });
        }
        public async Task CreateFile_NullFileName_ThrowsArgumentNull()
        {
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Create();
            var service           = new CreateFileFromTemplateService(projectVsServices);

            await Assert.ThrowsAsync <ArgumentNullException>("fileName", async() =>
            {
                await service.CreateFileAsync("SomeFile", ProjectTreeParser.Parse("Properties"), null);
            });
        }
        public async Task CreateFile(string input, string templateFilePath, bool expectedResult)
        {
            string templateName = "SettingsInternal.zip";
            string fileName     = "Settings.settings";
            var    inputTree    = ProjectTreeParser.Parse(input);

            var hierarchy = IVsHierarchyFactory.Create();
            var solution  = SolutionFactory.CreateWithGetProjectItemTemplate((templateFile, language) =>
            {
                Assert.Equal(templateName, templateFile);
                return(templateFilePath);
            });

            var project = ProjectFactory.CreateWithSolution(solution);

            ProjectFactory.ImplementCodeModelLanguage(project, CodeModelLanguageConstants.vsCMLanguageCSharp);

            hierarchy.ImplementGetProperty(Shell.VsHierarchyPropID.ExtObject, project);

            var vsProject = (IVsProject4)hierarchy;

            vsProject.ImplementAddItemWithSpecific((itemId, itemOperation, itemName, files, result) =>
            {
                Assert.Equal(inputTree.IsRoot() ? (uint)VSConstants.VSITEMID.Root : (uint)inputTree.Identity, itemId);
                Assert.Equal(VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD, itemOperation);
                Assert.Equal(fileName, itemName);
                Assert.Equal(new string[] { templateFilePath }, files);

                result[0] = expectedResult ? VSADDRESULT.ADDRESULT_Success : VSADDRESULT.ADDRESULT_Failure;

                return(VSConstants.S_OK);
            });

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => vsProject);
            var service           = new CreateFileFromTemplateService(projectVsServices);

            bool returnValue = await service.CreateFileAsync(templateName, inputTree, fileName);

            Assert.Equal(returnValue, expectedResult);
        }
Ejemplo n.º 4
0
        public async Task CreateFile(string input, string templateFilePath, bool expectedResult)
        {
            string templateName = "SettingsInternal.zip";
            string fileName     = "Settings.settings";
            var    inputTree    = ProjectTreeParser.Parse(input);

            var hierarchy = IVsHierarchyFactory.Create();
            var solution  = SolutionFactory.CreateWithGetProjectItemTemplate((templateFile, language) =>
            {
                Assert.Equal(templateName, templateFile);
                return(templateFilePath);
            });


            var vsProject = (IVsProject4)IVsHierarchyFactory.Create();

            vsProject.ImplementAddItemWithSpecific((itemId, itemOperation, itemName, files, result) =>
            {
                Assert.Equal((uint)inputTree.GetHierarchyId(), itemId);
                Assert.Equal(VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD, itemOperation);
                Assert.Equal(fileName, itemName);
                Assert.Equal(new string[] { templateFilePath }, files);

                result[0] = expectedResult ? VSADDRESULT.ADDRESULT_Success : VSADDRESULT.ADDRESULT_Failure;

                return(VSConstants.S_OK);
            });

            var dteServices = IDteServicesFactory.ImplementSolution(() => solution);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => vsProject);
            var properties        = CreateProperties();
            var service           = new CreateFileFromTemplateService(projectVsServices, dteServices, properties);

            bool returnValue = await service.CreateFileAsync(templateName, inputTree, fileName);

            Assert.Equal(returnValue, expectedResult);
        }