Пример #1
0
        private void TestConfig(StylerOptions stylerOptions, string expectedConfiguration)
        {
            var actualOptions = JsonConvert.SerializeObject(stylerOptions);
            var expectedOptions = File.ReadAllText(this.GetConfiguration(expectedConfiguration));

            Assert.That(Regex.Replace(actualOptions, @"\s+", ""), Is.EqualTo(Regex.Replace(expectedOptions, @"\s+", "")));
        }
Пример #2
0
            public XamlStylerConsole(Options options)
            {
                this.options = options;

                IStylerOptions stylerOptions = new StylerOptions();

                if (this.options.Configuration != null)
                {
                    stylerOptions = this.LoadConfiguration(this.options.Configuration);
                }

                this.stylerService = new StylerService(stylerOptions);
            }
Пример #3
0
        private bool LoadConfiguration(string config)
        {
            try
            {
                StylerOptions configOptions = JsonConvert.DeserializeObject <StylerOptions>(config);

                if (configOptions == null)
                {
                    this.LoadFallbackConfiguration();
                }
                else
                {
                    foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(this))
                    {
                        // Cannot set Config Path from External Configuration.
                        if (propertyDescriptor.Name.Equals(nameof(this.ConfigPath)))
                        {
                            continue;
                        }

                        // If a valid IndentSize is specified in configuration, do not load VS settings.
                        if (propertyDescriptor.Name.Equals(nameof(this.IndentSize)))
                        {
                            int indentSize;
                            try
                            {
                                indentSize = Convert.ToInt32(propertyDescriptor.GetValue(configOptions));
                            }
                            catch (Exception)
                            {
                                indentSize = -1;
                            }


                            // Cannot specify MissingMemberHandling for a single property, so relying on JSON default
                            // value to detect missing member, and setting default on detection.
                            if (indentSize > 0)
                            {
                                this.IndentSize = indentSize;
                                this.UseVisualStudioIndentSize = false;
                            }
                            else
                            {
                                this.IndentSize = StylerOptions.FallbackIndentSize;
                            }
                        }
                        else
                        {
                            propertyDescriptor.SetValue(this, propertyDescriptor.GetValue(configOptions));
                        }
                    }
                }
            }
            catch (Exception)
            {
                this.LoadFallbackConfiguration();
                return(false);
            }

            return(true);
        }
Пример #4
0
 public void TestConfiguration_AllDifferent()
 {
     var stylerOptions = new StylerOptions(config: this.GetConfiguration(@"TestConfigurations\AllDifferent.json"));
     this.TestConfig(stylerOptions, @"TestConfigurations\AllDifferent.json");
 }
Пример #5
0
 public void TestConfiguration_BadSetting()
 {
     var stylerOptions = new StylerOptions(config: this.GetConfiguration(@"TestConfigurations\BadSetting.json"));
     this.TestConfig(stylerOptions, @"TestConfigurations\SerializedDefault.json");
 }
Пример #6
0
 public void TestConfiguration_Single()
 {
     var stylerOptions = new StylerOptions(config: this.GetConfiguration(@"TestConfigurations\Single.json"));
     this.TestConfig(stylerOptions, @"TestConfigurations\Single.json");
 }
Пример #7
0
 public void TestConfiguration_Empty()
 {
     var stylerOptions = new StylerOptions(config: this.GetConfiguration(@"TestConfigurations\Empty.json"));
     this.TestConfig(stylerOptions, @"TestConfigurations\SerializedDefault.json");
 }
Пример #8
0
 private IStylerOptions LoadConfiguration(string path)
 {
     StylerOptions stylerOptions = new StylerOptions(path);
     this.Log(JsonConvert.SerializeObject(stylerOptions), LogLevel.Insanity);
     this.Log(JsonConvert.SerializeObject(stylerOptions.AttributeOrderingRuleGroups), LogLevel.Debug);
     return stylerOptions;
 }