Exemplo n.º 1
0
        private async Task VerifyCSharpAsync(string source, string shippedApiText, string unshippedApiText, params DiagnosticResult[] expected)
        {
            var test = new CSharpCodeFixTest <DeclarePublicApiAnalyzer, AnnotatePublicApiFix, XUnitVerifier>
            {
                TestState =
                {
                    Sources         = { source },
                    AdditionalFiles = {        },
                },
                TestBehaviors = TestBehaviors.SkipGeneratedCodeCheck,
            };

            if (shippedApiText != null)
            {
                test.TestState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.ShippedFileName, shippedApiText));
            }

            if (unshippedApiText != null)
            {
                test.TestState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.UnshippedFileName, unshippedApiText));
            }

            test.ExpectedDiagnostics.AddRange(expected);
            await test.RunAsync();
        }
Exemplo n.º 2
0
        public static async Task VerifyAnalyzerAsync(string source)
        {
            var analysisTester = new CSharpCodeFixTest <NXunitConverterAnalyzer, NXunitConverterFixProvider, MSTestVerifier>();

            analysisTester.ReferenceAssemblies = analysisTester.ReferenceAssemblies.AddPackages(ImmutableArray.Create(new PackageIdentity("nunit", "3.12.0")));
            analysisTester.TestCode            = source;
            analysisTester.TestBehaviors       = TestBehaviors.SkipGeneratedCodeCheck;
            await analysisTester.RunAsync();
        }
        public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
        {
            var test = new CSharpCodeFixTest <TAnalyzer, TCodeFix, XUnitVerifier>
            {
                TestCode = source
            };

            test.ExpectedDiagnostics.AddRange(expected);
            await test.RunAsync();
        }
Exemplo n.º 4
0
        public static async Task VerifyFixAsync(string source, string fixtest, DiagnosticResult expected)
        {
            var fixTester = new CSharpCodeFixTest <NXunitConverterAnalyzer, NXunitConverterFixProvider, MSTestVerifier>();

            fixTester.ReferenceAssemblies = fixTester.ReferenceAssemblies.AddPackages(ImmutableArray.Create(new PackageIdentity("nunit", "3.12.0")));
            fixTester.ReferenceAssemblies = fixTester.ReferenceAssemblies.AddPackages(ImmutableArray.Create(new PackageIdentity("xunit", "2.4.1")));
            fixTester.TestCode            = source;
            fixTester.FixedCode           = fixtest;
            fixTester.TestBehaviors       = TestBehaviors.SkipGeneratedCodeCheck;
            fixTester.ExpectedDiagnostics.Add(expected);
            await fixTester.RunAsync();
        }
Exemplo n.º 5
0
        public static Task VerifyCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
        {
            var test = new CSharpCodeFixTest <TAnalyzer, TCodeFix, TVerifier>
            {
                TestCode            = source,
                FixedCode           = fixedSource,
                ReferenceAssemblies = ReferenceAssemblies.Default,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(CancellationToken.None));
        }
        private async Task VerifyAdditionalFileFixAsync(string source, string oldShippedApiText, string oldUnshippedApiText, string newShippedApiText, string newUnshippedApiText)
        {
            var test = new CSharpCodeFixTest <DeclarePublicApiAnalyzer, AnnotatePublicApiFix, XUnitVerifier>();

            test.TestState.Sources.Add(source);
            test.TestState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.ShippedFileName, oldShippedApiText));
            test.TestState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.UnshippedFileName, oldUnshippedApiText));

            test.FixedState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.ShippedFileName, newShippedApiText));
            test.FixedState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.UnshippedFileName, newUnshippedApiText));

            await test.RunAsync();
        }
Exemplo n.º 7
0
        public static Task Verify(
            string[] sources,
            params DiagnosticResult[] diagnostics)
        {
            var test = new CSharpCodeFixTest <TAnalyzer, EmptyCodeFixProvider, XUnitVerifier>();

            foreach (var source in sources)
            {
                test.TestState.Sources.Add(source);
            }

            test.TestState.ExpectedDiagnostics.AddRange(diagnostics);

            test.TestState.AdditionalReferences.AddRange(new[]
        private async Task VerifyAdditionalFileFixAsync(string source, string oldShippedApiText, string oldUnshippedApiText, string newSource, string newShippedApiText, string newUnshippedApiText)
        {
            var test = new CSharpCodeFixTest <DeclarePublicApiAnalyzer, NullableEnablePublicApiFix, XUnitVerifier>();

            test.TestBehaviors |= TestBehaviors.SkipGeneratedCodeCheck;

            test.TestState.Sources.Add(source);
            test.TestState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.ShippedFileName, oldShippedApiText));
            test.TestState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.UnshippedFileName, oldUnshippedApiText));

            test.FixedState.Sources.Add(newSource);
            test.FixedState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.ShippedFileName, newShippedApiText));
            test.FixedState.AdditionalFiles.Add((DeclarePublicApiAnalyzer.UnshippedFileName, newUnshippedApiText));

            await test.RunAsync();
        }
Exemplo n.º 9
0
        private async Task VerifyCSharpAsync(string source, string shippedApiText, string unshippedApiText, string shippedApiFilePath, string unshippedApiFilePath, params DiagnosticResult[] expected)
        {
            var test = new CSharpCodeFixTest <DeclarePublicApiAnalyzer, DeclarePublicApiFix, XUnitVerifier>
            {
                TestState =
                {
                    Sources         = { source },
                    AdditionalFiles = {        },
                }
            };

            if (shippedApiText != null)
            {
                test.TestState.AdditionalFiles.Add((shippedApiFilePath, shippedApiText));
            }

            if (unshippedApiText != null)
            {
                test.TestState.AdditionalFiles.Add((unshippedApiFilePath, unshippedApiText));
            }

            test.ExpectedDiagnostics.AddRange(expected);
            await test.RunAsync();
        }