示例#1
0
        public async Task AspNetCore_MultiFileNesting()
        {
            string projectFileName = Util.GetSampleProject("aspnetcore-empty-30", "aspnetcore-empty-30.sln");

            using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), projectFileName)) {
                var project = sol.GetAllProjectsWithFlavor <AspNetCoreProjectExtension> ().FirstOrDefault();

                var dir = project.BaseDirectory;
                project.AddDirectory("FileNesting");

                var rootFile = AddFile(project, Path.Combine(dir, "FileNesting", "bootstrap.css"));
                Assert.That(FileNestingService.GetChildren(rootFile), Is.Null);
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile)?.Count() ?? 0, Is.EqualTo(0));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile)?.Count() ?? 0, Is.EqualTo(0));

                // This should be nested under bootstrap.css
                var mapFile = AddFile(project, Path.Combine(dir, "FileNesting", "bootstrap.css.map"));
                Assert.That(FileNestingService.GetChildren(rootFile), Contains.Item(mapFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile), Contains.Item(mapFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile)?.Count() ?? 0, Is.EqualTo(1));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile), Contains.Item(mapFile));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile)?.Count() ?? 0, Is.EqualTo(1));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(mapFile)?.Count() ?? 0, Is.EqualTo(0));
                Assert.That(FileNestingService.GetDependentOrNestedTree(mapFile)?.Count() ?? 0, Is.EqualTo(0));

                // This should be nested under bootstrap.css
                var minFile = AddFile(project, Path.Combine(dir, "FileNesting", "bootstrap.min.css"));
                Assert.That(FileNestingService.GetChildren(rootFile), Contains.Item(minFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile), Contains.Item(minFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile)?.Count() ?? 0, Is.EqualTo(2));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile), Contains.Item(minFile));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile)?.Count() ?? 0, Is.EqualTo(2));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(minFile)?.Count() ?? 0, Is.EqualTo(0));
                Assert.That(FileNestingService.GetDependentOrNestedTree(minFile)?.Count() ?? 0, Is.EqualTo(0));

                // This should be nested under bootstrap.min.css
                var minMapFile = AddFile(project, Path.Combine(dir, "FileNesting", "bootstrap.min.css.map"));
                Assert.That(FileNestingService.GetChildren(rootFile), !Contains.Item(minMapFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile), !Contains.Item(minMapFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(rootFile)?.Count() ?? 0, Is.EqualTo(2));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile), Contains.Item(minMapFile));
                Assert.That(FileNestingService.GetDependentOrNestedTree(rootFile)?.Count() ?? 0, Is.EqualTo(3));
                Assert.That(FileNestingService.GetChildren(minFile), Contains.Item(minMapFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(minFile), Contains.Item(minMapFile));
                Assert.That(FileNestingService.GetDependentOrNestedChildren(minFile)?.Count() ?? 0, Is.EqualTo(1));
                Assert.That(FileNestingService.GetDependentOrNestedTree(minFile), Contains.Item(minMapFile));
                Assert.That(FileNestingService.GetDependentOrNestedTree(minFile)?.Count() ?? 0, Is.EqualTo(1));

                // Check if all files are taken into account when renaming the top one
                var files = MonoDevelop.Ide.ProjectOperations.GetDependentFilesToRename(rootFile, "reboot.css");
                Assert.That(files.Count, Is.EqualTo(3));
                Assert.True(files.Any(x => x.File == mapFile && x.NewName == "reboot.css.map"));
                Assert.True(files.Any(x => x.File == minFile && x.NewName == "reboot.min.css"));
                Assert.True(files.Any(x => x.File == minMapFile && x.NewName == "reboot.min.css.map"));
            }
        }
        public async Task AspNetCore_FileNesting()
        {
            string projectFileName = Util.GetSampleProject("aspnetcore-empty-30", "aspnetcore-empty-30.sln");

            using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), projectFileName)) {
                var files = new List <(string, string)> ();
                files.Add(("Index.cshtml.cs", "Index.cshtml"));
                files.Add(("file.html.css", "file.html"));
                files.Add(("bootstrap.css.map", "bootstrap.css"));
                files.Add(("jquery.js", "jquery.ts"));
                files.Add(("site-vsdoc.js", "site.js"));
                files.Add(("jquery.min.js", "jquery.js"));
                files.Add(("template.cs", "template.tt"));
                files.Add(("template.doc", "template.tt"));
                files.Add((".bowerrc", "bower.json"));

                var project = sol.GetAllProjectsWithFlavor <AspNetCoreProjectExtension> ().FirstOrDefault();

                var dir = project.BaseDirectory;
                project.AddDirectory("FileNesting");

                foreach (var f in files)
                {
                    // Create files
                    string inputFileDestination  = Path.Combine(dir, "FileNesting", f.Item1);
                    string parentFileDestination = Path.Combine(dir, "FileNesting", f.Item2);

                    File.WriteAllText(parentFileDestination, "");
                    var parentFile = project.AddFile(parentFileDestination);
                    File.WriteAllText(inputFileDestination, "");
                    var inputFile = project.AddFile(inputFileDestination);

                    var actualParentFile = FileNestingService.GetParentFile(inputFile);
                    Assert.That(parentFile, Is.EqualTo(actualParentFile), $"Was expecting parent file {parentFileDestination} for {inputFileDestination} but got {actualParentFile}");

                    // Disable file nesting on the solution
                    sol.UserProperties.SetValue("MonoDevelop.Ide.FileNesting.Enabled", false);
                    Assert.False(FileNestingService.IsEnabledForProject(project));
                    Assert.Null(FileNestingService.GetParentFile(inputFile));

                    // Re-enable file nesting on the solution
                    sol.UserProperties.SetValue("MonoDevelop.Ide.FileNesting.Enabled", true);
                    Assert.True(FileNestingService.IsEnabledForProject(project));

                    // Test removing files
                    project.Files.Remove(inputFile);
                    Assert.That(FileNestingService.GetChildren(parentFile).Count, Is.EqualTo(0));
                    project.Files.Remove(parentFile);
                }
            }
        }
示例#3
0
        public override void BuildChildNodes(ITreeBuilder treeBuilder, object dataObject)
        {
            base.BuildChildNodes(treeBuilder, dataObject);
            ProjectFile file = (ProjectFile)dataObject;

            if (file.HasChildren)
            {
                treeBuilder.AddChildren(file.DependentChildren);
            }
            else
            {
                var children = FileNestingService.GetChildren(file);
                if ((children?.Count ?? 0) > 0)
                {
                    treeBuilder.AddChildren(children);
                }
            }
        }