|
| 1 | +// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +namespace StyleCop.Analyzers.Test.SpecialRules |
| 5 | +{ |
| 6 | + using System.Collections.Generic; |
| 7 | + using System.Threading; |
| 8 | + using System.Threading.Tasks; |
| 9 | + using Analyzers.Settings; |
| 10 | + using Analyzers.SpecialRules; |
| 11 | + using Microsoft.CodeAnalysis.Diagnostics; |
| 12 | + using TestHelper; |
| 13 | + using Xunit; |
| 14 | + |
| 15 | + /// <summary> |
| 16 | + /// Unit tests for <see cref="SA0002InvalidSettingsFile"/>. |
| 17 | + /// </summary> |
| 18 | + public class SA0002UnitTests : DiagnosticVerifier |
| 19 | + { |
| 20 | + private const string TestCode = @" |
| 21 | +namespace NamespaceName { } |
| 22 | +"; |
| 23 | + |
| 24 | + private string settings; |
| 25 | + |
| 26 | + [Fact] |
| 27 | + public async Task TestMissingSettingsAsync() |
| 28 | + { |
| 29 | + await this.VerifyCSharpDiagnosticAsync(TestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public async Task TestValidSettingsAsync() |
| 34 | + { |
| 35 | + this.settings = SettingsFileCodeFixProvider.DefaultSettingsFileContent; |
| 36 | + |
| 37 | + await this.VerifyCSharpDiagnosticAsync(TestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); |
| 38 | + } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public async Task TestInvalidSettingsAsync() |
| 42 | + { |
| 43 | + this.settings = @" |
| 44 | +{ |
| 45 | + ""$schema"": ""https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json"" |
| 46 | + ""settings"": { |
| 47 | + ""documentationRules"": { |
| 48 | + ""companyName"": ""ACME, Inc"", |
| 49 | + ""copyrightText"": ""Copyright 2015 {companyName}. All rights reserved."" |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | +"; |
| 54 | + |
| 55 | + DiagnosticResult expected = this.CSharpDiagnostic().WithLocation(null, 0, 0); |
| 56 | + |
| 57 | + await this.VerifyCSharpDiagnosticAsync(TestCode, expected, CancellationToken.None).ConfigureAwait(false); |
| 58 | + } |
| 59 | + |
| 60 | + /// <inheritdoc/> |
| 61 | + protected override string GetSettings() |
| 62 | + { |
| 63 | + return this.settings; |
| 64 | + } |
| 65 | + |
| 66 | + /// <inheritdoc/> |
| 67 | + protected override IEnumerable<DiagnosticAnalyzer> GetCSharpDiagnosticAnalyzers() |
| 68 | + { |
| 69 | + yield return new SA0002InvalidSettingsFile(); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments