public async Task Test(string input, string appManifestPropertyValue, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var projectTreeProvider = IProjectTreeProviderFactory.Create(@"C:\Foo\Properties", (root, path) => { root.TryFindImmediateChild(Path.GetFileName(path), out var node); return(node); }); var projectTree = IPhysicalProjectTreeFactory.Create(currentTree: inputTree, provider: projectTreeProvider); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var fileSystem = IFileSystemFactory.Create(path => true); var specialFilesManager = ISpecialFilesManagerFactory.Create(); var properties = ProjectPropertiesFactory.Create(UnconfiguredProjectFactory.Create(), new PropertyPageData { Category = ConfigurationGeneralBrowseObject.SchemaName, PropertyName = ConfigurationGeneralBrowseObject.ApplicationManifestProperty, Value = appManifestPropertyValue }); var provider = new AppManifestSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager, properties); var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.CreateIfNotExist); Assert.Equal(expectedFilePath, filePath); }
public async Task CreateFile_NotInSync(string input, string expected, bool fileExistsOnDisk, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var expectedTree = ProjectTreeParser.Parse(expected); var projectTreeProvider = new ProjectTreeProvider(); var projectTree = IPhysicalProjectTreeFactory.Create(provider: projectTreeProvider, currentTree: inputTree); var sourceItemsProvider = IProjectItemProviderFactory.CreateWithAdd(inputTree); var fileSystem = IFileSystemFactory.Create(path => fileExistsOnDisk, path => { // Verify that file is created on disk. Assert.False(fileExistsOnDisk); Assert.Equal(expectedFilePath, path); return(null); }); var specialFilesManager = ISpecialFilesManagerFactory.ImplementGetFile(@"C:\Foo\Properties"); var provider = new SettingsFileSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.CreateIfNotExist); Assert.Equal(expectedFilePath, filePath); AssertAreEquivalent(expectedTree, inputTree); }
public void Constructor_NullProjectTreeService_ThrowsArgumentNullException() { var fileSystem = IFileSystemFactory.Create(); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var specialFilesManager = ISpecialFilesManagerFactory.Create(); Assert.Throws <ArgumentNullException>("projectTree", () => { new AppSettingsSpecialFileProvider(null !, sourceItemsProvider, null, fileSystem, specialFilesManager); });
public void Constructor_NullFileSystem_ThrowsArgumentNullException() { var projectTree = IPhysicalProjectTreeFactory.Create(); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var specialFilesManager = ISpecialFilesManagerFactory.Create(); Assert.Throws <ArgumentNullException>("fileSystem", () => { new SettingsFileSpecialFileProvider(projectTree, sourceItemsProvider, null, null, specialFilesManager); }); }
public async Task FindFile_FromAppDesignerFolder(string input, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var projectTreeProvider = new ProjectTreeProvider(); var projectTree = IPhysicalProjectTreeFactory.Create(currentTree: inputTree, provider: projectTreeProvider); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var fileSystem = IFileSystemFactory.Create(path => true); var specialFilesManager = ISpecialFilesManagerFactory.ImplementGetFile(@"C:\Foo\Properties"); var provider = new SettingsFileSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.FullPath); Assert.Equal(expectedFilePath, filePath); }
public async Task FindFile_NodeNotInSync(string input, bool fileExistsOnDisk, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var projectTree = IPhysicalProjectTreeFactory.Create(currentTree: inputTree); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var fileSystem = IFileSystemFactory.Create(path => fileExistsOnDisk); var specialFilesManager = ISpecialFilesManagerFactory.Create(); var provider = new SettingsFileSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.FullPath); Assert.Equal(expectedFilePath, filePath); }
public async Task FindFile_FromRoot(string input, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var projectTree = IPhysicalProjectTreeFactory.Create(currentTree: inputTree); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var fileSystem = IFileSystemFactory.Create(path => true); var specialFilesManager = ISpecialFilesManagerFactory.Create(); var provider = new AppConfigFileSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppConfig, SpecialFileFlags.FullPath); Assert.Equal(expectedFilePath, filePath); }
public async Task GetFile_WhenNoAppDesigner_ReturnsPathUnderProjectRoot() { var inputTree = ProjectTreeParser.Parse(@" Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.csproj"" Properties (flags: {Folder}), FilePath: ""C:\Foo\Properties"" Settings.settings, FilePath: ""C:\Foo\Properties\Settings.settings"""); var projectTreeProvider = new ProjectTreeProvider(); var projectTree = IPhysicalProjectTreeFactory.Create(currentTree: inputTree, provider: projectTreeProvider); var sourceItemsProvider = IProjectItemProviderFactory.Create(); var fileSystem = IFileSystemFactory.Create(path => true); var specialFilesManager = ISpecialFilesManagerFactory.ImplementGetFile(null); // No AppDesigner var provider = new SettingsFileSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.FullPath); Assert.Equal(@"C:\Foo\Settings.settings", filePath); }
internal LaunchSettingsUnderTest GetLaunchSettingsProvider(IFileSystem fileSystem, string appDesignerFolder = @"c:\test\Project1\Properties", string activeProfile = "") { Mock <IEnumValue> activeProfileValue = new Mock <IEnumValue>(); activeProfileValue.Setup(s => s.Name).Returns(activeProfile); var debuggerData = new PropertyPageData() { Category = ProjectDebugger.SchemaName, PropertyName = ProjectDebugger.ActiveDebugProfileProperty, Value = activeProfileValue.Object }; var specialFilesManager = ISpecialFilesManagerFactory.ImplementGetFile(appDesignerFolder); var unconfiguredProject = UnconfiguredProjectFactory.Create(null, null, @"c:\test\Project1\Project1.csproj"); var properties = ProjectPropertiesFactory.Create(unconfiguredProject, new[] { debuggerData }); var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(unconfiguredProject, null, new IProjectThreadingServiceMock(), null, properties); var projectServices = IUnconfiguredProjectServicesFactory.Create(IProjectAsynchronousTasksServiceFactory.Create(CancellationToken.None)); var provider = new LaunchSettingsUnderTest(unconfiguredProject, projectServices, fileSystem ?? new IFileSystemMock(), commonServices, null, specialFilesManager); return(provider); }
public async Task CreateFile_CallTemplateProvider(string input, string expected, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var expectedTree = ProjectTreeParser.Parse(expected); var projectTreeProvider = IProjectTreeProviderFactory.Create(@"C:\Foo\Properties"); var projectTree = IPhysicalProjectTreeFactory.Create(provider: projectTreeProvider, currentTree: inputTree); var sourceItemsProvider = IProjectItemProviderFactory.CreateWithAdd(inputTree); var fileSystem = IFileSystemFactory.Create(path => false, path => { // Verify that file is created on disk. Assert.False(true, "File system create shouldn't have been called directly."); return(null); }); var templateProvider = new Lazy <ICreateFileFromTemplateService>(() => ICreateFileFromTemplateServiceFactory.Create()); var specialFilesManager = ISpecialFilesManagerFactory.Create(); var provider = new SettingsFileSpecialFileProvider(projectTree, sourceItemsProvider, templateProvider, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.CreateIfNotExist); Assert.Equal(expectedFilePath, filePath); }
public async Task CreateFile_InRootFolder(string input, string expected, string expectedFilePath) { var inputTree = ProjectTreeParser.Parse(input); var expectedTree = ProjectTreeParser.Parse(expected); var projectTreeProvider = IProjectTreeProviderFactory.Create(@"C:\Foo"); var projectTree = IPhysicalProjectTreeFactory.Create(provider: projectTreeProvider, currentTree: inputTree); var sourceItemsProvider = IProjectItemProviderFactory.CreateWithAdd(inputTree); var fileSystem = IFileSystemFactory.Create(path => false, path => { // Verify that file is created on disk. Assert.Equal(expectedFilePath, path); return(null); }); var specialFilesManager = ISpecialFilesManagerFactory.Create(); var provider = new AppConfigFileSpecialFileProvider(projectTree, sourceItemsProvider, null, fileSystem, specialFilesManager); var filePath = await provider.GetFileAsync(SpecialFiles.AppConfig, SpecialFileFlags.CreateIfNotExist); Assert.Equal(expectedFilePath, filePath); AssertAreEquivalent(expectedTree, inputTree); }