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 void Constructor_NullProjectTreeService_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("projectTreeService", () =>
     {
         new SettingsFileSpecialFileProvider(null, IProjectItemProviderFactory.Create(), null, IFileSystemFactory.Create(null));
     });
 }
        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);
        }
Example #4
0
        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_FromRoot(string input, string expectedFilePath)
        {
            var inputTree = ProjectTreeParser.Parse(input);

            var projectTreeService  = IProjectTreeServiceFactory.Create(inputTree);
            var sourceItemsProvider = IProjectItemProviderFactory.Create();
            var fileSystem          = IFileSystemFactory.Create(path => true);

            var provider = new AppConfigFileSpecialFileProvider(projectTreeService, sourceItemsProvider, null, fileSystem);

            var filePath = await provider.GetFileAsync(SpecialFiles.AppConfig, SpecialFileFlags.FullPath);

            Assert.Equal(expectedFilePath, filePath);
        }
        public async Task FindFile_NodeNotInSync(string input, bool fileExistsOnDisk, string expectedFilePath)
        {
            var inputTree = ProjectTreeParser.Parse(input);

            var projectTreeService  = IProjectTreeServiceFactory.Create(inputTree);
            var sourceItemsProvider = IProjectItemProviderFactory.Create();
            var fileSystem          = IFileSystemFactory.Create(path => fileExistsOnDisk);

            var provider = new SettingsFileSpecialFileProvider(projectTreeService, sourceItemsProvider, null, fileSystem);

            var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.FullPath);

            Assert.Equal(expectedFilePath, filePath);
        }
        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 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);
        }
        public async Task CreateFile_InRootFolder(string input, string expected, string expectedFilePath)
        {
            var inputTree    = ProjectTreeParser.Parse(input);
            var expectedTree = ProjectTreeParser.Parse(expected);

            var projectTreeService  = IProjectTreeServiceFactory.Create(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 provider = new AppConfigFileSpecialFileProvider(projectTreeService, sourceItemsProvider, null, fileSystem);
            var filePath = await provider.GetFileAsync(SpecialFiles.AppConfig, SpecialFileFlags.CreateIfNotExist);

            Assert.Equal(expectedFilePath, filePath);
            AssertAreEquivalent(expectedTree, inputTree);
        }
        public async Task CreateFile_CallTemplateProvider(string input, string expected, string expectedFilePath)
        {
            var inputTree    = ProjectTreeParser.Parse(input);
            var expectedTree = ProjectTreeParser.Parse(expected);

            var projectTreeService  = IProjectTreeServiceFactory.Create(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 provider = new SettingsFileSpecialFileProvider(projectTreeService, sourceItemsProvider, templateProvider, fileSystem);
            var filePath = await provider.GetFileAsync(SpecialFiles.AppSettings, SpecialFileFlags.CreateIfNotExist);

            Assert.Equal(expectedFilePath, filePath);
            AssertAreEquivalent(expectedTree, inputTree);
        }