Exemple #1
0
        public void TestAttributeSortingOptionHandling()
        {
            string testInput = MethodBase.GetCurrentMethod().Name + ".xaml";

            var stylerOptions = new StylerOptions
            {
                AttributeOrderClass          = "x:Class",
                AttributeOrderWpfNamespace   = "xmlns, xmlns:x",
                AttributeOrderKey            = "Key, x:Key, Uid, x:Uid",
                AttributeOrderName           = "Name, x:Name, Title",
                AttributeOrderAttachedLayout =
                    "Grid.Column, Grid.ColumnSpan, Grid.Row, Grid.RowSpan, Canvas.Right, Canvas.Bottom, Canvas.Left, Canvas.Top",
                AttributeOrderCoreLayout =
                    "MinWidth, MinHeight, Width, Height, MaxWidth, MaxHeight, Margin",
                AttributeOrderAlignmentLayout =
                    "Panel.ZIndex, HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment, VerticalContentAlignment",
                AttributeOrderOthers =
                    "Offset, Color, TargetName, Property, Value, StartPoint, EndPoint, PageSource, PageIndex",
                AttributeOrderBlendRelated =
                    "mc:Ignorable, d:IsDataSource, d:LayoutOverrides, d:IsStaticText"
            };
            var styler = StylerService.CreateInstance(stylerOptions);

            DoTest(testInput, styler);
        }
Exemple #2
0
        public void TestMarkupExtensionHandling()
        {
            string testInput = MethodBase.GetCurrentMethod().Name + ".xaml";

            var stylerOptions = new StylerOptions
            {
                FormatMarkupExtension = true
            };
            var styler = StylerService.CreateInstance(stylerOptions);

            DoTest(testInput, styler);
        }
Exemple #3
0
        /// <summary>
        /// Style input document and verify output against expected
        /// </summary>
        /// <param name="stylerOptions"></param>
        /// <param name="testFileBaseName"></param>
        /// <param name="expectedSuffix"></param>
        private static void DoTest(StylerOptions stylerOptions, string testFileBaseName, string expectedSuffix)
        {
            var stylerService = StylerService.CreateInstance(stylerOptions);

            var testFileResultBaseName = expectedSuffix != null ? testFileBaseName + "_" + expectedSuffix : testFileBaseName;

            // Excercise stylerService using supplied test xaml data
            string actualOutput = stylerService.ManipulateTreeAndFormatInput(File.ReadAllText(testFileBaseName + ".testxaml"));

            // Write output to ".actual" file for further investigation
            File.WriteAllText(testFileResultBaseName + ".actual", actualOutput, Encoding.UTF8);

            // Check result
            Assert.That(actualOutput, Is.EqualTo(File.ReadAllText(testFileResultBaseName + ".expected")));
        }
Exemple #4
0
        public void TestAttributeThresholdHandling()
        {
            string testInput = MethodBase.GetCurrentMethod().Name + ".xaml";

            var stylerOptions = new StylerOptions
            {
                AttributesTolerance          = 0,
                MaxAttributeCharatersPerLine = 80,
                MaxAttributesPerLine         = 3,
                PutEndingBracketOnNewLine    = true
            };

            var styler = StylerService.CreateInstance(stylerOptions);

            DoTest(testInput, styler);
        }
Exemple #5
0
            public XamlMagicConsole(Options options)
            {
                this.options = options;

                StylerOptions stylerOptions = new StylerOptions();

                if (this.options.Configuration != null)
                {
                    var config = File.ReadAllText(this.options.Configuration);
                    stylerOptions = JsonConvert.DeserializeObject <StylerOptions>(config);

                    if (this.options.LogLevel == LogLevel.Insanity)
                    {
                        this.Log(JsonConvert.SerializeObject(stylerOptions), LogLevel.Insanity);
                    }

                    this.Log(JsonConvert.SerializeObject(stylerOptions.AttributeOrderingRuleGroups), LogLevel.Debug);
                }

                this.stylerService = StylerService.CreateInstance(stylerOptions);
            }
Exemple #6
0
        private void Execute(Document document)
        {
            if (!IsFormatableDocument(document))
            {
                return;
            }

            Properties xamlEditorProps = _dte.Properties["TextEditor", "XAML"];

            var stylerOptions = GetDialogPage(typeof(PackageOptions)).AutomationObject as IStylerOptions;

            stylerOptions.IndentSize     = Int32.Parse(xamlEditorProps.Item("IndentSize").Value.ToString());
            stylerOptions.IndentWithTabs = (bool)xamlEditorProps.Item("InsertTabs").Value;

            StylerService styler = StylerService.CreateInstance(stylerOptions);

            var textDocument = (TextDocument)document.Object("TextDocument");

            TextPoint currentPoint   = textDocument.Selection.ActivePoint;
            int       originalLine   = currentPoint.Line;
            int       originalOffset = currentPoint.LineCharOffset;

            EditPoint startPoint = textDocument.StartPoint.CreateEditPoint();
            EditPoint endPoint   = textDocument.EndPoint.CreateEditPoint();

            string xamlSource = startPoint.GetText(endPoint);

            xamlSource = styler.Format(xamlSource);

            startPoint.ReplaceText(endPoint, xamlSource, 0);

            if (originalLine <= textDocument.EndPoint.Line)
            {
                textDocument.Selection.MoveToLineAndOffset(originalLine, originalOffset);
            }
            else
            {
                textDocument.Selection.GotoLine(textDocument.EndPoint.Line);
            }
        }
Exemple #7
0
 private void DoTest(StylerOptions stylerOptions, int testNumber, [System.Runtime.CompilerServices.CallerMemberName] string callerMemberName = "")
 {
     // ReSharper disable once ExplicitCallerInfoArgument
     DoTest(StylerService.CreateInstance(stylerOptions), testNumber, callerMemberName);
 }
Exemple #8
0
 private void DoTest(string testInput)
 {
     DoTest(testInput, StylerService.CreateInstance(new StylerOptions()));
 }