Пример #1
0
        private EditProjectFileCommand CreateInstance(
            UnconfiguredProject unconfiguredProject = null,
            bool implementCapabilities       = true,
            IMsBuildAccessor msbuildAccessor = null,
            IFileSystem fileSystem           = null,
            ITextDocumentFactoryService textDocumentService      = null,
            IVsEditorAdaptersFactoryService editorAdapterService = null,
            IProjectThreadingService threadingService            = null,
            IVsShellUtilitiesHelper shellUtilities = null
            )
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var uProj        = unconfiguredProject ?? IUnconfiguredProjectFactory.Create();
            var capabilities = IProjectCapabilitiesServiceFactory.ImplementsContains(CapabilityChecker(implementCapabilities));
            var msbuild      = msbuildAccessor ?? IMsBuildAccessorFactory.Create();
            var fs           = fileSystem ?? new IFileSystemMock();
            var tds          = textDocumentService ?? ITextDocumentFactoryServiceFactory.Create();
            var eas          = editorAdapterService ?? IVsEditorAdaptersFactoryServiceFactory.Create();
            var threadServ   = threadingService ?? IProjectThreadingServiceFactory.Create();
            var shellUt      = shellUtilities ?? new TestShellUtilitiesHelper(
                (sp, path) => Tuple.Create(IVsHierarchyFactory.Create(), (uint)1, IVsPersistDocDataFactory.Create(), (uint)1),
                (sp, path, edType, logView) => IVsWindowFrameFactory.Create());

            return(new EditProjectFileCommand(uProj, capabilities, IServiceProviderFactory.Create(), msbuild, fs, tds, eas, threadServ, shellUt));
        }
Пример #2
0
        public async Task ShowProjectDesignerAsync_WhenWindowShowReturnsHResult_Throws()
        {
            Guid editorGuid = Guid.NewGuid();

            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetProperty(VsHierarchyPropID.SupportsProjectDesigner, result: true);
            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, result: editorGuid);
            var project = (IVsProject4)hierarchy;

            var frame = IVsWindowFrameFactory.ImplementShow(() => VSConstants.E_FAIL);

            project.ImplementOpenItemWithSpecific(editorGuid, VSConstants.LOGVIEWID_Primary, frame);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => project);

            var designerService = CreateInstance(projectVsServices);

#pragma warning disable RS0003 // Do not directly await a Task (see https://github.com/dotnet/roslyn/issues/6770)
            await Assert.ThrowsAsync <COMException>(() => {
                return(designerService.ShowProjectDesignerAsync());
            });

#pragma warning restore RS0003 // Do not directly await a Task
        }
Пример #3
0
        public async Task ShowProjectDesignerAsync_WhenOpenedInInternalEditor_ShowsWindow()
        {
            Guid editorGuid = Guid.NewGuid();

            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetProperty(VsHierarchyPropID.SupportsProjectDesigner, result: true);
            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, result: editorGuid);
            var project = (IVsProject4)hierarchy;

            int callCount = 0;
            var frame     = IVsWindowFrameFactory.ImplementShow(() => { callCount++; return(0); });

            project.ImplementOpenItemWithSpecific(editorGuid, VSConstants.LOGVIEWID_Primary, frame);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => project);

            var designerService = CreateInstance(projectVsServices);

#pragma warning disable RS0003 // Do not directly await a Task (see https://github.com/dotnet/roslyn/issues/6770)
            await designerService.ShowProjectDesignerAsync();

#pragma warning restore RS0003 // Do not directly await a Task

            Assert.Equal(1, callCount);
        }
