Ejemplo n.º 1
0
        public async Task ExistingDependenciesFromSolution()
        {
            VSHost.EnsureSolution(@"LessDependencies\LessDependencies.sln");
            await graph.RescanComplete;
            var sharedDeps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(VSHost.FixtureDirectory, "LessDependencies", "_shared.less")
                );

            sharedDeps
            .Select(Path.GetFileName)
            .Should()
            .BeEquivalentTo(new[] { "_admin.less", "Manager.less", "Home.less" });

            var adminDeps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(VSHost.FixtureDirectory, "LessDependencies", "Areas", "_admin.less")
                );

            adminDeps
            .Select(Path.GetFileName)
            .Should()
            .BeEquivalentTo(new[] { "Manager.less" });

            var homeDeps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(VSHost.FixtureDirectory, "LessDependencies", "Home.less")
                );

            homeDeps.Should().BeEmpty();
        }
        public void ProjectEnumerationTest()
        {
            var solutionService = VSHost.GetService <IVsSolution>(typeof(SVsSolution));

            Project project = ProjectHelpers.GetAllProjects().First(p => p.Name == "CS-Normal");

            IVsHierarchy projHierarchy;

            ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out projHierarchy));
            ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, projHierarchy, 0));

            // We target VS2013, which can only open WinStore
            // apps when running on Win8.1. Therefore, I skip
            // those projects when testing on older platforms
            var isWin81 = Type.GetType("Windows.UI.Xaml.Controls.Flyout, Windows.UI.Xaml, ContentType=WindowsRuntime", false) != null;

            ProjectHelpers.GetAllProjects()
            .Select(ProjectHelpers.GetRootFolder)
            .Select(f => f.TrimEnd('\\'))
            .Should()
            .BeEquivalentTo(
                Directory.EnumerateDirectories(Path.Combine(VSHost.FixtureDirectory, "ProjectEnumeration"))
                .Where(f => Path.GetFileName(f) != "CS-Normal" && Path.GetFileName(f) != "Debug")                       // Skip temp folder & unloaded project
                .Where(f => isWin81 || !f.Contains("WinStore"))
                );
        }
Ejemplo n.º 3
0
        //[TestMethod, TestCategory("Completion")]
        public async Task AspxZenCodingTest()
        {
            var textView = await VSHost.TypeText(".aspx", "#id.class\t");

            await VSHost.Dispatcher.NextFrame(DispatcherPriority.ApplicationIdle);

            textView.GetText().Should().Be("<div id=\"id\" class=\"class\"></div>");
        }
Ejemplo n.º 4
0
        public async Task BlockCommentCompletion()
        {
            SettingsStore.EnterTestMode(new WESettings
            {
                JavaScript = { BlockCommentCompletion = true }
            });
            var textView = await VSHost.TypeText(".js", "/*");

            textView.GetText().Should().Be("/**/");
        }
