|
| 1 | +// ReSharper disable InconsistentNaming |
| 2 | +#pragma warning disable GURA04, GURA06 // Name of class should match asserts. |
| 3 | +namespace IDisposableAnalyzers.NetCoreTests |
| 4 | +{ |
| 5 | + using System; |
| 6 | + using System.Collections.Immutable; |
| 7 | + using System.Linq; |
| 8 | + using Gu.Roslyn.AnalyzerExtensions; |
| 9 | + using Gu.Roslyn.Asserts; |
| 10 | + using Microsoft.CodeAnalysis; |
| 11 | + using Microsoft.CodeAnalysis.Diagnostics; |
| 12 | + using NUnit.Framework; |
| 13 | + |
| 14 | + public static class ValidWithAllAnalyzers |
| 15 | + { |
| 16 | + private static readonly ImmutableArray<DiagnosticAnalyzer> AllAnalyzers = typeof(KnownSymbol) |
| 17 | + .Assembly |
| 18 | + .GetTypes() |
| 19 | + .Where(typeof(DiagnosticAnalyzer).IsAssignableFrom) |
| 20 | + .Select(t => (DiagnosticAnalyzer)Activator.CreateInstance(t)) |
| 21 | + .ToImmutableArray(); |
| 22 | + |
| 23 | + // ReSharper disable once InconsistentNaming |
| 24 | + private static readonly Solution ValidCodeProjectSln = CodeFactory.CreateSolution( |
| 25 | + ProjectFile.Find("ValidCode.NetCore.csproj"), |
| 26 | + AllAnalyzers, |
| 27 | + MetadataReferences.FromAttributes()); |
| 28 | + |
| 29 | + private static IDisposable cacheTransaction; |
| 30 | + |
| 31 | + [OneTimeSetUp] |
| 32 | + public static void OneTimeSetUp() |
| 33 | + { |
| 34 | + // The cache will be enabled when running in VS. |
| 35 | + // It speeds up the tests and makes them more realistic |
| 36 | + cacheTransaction = SyntaxTreeCache<SemanticModel>.Begin(null); |
| 37 | + } |
| 38 | + |
| 39 | + [OneTimeTearDown] |
| 40 | + public static void OneTimeTearDown() |
| 41 | + { |
| 42 | + cacheTransaction.Dispose(); |
| 43 | + } |
| 44 | + |
| 45 | + [Test] |
| 46 | + public static void NotEmpty() |
| 47 | + { |
| 48 | + CollectionAssert.IsNotEmpty(AllAnalyzers); |
| 49 | + } |
| 50 | + |
| 51 | + [TestCaseSource(nameof(AllAnalyzers))] |
| 52 | + public static void ValidCodeProject(DiagnosticAnalyzer analyzer) |
| 53 | + { |
| 54 | + RoslynAssert.Valid(analyzer, ValidCodeProjectSln); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments