public void NoJson_DoesntCrash() { UnitTestHelper.IsRunningUnitTests = true; var solution = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback); var dteSolution = SolutionFactory.ImplementFindProjectItem(path => { Assert.Equal(Path.Combine(Directory, "global.json"), path); return(null); }); var dte = DTEFactory.ImplementSolution(() => dteSolution); var serviceProvider = IServiceProviderFactory.ImplementGetService(t => { if (typeof(SVsSolution) == t) { return(solution); } if (typeof(DTE) == t) { return(dte); } Assert.False(true); throw new InvalidOperationException(); }); var remover = new GlobalJsonRemover(serviceProvider, IFileSystemFactory.Create()); GlobalJsonRemover.Remover = remover; Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0)); }
private CreateFileFromTemplateService CreateInstance(IUnconfiguredProjectVsServices projectVsServices, DTE2 dte, ProjectProperties properties) { projectVsServices ??= IUnconfiguredProjectVsServicesFactory.Create(); dte ??= DTEFactory.Create(); properties ??= ProjectPropertiesFactory.CreateEmpty(); return(new CreateFileFromTemplateService(projectVsServices, IVsUIServiceFactory.Create <SDTE, DTE2>(dte), properties)); }
public void AfterRemoval_UnadvisesEvents() { UnitTestHelper.IsRunningUnitTests = true; var globalJsonPath = Path.Combine(Directory, "global.json"); var solution = IVsSolutionFactory.CreateWithSolutionDirectory(DirectoryInfoCallback); var projectItem = EnvDTE.ProjectItemFactory.Create(); var dteSolution = SolutionFactory.ImplementFindProjectItem(path => { Assert.Equal(globalJsonPath, path); return(projectItem); }); var dte = DTEFactory.ImplementSolution(() => dteSolution); var serviceProvider = IServiceProviderFactory.ImplementGetService(t => { if (typeof(SVsSolution) == t) { return(solution); } if (typeof(DTE) == t) { return(dte); } Assert.False(true); throw new InvalidOperationException(); }); var fileSystem = IFileSystemFactory.Create(); fileSystem.Create(globalJsonPath); var remover = new GlobalJsonRemover(serviceProvider, fileSystem) { SolutionCookie = 1234 }; GlobalJsonRemover.Remover = remover; Assert.Equal(VSConstants.S_OK, remover.OnAfterOpenSolution(null, 0)); Mock.Get(solution).Verify(s => s.UnadviseSolutionEvents(1234), Times.Once); }
public async Task CreateFile(string templateFilePath, bool expectedResult) { string templateName = "SettingsInternal.zip"; string fileName = "Settings.settings"; var hierarchy = IVsHierarchyFactory.Create(); var solution = (Solution)SolutionFactory.CreateWithGetProjectItemTemplate((templateFile, language) => { Assert.Equal(templateName, templateFile); return(templateFilePath); }); var vsProject = (IVsProject4)IVsHierarchyFactory.Create(); vsProject.ImplementAddItemWithSpecific((itemId, itemOperation, itemName, cOpen, files, result) => { Assert.Equal(VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD, itemOperation); Assert.Equal(fileName, itemName); Assert.Equal((uint)1, cOpen); Assert.Equal(new string[] { templateFilePath }, files); result[0] = expectedResult ? VSADDRESULT.ADDRESULT_Success : VSADDRESULT.ADDRESULT_Failure; return(VSConstants.S_OK); }); var dte = DTEFactory.ImplementSolution(() => solution); var projectVsServices = IUnconfiguredProjectVsServicesFactory.Implement(() => hierarchy, () => vsProject); var properties = CreateProperties(); var service = CreateInstance(projectVsServices, dte, properties); bool returnValue = await service.CreateFileAsync(templateName, "Moniker", fileName); Assert.Equal(expectedResult, returnValue); }