Ejemplo n.º 5
0
        public async Task UseStrictEmptyFile()
        {
            var textView = await VSHost.TypeText(".js", "'");

            textView.IsCompletionOpen().Should().BeTrue();
            await VSHost.TypeString("\t");

            textView.GetText().Should().Be("'use strict';");
            textView.IsCompletionOpen().Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void Variables2()
        {
            VSHost.ReadyingSolution();

            string input    = "div.item { color: $bg; $bg: blue; }";
            string expected = "div.item {$bg: blue;color: $bg;}";

            string result = _sorter.SortScss(input);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 7
0
        public void Mixin1()
        {
            VSHost.ReadyingSolution();

            string input    = "div.item { top: 10px; position: relative; .mixin(); }";
            string expected = "div.item {position: relative;top: 10px;.mixin();}";

            string result = _sorter.SortLess(input);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 8
0
        public void Nesting1()
        {
            VSHost.ReadyingSolution();

            string input    = "div.item { top: 10px; position: relative; div{color:red; top: 5px;}}";
            string expected = "div.item {position: relative;top: 10px; div{top: 5px;color:red;}}";

            string result = _sorter.SortScss(input);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 9
0
        public void Mixin2()
        {
            VSHost.ReadyingSolution();

            string input    = "div.item { top: 10px; position: relative; .mixin(@red, 5px); display: block; }";
            string expected = "div.item {position: relative;top: 10px;display: block;.mixin(@red, 5px);}";

            string result = _sorter.SortScss(input);

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 10
0
        public async Task BlockCommentStarCompletionDisabled()
        {
            SettingsStore.EnterTestMode(new WESettings
            {
                JavaScript = { BlockCommentCompletion = false }
            });

            var textView = await VSHost.TypeText(".js", "/*\n");

            textView.GetText().Should().Be("/*\r\n");
        }
Ejemplo n.º 11
0
        public async Task BackspaceDismisses()
        {
            var textView = await VSHost.TypeText(".js", "'u");

            textView.IsCompletionOpen().Should().BeTrue();
            await VSHost.TypeString("\b");

            textView.IsCompletionOpen().Should().BeTrue();
            await VSHost.TypeString("\b");

            textView.IsCompletionOpen().Should().BeFalse();
        }
Ejemplo n.º 12
0
        public void CreateGraph()
        {
            // Make sure VS has loaded before using MEF (prevents native access violations!)
            VSHost.EnsureSolution(@"LessDependencies\LessDependencies.sln");

            // Don't create the instance using MEF, to ensure that I get a fresh graph for each test.
            graph           = new LessDependencyGraph(WebEditor.ExportProvider.GetExport <IFileExtensionRegistryService>().Value);
            graph.IsEnabled = true;

            // Add the instance to the MEF catalog so that its IFileSaveListener is picked up
            graphPart = AttributedModelServices.CreatePart(graph);
            var cc = (CompositionContainer)WebEditor.CompositionService;

            cc.Compose(new CompositionBatch(new[] { graphPart }, null));
        }
Ejemplo n.º 13
0
        public async Task DeletedImports()
        {
            var s2 = (Solution2)VSHost.DTE.Solution;

            s2.Create(TestCaseDirectory, "ImportDeleteTests");
            var template = s2.GetProjectTemplate("EmptyWebApplicationProject40.zip", "CSharp");

            s2.AddFromTemplate(template, Path.Combine(TestCaseDirectory, "WebAppProject2"), "WebAppProject.csproj");

            // To be discovered on save of dependent file
            File.WriteAllText(Path.Combine(TestCaseDirectory, "WebAppProject2", "_mixins.less"), "// Content...");

            AddProjectFile(Path.Combine(TestCaseDirectory, "WebAppProject2", "page.less"), "@import '_mixins';");

            await graph.RescanComplete;

            var deps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(TestCaseDirectory, "WebAppProject2", "_mixins.less")
                );

            deps
            .Select(Path.GetFileName)
            .Should()
            .BeEquivalentTo(new[] { "page.less" });

            var window = VSHost.DTE.ItemOperations.OpenFile(Path.Combine(TestCaseDirectory, "WebAppProject2", "page.less"));

            await VSHost.Dispatcher.NextFrame();    // Text editoro commands must be sent from the UI thread

            var target = (IOleCommandTarget)ProjectHelpers.GetCurrentNativeTextView();

            target.Execute(VSConstants.VSStd97CmdID.SelectAll);
            await VSHost.TypeString("// Import was removed");

            window.Document.Save();

            await graph.RescanComplete;

            deps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(TestCaseDirectory, "WebAppProject2", "_mixins.less")
                );

            deps
            .Select(Path.GetFileName)
            .Should()
            .BeEmpty();
        }
        public async Task SaveDependentFiles()
        {
            var s2 = (Solution2)VSHost.DTE.Solution;

            s2.Create(TestCaseDirectory, "ChainCompilationTests");
            var template = s2.GetProjectTemplate("EmptyWebApplicationProject40.zip", "CSharp");

            s2.AddFromTemplate(template, Path.Combine(TestCaseDirectory, "WebAppProject"), "WebAppProject.csproj");

            // To be discovered on save of dependent file
            var    mixinsPath   = Path.Combine(TestCaseDirectory, "WebAppProject", "_mixins.less");
            string pagePath     = Path.Combine(TestCaseDirectory, "WebAppProject", "page.less");
            string basePath     = Path.Combine(TestCaseDirectory, "WebAppProject", "base.less");
            string otherDepPath = Path.Combine(TestCaseDirectory, "WebAppProject", "otherDep.less");

            File.WriteAllText(mixinsPath, "// Content...");
            AddProjectFile(basePath, "body { font: sans-serif }");
            AddProjectFile(pagePath, "@import 'base';");
            AddProjectFile(otherDepPath, "@import 'base';");

            File.WriteAllText(CssPath(basePath), "");
            File.WriteAllText(CssPath(pagePath), "");
            await Task.Delay(10);   // Give a tiny bit of time for the graph to initialize

            var window = VSHost.DTE.ItemOperations.OpenFile(basePath);
            await VSHost.TypeString("@import url(\"./_mixins.less\");\n");

            window.Document.Save();

            await WaitFor(() => new FileInfo(CssPath(basePath)).Length > 5, "base.less to compile", maxSeconds : 8);
            await WaitFor(() => new FileInfo(CssPath(pagePath)).Length > 5, "page.less to chain compile", maxSeconds : 2);

            File.Exists(CssPath(otherDepPath)).Should().BeFalse("Dependency without .css file should not be compiled");

            window = VSHost.DTE.ItemOperations.OpenFile(mixinsPath);
            await VSHost.TypeString(".MyClass { color: purple; }\n");

            window.Document.Save();

            await WaitFor(() => File.ReadAllText(CssPath(pagePath)).Contains(".MyClass"), "page.less to chain compile", maxSeconds : 2);

            File.Exists(CssPath(mixinsPath)).Should().BeFalse("File without .css file should not be compiled");
        }
Ejemplo n.º 15
0
        public async Task DependenciesFromNewFiles()
        {
            var s2 = (Solution2)VSHost.DTE.Solution;

            s2.Create(TestCaseDirectory, "DependencyCreationTests");
            var template = s2.GetProjectTemplate("EmptyWebApplicationProject40.zip", "CSharp");

            s2.AddFromTemplate(template, Path.Combine(TestCaseDirectory, "WebAppProject"), "WebAppProject.csproj");

            // To be discovered on save of dependent file
            File.WriteAllText(Path.Combine(TestCaseDirectory, "WebAppProject", "_mixins.less"), "// Content...");

            AddProjectFile(Path.Combine(TestCaseDirectory, "WebAppProject", "base.less"), "@import url('//google.com/webfonts'); body { font: sans-serif }");

            AddProjectFile(Path.Combine(TestCaseDirectory, "WebAppProject", "page.less"), "@import 'base';");

            await graph.RescanComplete;

            var deps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(TestCaseDirectory, "WebAppProject", "base.less")
                );

            deps
            .Select(Path.GetFileName)
            .Should()
            .BeEquivalentTo(new[] { "page.less" });

            var window = VSHost.DTE.ItemOperations.OpenFile(Path.Combine(TestCaseDirectory, "WebAppProject", "base.less"));
            await VSHost.TypeString("@import url(\"./_mixins\");\n");

            window.Document.Save();

            await graph.RescanComplete;

            deps = await graph.GetRecursiveDependentsAsync(
                Path.Combine(TestCaseDirectory, "WebAppProject", "_mixins.less")
                );

            deps
            .Select(Path.GetFileName)
            .Should()
            .BeEquivalentTo(new[] { "base.less", "page.less" });
        }
Ejemplo n.º 16
0
        public async Task SolutionSettingsMigrationTest()
        {
            SettingsStore.InTestMode = false;   // Enable settings load
            File.Delete(Path.Combine(VSHost.FixtureDirectory, "LegacySettings", SettingsStore.FileName));

            VSHost.EnsureSolution(@"LegacySettings\LegacySettings.sln");
            await Task.Delay(750);  // Wait for things to load

            File.Exists(Path.Combine(VSHost.FixtureDirectory, "LegacySettings", SettingsStore.FileName))
            .Should().BeTrue("opening solution with legacy settings file should create new settings file");

            // Check some non-default values from the legacy XML
            WESettings.Instance.Less.CompileOnSave.Should().BeFalse();
            WESettings.Instance.TypeScript.LintOnSave.Should().BeFalse();

            // Check default values for new settings
            WESettings.Instance.Html.GzipMinifiedFiles.Should().BeFalse();
            WESettings.Instance.Less.EnableChainCompilation.Should().BeTrue();
        }
Ejemplo n.º 17
0
        public async Task DontActivateElsewhere()
        {
            var textView = await VSHost.TypeText(".js", "var x = {\n'u");

            textView.IsCompletionOpen().Should().BeFalse();
        }
Ejemplo n.º 18
0
        public async Task UseAsmFunction()
        {
            var textView = await VSHost.TypeText(".js", "var a=function(){\n\"use a\"");

            textView.GetText().Should().EndWith("\"use asm\"\r\n}");
        }
Ejemplo n.º 19
0
 public void Init()
 {
     item      = VSHost.EnsureSolution(@"CodeGen\CodeGen.sln").FindProjectItem("CollectionModel.cs");
     theObject = IntellisenseParser.ProcessFile(item).First();
 }
Ejemplo n.º 20
0
 public void Init()
 {
     _item      = VSHost.EnsureSolution(@"CodeGen\CodeGen.sln").FindProjectItem("Simple.cs");
     _theObject = IntellisenseParser.ProcessFile(_item).First();
 }
Ejemplo n.º 21
0
        protected IEnumerable <Currency> ParseCurrent(string path)
        {
            var source = VSHost.ResolvePath(path);

            using (var reader = XmlReader.Create(source, s_Settings))
            {
                var root = XElement.Load(reader, LoadOptions.None);
                var list = root.Element("CcyTbl").Elements("CcyNtry");

                foreach (var item in list)
                {
                    // Currency Alphabetic Code.
                    var codeElement = item.Element("Ccy");
                    if (codeElement == null)
                    {
                        if (Debug)
                        {
                            Warning("Found a currency without a universal currency: " + item.Element("CtryNm").Value);
                        }

                        continue;
                    }

                    var code = codeElement.Value;

                    // Currency Numeric Code.
                    // NB: Int16.Parse should never fail.
                    var numericCode = Int16.Parse(item.Element("CcyNbr").Value);

                    // Currency English Name.
                    var englishNameElement = item.Element("CcyNm");
                    var englishName        = englishNameElement.Value
                                             .Replace("\"", "\"\"");

                    // Fund Currency.
                    bool isFund     = false;
                    var  isFundAttr = englishNameElement.Attribute("IsFund");
                    if (isFundAttr != null)
                    {
                        isFund = isFundAttr.Value == "true";
                    }

                    // Country English Name.
                    var englishRegionName = item.Element("CtryNm").Value
                                            .Replace("’", "'")
                                            .Replace("\"", "\"\"")
                                            .Replace("\n", String.Empty);

                    // Minor Units.
                    var   minorUnitsValue = item.Element("CcyMnrUnts").Value;
                    short?minorUnits      = null;
                    if (minorUnitsValue != "N.A.")
                    {
                        // NB: ParseTo should never fail.
                        minorUnits = Int16.Parse(minorUnitsValue);
                    }

                    yield return(new Currency
                    {
                        Code = code,
                        EnglishName = englishName,
                        EnglishRegionName = englishRegionName,
                        IsFund = isFund,
                        MinorUnits = minorUnits,
                        NumericCode = numericCode,
                    });
                }
            }
        }
 public static void Initialize(TestContext c)
 {
     SettingsStore.EnterTestMode();
     VSHost.EnsureSolution(@"ProjectEnumeration\ProjectEnumeration.sln");
 }
Ejemplo n.º 23
0
        public async Task GetElementsByTagName()
        {
            var textView = await VSHost.TypeText(".js", "document.body.getElementsByTagName('ta')");

            textView.GetText().Should().Be("document.body.getElementsByTagName('table')");
        }
Ejemplo n.º 24
0
        protected IEnumerable <Currency> ParseLegacy(string path)
        {
            var source = VSHost.ResolvePath(path);

            using (var reader = XmlReader.Create(source, s_Settings))
            {
                var root = XElement.Load(reader, LoadOptions.None);
                var list = root.Element("HstrcCcyTbl").Elements("HstrcCcyNtry");

                foreach (var item in list)
                {
                    // Currency Alphabetic Code
                    var code = item.Element("Ccy").Value;

                    // Currency Numeric Code
                    // NB: ParseTo should never fail.
                    var   numericCodeElement = item.Element("CcyNbr");
                    short numericCode;
                    if (numericCodeElement == null)
                    {
                        if (Debug)
                        {
                            Warning("Found a legacy currency without a numeric code: " + item.Element("CtryNm").Value);
                        }

                        numericCode = (short)0;
                    }
                    else
                    {
                        numericCode = Int16.Parse(numericCodeElement.Value);
                    }

                    // Currency English Name
                    var englishNameElement = item.Element("CcyNm");
                    var englishName        = englishNameElement.Value
                                             .Replace("\"", "\"\"");

                    // Fund Currency
                    bool isFund     = false;
                    var  isFundAttr = englishNameElement.Attribute("IsFund");
                    if (isFundAttr != null)
                    {
                        // NB: There are whitespace-only values, there are interpreted to be the same as no attibrute.
                        isFund = isFundAttr.Value == "true";
                    }

                    // Country English Name
                    var englishRegionName = item.Element("CtryNm").Value
                                            .Replace("’", "'")
                                            .Replace("\"", "\"\"")
                                            .Replace("\n", String.Empty);

                    yield return(new Currency
                    {
                        Code = code,
                        EnglishName = englishName,
                        EnglishRegionName = englishRegionName,
                        IsFund = isFund,
                        IsLegacy = true,
                        NumericCode = numericCode,
                    });
                }
            }
        }