Пример #4
0
        private EditProjectFileCommand SetupScenario(string projectXml, string tempPath, string tempProjectFile, string projectFile, string caption,
                                                     IFileSystemMock fileSystem, ITextDocument textDoc, IVsWindowFrame frame)
        {
            fileSystem.SetTempFile(tempPath);
            var configuredProject   = ConfiguredProjectFactory.Create();
            var unconfiguredProject = IUnconfiguredProjectFactory.Create(filePath: projectFile, configuredProject: configuredProject);
            var shellUtilities      = new TestShellUtilitiesHelper((sp, path) =>
            {
                Assert.Equal(tempProjectFile, path);
                return(Tuple.Create(IVsHierarchyFactory.Create(), (uint)0, IVsPersistDocDataFactory.ImplementAsIVsTextBuffer(), (uint)0));
            }, (sp, path, factoryGuid, logicalView) =>
            {
                Assert.Equal(tempProjectFile, path);
                Assert.Equal(XmlGuid, factoryGuid);
                Assert.Equal(Guid.Empty, logicalView);

                return(frame);
            });

            var textBuffer           = ITextBufferFactory.ImplementSnapshot(projectXml);
            var editorFactoryService = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);

            Mock.Get(textDoc).SetupGet(t => t.TextBuffer).Returns(textBuffer);
            var textDocFactory = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDoc, true);

            var msbuildAccessor = IMsBuildAccessorFactory.Implement(projectXml, async(writeLock, callback) =>
            {
                await callback();
                Assert.True(writeLock);
            });

            var threadingService = IProjectThreadingServiceFactory.Create();

            return(CreateInstance(unconfiguredProject, true, msbuildAccessor, fileSystem, textDocFactory, editorFactoryService, threadingService, shellUtilities));
        }
        private static DesignTimeAssemblyResolution CreateInstance(IVsHierarchy hierarchy = null)
        {
            hierarchy = hierarchy ?? IVsHierarchyFactory.Create();

            IUnconfiguredProjectVsServices projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            return(new DesignTimeAssemblyResolution(projectVsServices));
        }
        private static DesignTimeAssemblyResolution CreateInstance(params Reference[] references)
        {
            VSProject    vsProject = VSProjectFactory.ImplementReferences(references);
            Project      project   = ProjectFactory.ImplementObject(() => vsProject);
            IVsHierarchy hierarchy = IVsHierarchyFactory.ImplementGetProperty(project);

            return(CreateInstance(hierarchy));
        }
        public void GetTargetFramework_WhenUnderlyingGetPropertyReturnsDISP_E_MEMBERNOTFOUND_ReturnsOK()
        {
            var hierarchy  = IVsHierarchyFactory.ImplementGetProperty(VSConstants.DISP_E_MEMBERNOTFOUND);
            var resolution = CreateInstance(hierarchy);

            var result = resolution.GetTargetFramework(out string _);

            Assert.Equal(VSConstants.S_OK, result);
        }
        public void GetTargetFramework_WhenUnderlyingGetPropertyReturnsHResult_SetsTargetFrameworkToNull()
        {
            var hierarchy  = IVsHierarchyFactory.ImplementGetProperty(VSConstants.E_INVALIDARG);
            var resolution = CreateInstance(hierarchy);

            resolution.GetTargetFramework(out string result);

            Assert.Null(result);
        }
        public void GetTargetFramework_WhenUnderlyingGetPropertyReturnsDISP_E_MEMBERNOTFOUND_SetsTargetFrameworkToNull()
        {
            var hierarchy  = IVsHierarchyFactory.ImplementGetProperty(VSConstants.DISP_E_MEMBERNOTFOUND);
            var resolution = CreateInstance(hierarchy);

            resolution.GetTargetFramework(out string result);

            Assert.Null(result);
        }
Пример #10
0
        private static IVsHierarchy CreateIVSHierarchy(string targetFrameworkMoniker = ".NETCoreApp,Version=v3.0")
        {
            var projectProperties  = IProjectPropertiesFactory.CreateWithPropertyAndValue("TargetFrameworkMoniker", targetFrameworkMoniker);
            var propertiesProvider = IProjectPropertiesProviderFactory.Create(commonProps: projectProperties);
            var project            = ConfiguredProjectFactory.Create(services: ConfiguredProjectServicesFactory.Create(projectPropertiesProvider: propertiesProvider));
            var scope        = IProjectCapabilitiesScopeFactory.Create(new[] { ProjectCapability.DotNet, ProjectCapability.PackageReferences });
            var ivsHierarchy = IVsHierarchyFactory.ImplementAsUnconfiguredProject(UnconfiguredProjectFactory.Create(scope: scope, configuredProject: project));

            return(ivsHierarchy);
        }
Пример #11
0
        public async Task OnAfterOpenProject_CompatibilityNotSet_DoNotShowWarning()
        {
            var compatibilityDetector = CreateCompatibilityDetector(out var dialogServices, isSolutionOpen: true);
            await compatibilityDetector.InitializeAsync();

            var ivsHierarchy = IVsHierarchyFactory.ImplementAsUnconfiguredProject(UnconfiguredProjectFactory.Create());

            compatibilityDetector.OnAfterOpenProject(ivsHierarchy, fAdded: 1);
            Mock.Get(dialogServices).Verify(x => x.DontShowAgainMessageBox(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never);
        }
        public void Constructor_ValueAsUnconfiguedProject_SetsVsProjectToHostObject()
        {
            var hierarchy      = IVsHierarchyFactory.Create();
            var project        = IUnconfiguredProjectFactory.Create(hostObject: hierarchy);
            var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(project: project);

            var vsServices = CreateInstance(commonServices);

            Assert.Same(hierarchy, vsServices.VsProject);
        }
        public void GetTargetFramework_WhenUnderlyingGetPropertyReturnsValue_SetsTargetFramework(string input)
        {
            var hierarchy  = IVsHierarchyFactory.ImplementGetProperty(input);
            var resolution = CreateInstance(hierarchy);

            var hr = resolution.GetTargetFramework(out string result);

            Assert.Equal(input, result);
            Assert.Equal(VSConstants.S_OK, hr);
        }
Пример #14
0
        public void ShowProjectDesignerAsync_WhenSupportsProjectDesignerFalse_ThrowsInvalidOperation()
        {
            var hierarchy         = IVsHierarchyFactory.ImplementGetProperty(result: false);
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            var designerService = CreateInstance(projectVsServices);

            Assert.Throws <InvalidOperationException>(() => {
                designerService.ShowProjectDesignerAsync();
            });
        }
Пример #15
0
        public void SupportsProjectDesigner_ReturnsResultOfHierarchyGetProperty(bool supportsProjectDesigner)
        {
            var hierarchy         = IVsHierarchyFactory.ImplementGetProperty(result: supportsProjectDesigner);
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            var designerService = CreateInstance(projectVsServices);

            var result = designerService.SupportsProjectDesigner;

            Assert.Equal(supportsProjectDesigner, result);
        }
Пример #16
0
        public void SupportsProjectDesigner_WhenHierarchyGetPropertyReturnsMemberNotFound_IsFalse()
        {
            var hierarchy         = IVsHierarchyFactory.ImplementGetProperty(hr: VSConstants.DISP_E_MEMBERNOTFOUND);
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            var designerService = CreateInstance(projectVsServices);

            var result = designerService.SupportsProjectDesigner;

            Assert.False(result);
        }
Пример #17
0
        public void SupportsProjectDesigner_WhenHierarchyGetPropertyReturnsHResult_ThrowsCOMException()
        {
            var hierarchy         = IVsHierarchyFactory.ImplementGetProperty(hr: VSConstants.E_FAIL);
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            var designerService = CreateInstance(projectVsServices);

            Assert.Throws <COMException>(() => {
                var result = designerService.SupportsProjectDesigner;
            });
        }
        public async Task ShowProjectDesignerAsync_WhenProjectDesignerEditorReturnsHResult_Throws()
        {
            var vsProjectDesignerPageService = IVsProjectDesignerPageServiceFactory.ImplementIsProjectDesignerSupported(() => true);

            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, VSConstants.E_FAIL);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            var designerService = CreateInstance(projectVsServices, vsProjectDesignerPageService);

            await Assert.ThrowsAsync <COMException>(designerService.ShowProjectDesignerAsync);
        }
        public void Project_ReturnsVsHierarchyGetProperty()
        {
            var project   = ProjectFactory.Create();
            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetProperty(VsHierarchyPropID.ExtObject, project);
            var threadingService  = IProjectThreadingServiceFactory.ImplementVerifyOnUIThread(() => { });
            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(hierarchyCreator: () => hierarchy, threadingServiceCreator: () => threadingService);

            var dteServices = CreateInstance(projectVsServices);

            var result = dteServices.Project;

            Assert.Same(project, result);
        }
        internal AbstractGenerateNuGetPackageCommand CreateInstance(
            GeneratePackageOnBuildPropertyProvider?generatePackageOnBuildPropertyProvider = null,
            ISolutionBuildManager?solutionBuildManager     = null,
            IVsUpdateSolutionEvents?solutionEventsListener = null,
            bool isBuilding  = false,
            bool cancelBuild = false)
        {
            var hierarchy        = IVsHierarchyFactory.Create();
            var project          = UnconfiguredProjectFactory.Create(hierarchy);
            var threadingService = IProjectThreadingServiceFactory.Create();

            solutionBuildManager ??= ISolutionBuildManagerFactory.Create(solutionEventsListener, hierarchy, isBuilding, cancelBuild);
            generatePackageOnBuildPropertyProvider ??= CreateGeneratePackageOnBuildPropertyProvider();

            return(CreateInstanceCore(project, threadingService, solutionBuildManager, generatePackageOnBuildPropertyProvider));
        }
