<commit_before>﻿/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the Apache License, Version 2.0, please send an email to 
 * <EMAIL>. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Apache License, Version 2.0.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.TC.TestHostAdapters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestUtilities;
using TestUtilities.SharedProject;
using TestUtilities.UI;
using Keyboard = TestUtilities.UI.Keyboard;

namespace Microsoft.VisualStudioTools.SharedProjectTests {
    [TestClass]
    public class ShowAllFiles : SharedProjectTest {
        [ClassInitialize]
        public static void DoDeployment(TestContext context) {
            AssertListener.Initialize();
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesToggle() {
            foreach (var projectType in ProjectTypes) {
                var def = new ProjectDefinition(
                    "ShowAllFiles",
                    projectType,
                    Folder("SubFolder"),
                    Compile("SubFolder\\server"),
                    Property("ProjectView", "ProjectFiles")
                );

                using (var solution = def.Generate().ToVs()) {
                    var projectNode = solution.WaitForItem("ShowAllFiles", "SubFolder", "server" + projectType.CodeExtension);
                    AutomationWrapper.Select(projectNode);

                    solution.App.Dte.ExecuteCommand("Project.ShowAllFiles"); // start showing all

                    Assert.IsTrue(solution.Project.GetIsFolderExpanded("SubFolder"));
                }
            }
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesFilesAlwaysHidden() {
            foreach (var projectType in ProjectTypes) {
                var def = MakeBasicProject(projectType);
                using (var solution = def.Generate().ToVs()) {
                    var projectNode = solution.WaitForItem("ShowAllFiles");
                    Assert.IsNull(solution.WaitForItemRemoved("ShowAllFiles", "ShowAllFiles.sln"));
                    Assert.IsNull(solution.WaitForItemRemoved("ShowAllFiles", "ShowAllFiles.suo"));
                }
            }
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesSymLinks() {
            foreach (var projectType in ProjectTypes) {
                var def = new ProjectDefinition(
                    "ShowAllFilesSymLink",
                    projectType,
                    Folder("SubFolder")
                );
                var userDef = new ProjectDefinition(
                    def.Name,
                    projectType,
                    true,
                    Property("ProjectView", "ShowAllFiles")
                );

                var solutionFile = SolutionFile.Generate(def.Name, def, userDef);

                using (System.Diagnostics.Process p = System.Diagnostics.Process.Start("cmd.exe",
                    String.Format("/c mklink /J \"{0}\" \"{1}\"",
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SymFolder"),
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder")
                    ))) {
                    p.WaitForExit();
                }

                using (System.Diagnostics.Process p = System.Diagnostics.Process.Start("cmd.exe",
                    String.Format("/c mklink /J \"{0}\" \"{1}\"",
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder\Infinite"),
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder")
                    ))) {
                    p.WaitForExit();
                }

                using (var solution = solutionFile.ToVs()) {
                    Assert.IsNotNull(solution.WaitForItem("ShowAllFilesSymLink", "SymFolder"));

                    // https://pytools.codeplex.com/workitem/1150 - infinite links, not displayed
                    Assert.IsNull(solution.FindItem("ShowAllFilesSymLink", "SubFolder", "Infinite"));

                    File.WriteAllText(
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder\Foo.txt"),
                        "Hi!"
                    );

                    // https://pytools.codeplex.com/workitem/1152 - watching the sym link folder
                    Assert.IsNotNull(solution.WaitForItem("ShowAllFilesSymLink", "SubFolder", "Foo.txt"));
                    Assert.IsNotNull(solution.WaitForItem("ShowAllFilesSymLink", "SymFolder", "Foo.txt"));
                }
            }
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesLinked() {
            foreach (var projectType in ProjectTypes) {
                var def = new ProjectDefinition(
                    "ShowAllFilesLinked",
                    projectType,
                    Compile("..\\File"),
                    Folder("SubFolder"),
                    Compile("..\\LinkedFile").Link("SubFolder\\LinkedFile"),
                    Property("ProjectView", "ProjectFiles")
                );

                using (var solution = def.Generate().ToVs()) {
                    var linkedNode = solution.WaitForItem("ShowAllFilesLinked", "File" + projectType.CodeExtension);
                    AutomationWrapper.Select(linkedNode);<commit_msg>Makes the ShowAllFilesSymLinks test remove its own directory junctions, since the test runner fails to remove them correctly.<commit_after>﻿/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the Apache License, Version 2.0, please send an email to 
 * <EMAIL>. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Apache License, Version 2.0.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * ***************************************************************************/

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.TC.TestHostAdapters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestUtilities;
using TestUtilities.SharedProject;
using TestUtilities.UI;
using Keyboard = TestUtilities.UI.Keyboard;

namespace Microsoft.VisualStudioTools.SharedProjectTests {
    [TestClass]
    public class ShowAllFiles : SharedProjectTest {
        [ClassInitialize]
        public static void DoDeployment(TestContext context) {
            AssertListener.Initialize();
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesToggle() {
            foreach (var projectType in ProjectTypes) {
                var def = new ProjectDefinition(
                    "ShowAllFiles",
                    projectType,
                    Folder("SubFolder"),
                    Compile("SubFolder\\server"),
                    Property("ProjectView", "ProjectFiles")
                );

                using (var solution = def.Generate().ToVs()) {
                    var projectNode = solution.WaitForItem("ShowAllFiles", "SubFolder", "server" + projectType.CodeExtension);
                    AutomationWrapper.Select(projectNode);

                    solution.App.Dte.ExecuteCommand("Project.ShowAllFiles"); // start showing all

                    Assert.IsTrue(solution.Project.GetIsFolderExpanded("SubFolder"));
                }
            }
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesFilesAlwaysHidden() {
            foreach (var projectType in ProjectTypes) {
                var def = MakeBasicProject(projectType);
                using (var solution = def.Generate().ToVs()) {
                    var projectNode = solution.WaitForItem("ShowAllFiles");
                    Assert.IsNull(solution.WaitForItemRemoved("ShowAllFiles", "ShowAllFiles.sln"));
                    Assert.IsNull(solution.WaitForItemRemoved("ShowAllFiles", "ShowAllFiles.suo"));
                }
            }
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesSymLinks() {
            foreach (var projectType in ProjectTypes) {
                var def = new ProjectDefinition(
                    "ShowAllFilesSymLink",
                    projectType,
                    Folder("SubFolder")
                );
                var userDef = new ProjectDefinition(
                    def.Name,
                    projectType,
                    true,
                    Property("ProjectView", "ShowAllFiles")
                );

                var solutionFile = SolutionFile.Generate(def.Name, def, userDef);

                using (System.Diagnostics.Process p = System.Diagnostics.Process.Start("cmd.exe",
                    String.Format("/c mklink /J \"{0}\" \"{1}\"",
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SymFolder"),
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder")
                    ))) {
                    p.WaitForExit();
                }

                using (System.Diagnostics.Process p = System.Diagnostics.Process.Start("cmd.exe",
                    String.Format("/c mklink /J \"{0}\" \"{1}\"",
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder\Infinite"),
                        Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder")
                    ))) {
                    p.WaitForExit();
                }

                try {
                    using (var solution = solutionFile.ToVs()) {
                        Assert.IsNotNull(solution.WaitForItem("ShowAllFilesSymLink", "SymFolder"));

                        // https://pytools.codeplex.com/workitem/1150 - infinite links, not displayed
                        Assert.IsNull(solution.FindItem("ShowAllFilesSymLink", "SubFolder", "Infinite"));

                        File.WriteAllText(
                            Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder\Foo.txt"),
                            "Hi!"
                        );

                        // https://pytools.codeplex.com/workitem/1152 - watching the sym link folder
                        Assert.IsNotNull(solution.WaitForItem("ShowAllFilesSymLink", "SubFolder", "Foo.txt"));
                        Assert.IsNotNull(solution.WaitForItem("ShowAllFilesSymLink", "SymFolder", "Foo.txt"));
                    }
                } finally {
                    using (System.Diagnostics.Process p = System.Diagnostics.Process.Start("cmd.exe",
                        String.Format("/c rmdir \"{0}\" \"{1}\"",
                            Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SymFolder"),
                            Path.Combine(solutionFile.Directory, @"ShowAllFilesSymLink\SubFolder\Infinite")
                        ))) {
                        p.WaitForExit();
                    }
                }
            }
        }

        [TestMethod, Priority(0), TestCategory("Core")]
        [HostType("TC Dynamic"), DynamicHostType(typeof(VsIdeHostAdapter))]
        public void ShowAllFilesLinked() {
            foreach (var projectType in ProjectTypes) {
                var def = new ProjectDefinition(
                    "ShowAllFilesLinked",
                    projectType,
                    Compile("..\\File"),
                    Folder("SubFolder"),
                    Compile("..\\LinkedFile").Link("SubFolder\\LinkedFile"),
                    Property("ProjectView", "ProjectFiles")
                );

                using (var solution = def.Generate().ToVs()) {
                    var linkedNode = solution.WaitForItem("ShowAllFilesLinked", "File" + projectType.CodeExtension);
                    AutomationWrapper.Select(linkedNode);
{'fraction_non_alphanumeric': 0.12540241072097028, 'fraction_numerical': 0.0034438871003967956, 'mean_word_length': 1.9216972878390202, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '406461', 'n_tokens_mistral': 3354, 'n_tokens_neox': 3052, 'n_words': 671}