public void Constructor_NullFileSystem_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("fileSystem", () =>
     {
         new SettingsFileSpecialFileProvider(IProjectTreeServiceFactory.Create(null), IProjectItemProviderFactory.Create(), null, null);
     });
 }
 public void Constructor_NullSourceItemsProvider_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("sourceItemsProvider", () =>
     {
         new SettingsFileSpecialFileProvider(IProjectTreeServiceFactory.Create(null), null, null, IFileSystemFactory.Create(null));
     });
 }
        public void Constructor_NullAsTreeProvider_ThrowsArgumentNull()
        {
            var projectTreeService = new Lazy <IProjectTreeService>(() => IProjectTreeServiceFactory.Create());

            Assert.Throws <ArgumentNullException>("treeProvider", () => {
                new PhysicalProjectTree(projectTreeService, (Lazy <IProjectTreeProvider>)null);
            });
        }
        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 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);
        }
        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_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);
        }
        public static IPhysicalProjectTree Create(IProjectTreeProvider?provider = null, IProjectTree?currentTree = null, IProjectTreeService?service = null, IPhysicalProjectTreeStorage?storage = null)
        {
            currentTree ??= ProjectTreeParser.Parse("Project");
            provider ??= new ProjectTreeProvider();
            storage ??= IPhysicalProjectTreeStorageFactory.Create();
            service ??= IProjectTreeServiceFactory.Create(currentTree, provider);

            var mock = new Mock <IPhysicalProjectTree>();

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

            mock.Setup(t => t.CurrentTree)
            .Returns(currentTree);

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

            mock.Setup(t => t.TreeStorage)
            .Returns(storage);

            return(mock.Object);
        }