Пример #21
0
        public void GetContainedLanguageFactoryForFile_WhenReturnsResult_ReturnsS_OK()
        {
            var hierarchy  = IVsHierarchyFactory.Create();
            var project    = IVsProject_Factory.ImplementIsDocumentInProject(found: true, itemid: 1);
            var properties = ProjectPropertiesFactory.Create(ConfigurationGeneral.SchemaName, ConfigurationGeneral.LanguageServiceIdProperty, LanguageServiceId);
            var containedLanguageFactory = IVsContainedLanguageFactoryFactory.Create();

            var factory = CreateInstance(containedLanguageFactory, hierarchy: hierarchy, project: project, properties: properties);

            var result = factory.GetContainedLanguageFactoryForFile("FilePath", out var hierarchyResult, out var itemIdResult, out var containedLanguageFactoryResult);

            Assert.Equal(VSConstants.S_OK, result);
            Assert.Same(hierarchy, hierarchyResult);
            Assert.Same(containedLanguageFactory, containedLanguageFactoryResult);
            Assert.Equal(1u, itemIdResult);
        }
Пример #22
0
        public async Task ShowProjectDesignerAsync_WhenProjectDesignerEditorReturnsHResult_Throws()
        {
            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetProperty(VsHierarchyPropID.SupportsProjectDesigner, result: true);
            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, VSConstants.E_FAIL);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy);

            var designerService = CreateInstance(projectVsServices);

#pragma warning disable RS0003 // Do not directly await a Task (see https://github.com/dotnet/roslyn/issues/6770)
            await Assert.ThrowsAsync <COMException>(() => {
                return(designerService.ShowProjectDesignerAsync());
            });

#pragma warning restore RS0003 // Do not directly await a Task
        }
Пример #23
0
        private static IVsHierarchyItem CreateItemWithFlags(string flagsString)
        {
            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetProperty((VsHierarchyPropID)__VSHPROPID7.VSHPROPID_ProjectTreeCapabilities, flagsString);

            var identity = new Mock <IVsHierarchyItemIdentity>(MockBehavior.Strict);

            identity.SetupGet(i => i.NestedHierarchy).Returns(hierarchy);
            identity.SetupGet(i => i.NestedItemID).Returns(0);

            var hierarchyItem = new Mock <IVsHierarchyItem>(MockBehavior.Strict);

            hierarchyItem.SetupGet(i => i.HierarchyIdentity).Returns(identity.Object);
            hierarchyItem.SetupGet <IVsHierarchyItem?>(i => i.Parent).Returns((IVsHierarchyItem?)null);

            return(hierarchyItem.Object);
        }
        public Task ShowProjectDesignerAsync_WhenOpenedInExternalEditor_DoesNotAttemptToShowWindow()
        {   // OpenItemWithSpecific returns null frame when opened in external editor

            var vsProjectDesignerPageService = IVsProjectDesignerPageServiceFactory.ImplementIsProjectDesignerSupported(() => true);

            var editorGuid = Guid.NewGuid();

            var hierarchy = IVsHierarchyFactory.Create();
            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, result: editorGuid);

            var project = (IVsProject4)hierarchy;
            project.ImplementOpenItemWithSpecific(editorGuid, VSConstants.LOGVIEWID_Primary, (IVsWindowFrame?)null);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => project);

            var designerService = CreateInstance(projectVsServices, vsProjectDesignerPageService);

            return designerService.ShowProjectDesignerAsync();
        }
        public async Task ShowProjectDesignerAsync_WhenOpenItemWithSpecificEditorReturnsHResult_Throws()
        {
            var vsProjectDesignerPageService = IVsProjectDesignerPageServiceFactory.ImplementIsProjectDesignerSupported(() => true);

            var editorGuid = Guid.NewGuid();

            var hierarchy = IVsHierarchyFactory.Create();

            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, result: editorGuid);

            var project = (IVsProject4)hierarchy;

            project.ImplementOpenItemWithSpecific(editorGuid, VSConstants.LOGVIEWID_Primary, VSConstants.E_FAIL);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => project);

            var designerService = CreateInstance(projectVsServices, vsProjectDesignerPageService);

            await Assert.ThrowsAsync <COMException>(designerService.ShowProjectDesignerAsync);
        }
        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);
        }
        public async Task ShowProjectDesignerAsync_WhenOpenedInInternalEditor_ShowsWindow()
        {
            var vsProjectDesignerPageService = IVsProjectDesignerPageServiceFactory.ImplementIsProjectDesignerSupported(() => true);

            var editorGuid = Guid.NewGuid();

            var hierarchy = IVsHierarchyFactory.Create();
            hierarchy.ImplementGetGuid(VsHierarchyPropID.ProjectDesignerEditor, result: editorGuid);
            var project = (IVsProject4)hierarchy;

            int callCount = 0;
            var frame = IVsWindowFrameFactory.ImplementShow(() => { callCount++; return 0; });
            project.ImplementOpenItemWithSpecific(editorGuid, VSConstants.LOGVIEWID_Primary, frame);

            var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => project);

            var designerService = CreateInstance(projectVsServices, vsProjectDesignerPageService);

            await designerService.ShowProjectDesignerAsync();

            Assert.Equal(1, callCount);
        }
        public void FrameOpenCloseListener_QueryUnloadCorrectProjectNoCancel_CallsCloseOnEditor()
        {
            var uiShell = IVsUIShell7Factory.ImplementAdviseUnadviseWindowEvents(l => 1234, c => Assert.Equal <uint>(1234, c));

            var solution = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(4321);

            var serviceProvider = IServiceProviderFactory.ImplementGetService(ServiceTypeChecker(uiShell, solution));

            var editorState = IProjectFileEditorPresenterFactory.ImplementCloseWindowAsync(true);

            var projPath            = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projPath);
            var hierarchy           = IVsHierarchyFactory.ImplementAsUnconfiguredProject(unconfiguredProject);

            int shouldCancel = -1;

            var listener = new FrameOpenCloseListener(serviceProvider, editorState, new IProjectThreadingServiceMock(), unconfiguredProject);

            Assert.Equal(VSConstants.S_OK, listener.OnQueryUnloadProject(hierarchy, ref shouldCancel));
            Assert.Equal(0, shouldCancel);
            Mock.Get(editorState).Verify(e => e.CanCloseWindowAsync(), Times.Once);
        }
Пример #29
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);
        }
Пример #30
0
        public static ISolutionBuildManager Create(
            IVsUpdateSolutionEvents?solutionEventsListener = null,
            IVsHierarchy?hierarchyToBuild = null,
            bool isBuilding  = false,
            bool cancelBuild = false)
        {
            var buildManager = new Mock <ISolutionBuildManager>();

            solutionEventsListener ??= IVsUpdateSolutionEventsFactory.Create();
            hierarchyToBuild ??= IVsHierarchyFactory.Create();

            int isBusy = isBuilding ? 1 : 0;

            buildManager.Setup(b => b.QueryBuildManagerBusy())
            .Returns(isBusy);

            if (hierarchyToBuild != null)
            {
                void onBuildStartedWithReturn(IVsHierarchy[] _, uint[] __, uint ___)
                {
                    solutionEventsListener !.UpdateSolution_Begin(It.IsAny <int>());

                    if (cancelBuild)
                    {
                        solutionEventsListener.UpdateSolution_Cancel();
                    }
                    else
                    {
                        solutionEventsListener.UpdateSolution_Done(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>());
                    }
                }

                buildManager.Setup(b => b.StartUpdateSpecificProjectConfigurations(It.IsAny <IVsHierarchy[]>(), It.IsAny <uint[]>(), It.IsAny <uint>()))
                .Callback((System.Action <IVsHierarchy[], uint[], uint>)onBuildStartedWithReturn);
            }

            return(buildManager.Object);
        }