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_NullAsTreeService_ThrowsArgumentNull()
        {
            var projectTreeProvider = new Lazy <IProjectTreeProvider>(() => IProjectTreeProviderFactory.Create());

            Assert.Throws <ArgumentNullException>("treeService", () => {
                new PhysicalProjectTree((Lazy <IProjectTreeService>)null, projectTreeProvider);
            });
        }
        public static IPhysicalProjectTree Create(IProjectTreeProvider provider = null)
        {
            var mock = new Mock <IPhysicalProjectTree>();

            mock.Setup(t => t.TreeProvider).Returns(provider ?? IProjectTreeProviderFactory.Create());

            return(mock.Object);
        }
        public void Constructor_WhenTreeServiceCurrentTreeIsNull_SetsCurrentTreeToNull()
        {
            var projectTreeService  = new Lazy <IProjectTreeService>(() => IProjectTreeServiceFactory.ImplementCurrentTree(() => null));
            var projectTreeProvider = new Lazy <IProjectTreeProvider>(() => IProjectTreeProviderFactory.Create());

            var projectTree = new PhysicalProjectTree(projectTreeService, projectTreeProvider);

            Assert.Null(projectTree.CurrentTree);
        }
        public void Constructor_ValueAsTreeProvider_SetTreeProviderProperty()
        {
            var projectTreeService  = new Lazy <IProjectTreeService>(() => IProjectTreeServiceFactory.Create());
            var projectTreeProvider = new Lazy <IProjectTreeProvider>(() => IProjectTreeProviderFactory.Create());

            var projectTree = new PhysicalProjectTree(projectTreeService, projectTreeProvider);

            Assert.Same(projectTreeProvider.Value, projectTree.TreeProvider);
        }
        public async Task CreateFolderAsync_ValueAsPath_IsCalculatedRelativeToProjectDirectory(string projectPath, string input, string expected)
        {
            var project = UnconfiguredProjectFactory.Create(filePath: projectPath);
            string result = null;
            var treeProvider = IProjectTreeProviderFactory.ImplementFindByPath((root, path) => { result = path; return null; });
            var currentTree = ProjectTreeParser.Parse(projectPath);

            var storage = CreateInstance(treeProvider: treeProvider, project: project);

            await storage.CreateFolderAsync(input);

            Assert.Equal(expected, result);
        }
        public void Constructor_ValueAsTreeService_SetsCurrentTreeToTreeServiceCurrentTreeTree()
        {
            var tree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot})
");

            var projectTreeServiceState = IProjectTreeServiceStateFactory.ImplementTree(() => tree);
            var projectTreeService      = new Lazy <IProjectTreeService>(() => IProjectTreeServiceFactory.ImplementCurrentTree(() => projectTreeServiceState));
            var projectTreeProvider     = new Lazy <IProjectTreeProvider>(() => IProjectTreeProviderFactory.Create());

            var projectTree = new PhysicalProjectTree(projectTreeService, projectTreeProvider);

            Assert.Same(tree, projectTree.CurrentTree);
        }
        private PhysicalProjectTreeStorage CreateInstance(IProjectTreeService treeService = null, IProjectTreeProvider treeProvider = null, IFileSystem fileSystem = null, IFolderManager folderManager = null, UnconfiguredProject project = null)
        {
            treeService = treeService ?? IProjectTreeServiceFactory.Create(ProjectTreeParser.Parse("Root"));
            treeProvider = treeProvider ?? IProjectTreeProviderFactory.Create();
            fileSystem = fileSystem ?? IFileSystemFactory.Create();
            folderManager = folderManager ?? IFolderManagerFactory.Create();
            project = project ?? UnconfiguredProjectFactory.Create();

            return new PhysicalProjectTreeStorage(new Lazy<IProjectTreeService>(() => treeService),
                                                  new Lazy<IProjectTreeProvider>(() => treeProvider),
                                                  new Lazy<IFileSystem>(() => fileSystem),
                                                  ActiveConfiguredProjectFactory.ImplementValue(() => folderManager),
                                                  project);
        }
        public static IPhysicalProjectTree Create(IProjectTreeProvider provider = null, IProjectTree currentTree = null, IProjectTreeService service = null)
        {
            var mock = new Mock <IPhysicalProjectTree>();

            mock.Setup(t => t.TreeProvider)
            .Returns(provider ?? IProjectTreeProviderFactory.Create());

            mock.Setup(t => t.CurrentTree)
            .Returns(currentTree ?? ProjectTreeParser.Parse("Project"));

            mock.Setup(t => t.TreeService)
            .Returns(service ?? IProjectTreeServiceFactory.Create());

            return(mock.Object);
        }
        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);
        }
        public static IProjectTreeService Create(IProjectTree tree, IProjectTreeProvider?treeProvider = null)
        {
            var mock = new Mock <IProjectTreeService>();

            var treeState = IProjectTreeServiceStateFactory.ImplementTree(() => tree, () => treeProvider ?? IProjectTreeProviderFactory.Create());

            mock.Setup(s => s.PublishAnyNonLoadingTreeAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(treeState);

            mock.Setup(s => s.PublishAnyNonNullTreeAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(treeState);

            mock.SetupGet(s => s.CurrentTree)
            .Returns(treeState);

            return(mock.Object);
        }
        public static IProjectTreeService Create(IProjectTree tree)
        {
            var mock = new Mock <IProjectTreeService>();

            var treeState = IProjectTreeServiceStateFactory.ImplementTree(() => tree, () => IProjectTreeProviderFactory.Create());

            mock.SetupGet(s => s.CurrentTree)
            .Returns(treeState);

            return(mock.Object);
        }