public CSharpTest(LanguageVersion?languageVersion) { this.ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssemblies; this.LanguageVersion = languageVersion ?? this.GetDefaultLanguageVersion(); this.OptionsTransforms.Add(options => options .WithChangedOption(FormattingOptions.IndentationSize, this.Language, this.IndentationSize) .WithChangedOption(FormattingOptions.TabSize, this.Language, this.TabSize) .WithChangedOption(FormattingOptions.UseTabs, this.Language, this.UseTabs)); this.TestState.AdditionalFilesFactories.Add(GenerateSettingsFile); this.CodeActionValidationMode = CodeActionValidationMode.None; this.SolutionTransforms.Add((solution, projectId) => { var corlib = solution.GetProject(projectId).MetadataReferences.OfType <PortableExecutableReference>() .Single(reference => Path.GetFileName(reference.FilePath) == "mscorlib.dll"); var system = solution.GetProject(projectId).MetadataReferences.OfType <PortableExecutableReference>() .Single(reference => Path.GetFileName(reference.FilePath) == "System.dll"); return(solution .RemoveMetadataReference(projectId, corlib) .RemoveMetadataReference(projectId, system) .AddMetadataReference(projectId, corlib.WithAliases(new[] { "global", "corlib" })) .AddMetadataReference(projectId, system.WithAliases(new[] { "global", "system" }))); }); return; // Local function IEnumerable <(string filename, SourceText content)> GenerateSettingsFile() { var settings = this.Settings; StyleCopSettings defaultSettings = new StyleCopSettings(); if (this.IndentationSize != defaultSettings.Indentation.IndentationSize || this.UseTabs != defaultSettings.Indentation.UseTabs || this.TabSize != defaultSettings.Indentation.TabSize) { var indentationSettings = $@" {{ ""settings"": {{ ""indentation"": {{ ""indentationSize"": {this.IndentationSize}, ""useTabs"": {this.UseTabs.ToString().ToLowerInvariant()}, ""tabSize"": {this.TabSize} }} }} }} "; if (string.IsNullOrEmpty(settings)) { settings = indentationSettings; } else { JsonObject indentationObject = JsonReader.Parse(indentationSettings).AsJsonObject; JsonObject settingsObject = JsonReader.Parse(settings).AsJsonObject; JsonObject mergedSettings = JsonTestHelper.MergeJsonObjects(settingsObject, indentationObject); using (var writer = new JsonWriter(pretty: true)) { settings = writer.Serialize(mergedSettings); } } } if (!string.IsNullOrEmpty(settings)) { yield return(this.SettingsFileName, SourceText.From(settings)); } } }