Ejemplo n.º 1
0
            public static void FixDoesNotMatchAnalyzer()
            {
                var code = @"
namespace N
{
    class C
    {
        private readonly int ↓_value;
    }
}";

                var fixedCode = @"
namespace N
{
    class C
    {
        private readonly int value;
    }
}";
                var expected  = "NopAnalyzer does not produce diagnostics fixable by DoNotUseUnderscoreFix.\r\n" +
                                "NopAnalyzer.SupportedDiagnostics: 'IdWithNoFix'.\r\n" +
                                "DoNotUseUnderscoreFix.FixableDiagnosticIds: {SA1309, SA1309a, SA1309b}.";
                var analyzer  = new NopAnalyzer(Descriptors.IdWithNoFix);
                var fix       = new DoNotUseUnderscoreFix();
                var exception = Assert.Throws <AssertException>(() => RoslynAssert.NoFix(analyzer, fix, code, fixedCode));

                Assert.AreEqual(expected, exception.Message);
            }
Ejemplo n.º 2
0
        public void ClassLibrary1NopAnalyzer()
        {
            var analyzer   = new NopAnalyzer();
            var code       = ProjectFile.Find("ClassLibrary1.csproj");
            var descriptor = NopAnalyzer.Descriptor;

            RoslynAssert.Valid(typeof(NopAnalyzer), descriptor, code);
            RoslynAssert.Valid(analyzer, descriptor, code);
            RoslynAssert.Valid(analyzer, code, compilationOptions: CodeFactory.DefaultCompilationOptions(analyzer, descriptor, null));
        }
Ejemplo n.º 3
0
            public static void WithTransitiveMetadataReference()
            {
                var code               = @"
namespace N
{
    class C
    {
    }
}";
                var analyzer           = new NopAnalyzer();
                var metadataReferences = Gu.Roslyn.Asserts.MetadataReferences.Transitive(typeof(Microsoft.CodeAnalysis.CSharp.CSharpCompilation)).ToArray();

                RoslynAssert.Valid(analyzer, code, metadataReferences: metadataReferences, compilationOptions: CodeFactory.DefaultCompilationOptions(analyzer));
            }
Ejemplo n.º 4
0
            public static void WithSingleMetadataReference()
            {
                var code               = @"
namespace N
{
    class C
    {
    }
}";
                var analyzer           = new NopAnalyzer();
                var metadataReferences = new[] { Gu.Roslyn.Asserts.MetadataReferences.CreateFromAssembly(typeof(object).Assembly) };

                RoslynAssert.Valid(analyzer, code, metadataReferences: metadataReferences, compilationOptions: CodeFactory.DefaultCompilationOptions(analyzer));
            }
Ejemplo n.º 5
0
            public static void ProjectFileNopAnalyzer()
            {
                Assert.Inconclusive("This has dependency problems in bot net472 and netcoreapp.");
                var code = ProjectFile.Find("Gu.Roslyn.Asserts.csproj");
                var metadataReferences = Gu.Roslyn.Asserts.MetadataReferences.Transitive(
                    typeof(Microsoft.CodeAnalysis.CSharp.CSharpCompilation),
                    typeof(Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider))
                                         .ToArray();
                var descriptor = Descriptors.Id1;
                var analyzer   = new NopAnalyzer(descriptor);

                RoslynAssert.Valid(analyzer, code, metadataReferences: metadataReferences);
                RoslynAssert.Valid(typeof(NopAnalyzer), code, metadataReferences: metadataReferences);

                RoslynAssert.Valid(analyzer, descriptor, code, metadataReferences: metadataReferences);
                RoslynAssert.Valid(typeof(NopAnalyzer), descriptor, code, metadataReferences: metadataReferences);
            }
Ejemplo n.º 6
0
            public static void SingleDocumentNopAnalyzer()
            {
                var code       = @"
namespace N
{
    class C
    {
    }
}";
                var descriptor = Descriptors.Id1;
                var analyzer   = new NopAnalyzer(descriptor);

                RoslynAssert.Valid(analyzer, code);
                RoslynAssert.Valid(typeof(NopAnalyzer), code);

                RoslynAssert.Valid(analyzer, descriptor, code);
                RoslynAssert.Valid(typeof(NopAnalyzer), descriptor, code);
            }
Ejemplo n.º 7
0
            public static void SevenPointThreeFeature()
            {
                var code       = @"
namespace N
{
    class C<T>
        where T : struct, System.Enum
    {
    }
}";
                var descriptor = Descriptors.Id1;
                var analyzer   = new NopAnalyzer(descriptor);

                RoslynAssert.Valid(analyzer, code);
                RoslynAssert.Valid(typeof(NopAnalyzer), code);

                RoslynAssert.Valid(analyzer, descriptor, code);
                RoslynAssert.Valid(typeof(NopAnalyzer), descriptor, code);
            }
Ejemplo n.º 8
0
            public static void TwoProjectsNopAnalyzer()
            {
                var code1    = @"
namespace Project1
{
    class Code1
    {
    }
}";
                var code2    = @"
namespace Project2
{
    class Code2
    {
    }
}";
                var analyzer = new NopAnalyzer();

                RoslynAssert.Valid(analyzer, code1, code2);
                RoslynAssert.Valid(analyzer, code2, code1);
                RoslynAssert.Valid(typeof(NopAnalyzer), code1, code2);
            }