示例#1
0
        private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, bool offerEmptyFixer, CancellationToken cancellationToken)
        {
            string contentWithValue           = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <summary>Foo</summary>
    <value>Bar</value>
  </Property>
</ClassName>
";
            string contentWithoutValue        = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <summary>Foo</summary>
  </Property>
</ClassName>
";
            string contentWithEmptyValue      = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <summary>Foo</summary>
    <value>  </value>
  </Property>
</ClassName>
";
            string contentWithInheritdocValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <inheritdoc/>
  </Property>
</ClassName>
";

            var test = new StyleCopCodeFixVerifier <SA1610PropertyDocumentationMustHaveValueText, SA1609SA1610CodeFixProvider> .CSharpTest
            {
                TestCode      = source,
                FixedCode     = fixedSource,
                XmlReferences =
                {
                    { "PropertyWithValue.xml",      contentWithValue           },
                    { "PropertyWithoutValue.xml",   contentWithoutValue        },
                    { "PropertyWithEmptyValue.xml", contentWithEmptyValue      },
                    { "PropertyWithInheritdoc.xml", contentWithInheritdocValue },
                },
            };

            if (source == fixedSource && offerEmptyFixer)
            {
                test.NumberOfIncrementalIterations = 1;
                test.NumberOfFixAllIterations      = 1;
            }

            test.ExpectedDiagnostics.AddRange(expected);

            return(test.RunAsync(cancellationToken));
        }
示例#2
0
        private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1200UsingDirectivesMustBePlacedCorrectly, UsingCodeFixProvider> .CSharpTest
            {
                TestCode = source,
                Settings = TestSettings,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
示例#3
0
        protected static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1402FileMayOnlyContainASingleType, SA1402CodeFixProvider> .CSharpTest
            {
                TestCode = source,
                Settings = testSettings,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1027UseTabsCorrectly, SA1027CodeFixProvider> .CSharpTest
            {
                TestCode = source,
                UseTabs  = true,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1217UsingStaticDirectivesMustBeOrderedAlphabetically, UsingCodeFixProvider> .CSharpTest
            {
                TestCode = source,
                Settings = this.useSystemUsingDirectivesFirst ? TestSettings : TestSettingsNoSystemDirectivesFirst,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpFixAsync(string source, string testSettings, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <FileHeaderAnalyzers, FileHeaderCodeFixProvider> .CSharpTest
            {
                TestCode  = source,
                FixedCode = fixedSource,
                Settings  = testSettings,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace, UsingCodeFixProvider> .CSharpTest
            {
                TestCode  = source,
                FixedCode = fixedSource,
                Settings  = CombinedUsingDirectivesTestSettings,
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
示例#8
0
        protected Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, DiagnosticResult[] remainingDiagnostics, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <FileHeaderAnalyzers, FileHeaderCodeFixProvider> .CSharpTest
            {
                TestCode  = source,
                FixedCode = fixedSource,
                Settings  = this.GetSettings(),
            };

            test.ExpectedDiagnostics.AddRange(expected);
            test.RemainingDiagnostics.AddRange(remainingDiagnostics);
            test.DisabledDiagnostics.AddRange(this.GetDisabledDiagnostics());
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
        {
            string contentWithValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <summary>Foo</summary>
    <value>Bar</value>
  </Property>
</ClassName>
";

            string contentWithoutValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <summary>Foo</summary>
  </Property>
</ClassName>
";

            string contentWithInheritdocValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Property>
    <inheritdoc/>
  </Property>
</ClassName>
";

            var test = new StyleCopCodeFixVerifier <SA1609PropertyDocumentationMustHaveValue, SA1609SA1610CodeFixProvider> .CSharpTest
            {
                TestCode      = source,
                FixedCode     = fixedSource,
                XmlReferences =
                {
                    { "PropertyWithValue.xml",      contentWithValue           },
                    { "PropertyWithoutValue.xml",   contentWithoutValue        },
                    { "PropertyWithInheritdoc.xml", contentWithInheritdocValue },
                },
            };

            if (source == fixedSource)
            {
                test.FixedState.InheritanceMode      = StateInheritanceMode.AutoInheritAll;
                test.FixedState.MarkupHandling       = MarkupMode.Allow;
                test.BatchFixedState.InheritanceMode = StateInheritanceMode.AutoInheritAll;
                test.BatchFixedState.MarkupHandling  = MarkupMode.Allow;
            }

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
示例#10
0
        private static Task VerifyCSharpDiagnosticAsync(OptionSetting?newlineAtEndOfFile, string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1518UseLineEndingsCorrectlyAtEndOfFile, SA1518CodeFixProvider> .CSharpTest
            {
                TestCode = source,
            };

            if (newlineAtEndOfFile != null)
            {
                test.Settings = GetSettings(newlineAtEndOfFile.Value);
            }

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
        {
            string contentWithReturns          = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Class1>
  <MethodName>
    <summary>
      Sample method.
    </summary>
    <returns>
      A <see cref=""Task""/> representing the asynchronous operation.
    </returns>
  </MethodName>
</Class1>
";
            string contentWithInheritedReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Class1>
  <MethodName>
    <inheritdoc/>
  </MethodName>
</Class1>
";
            string contentWithoutReturns       = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Class1>
  <MethodName>
    <summary>
      Sample method.
    </summary>
  </MethodName>
</Class1>
";

            var test = new StyleCopCodeFixVerifier <SA1615ElementReturnValueMustBeDocumented, SA1615SA1616CodeFixProvider> .CSharpTest
            {
                TestCode      = source,
                FixedCode     = fixedSource,
                XmlReferences =
                {
                    { "MethodWithReturns.xml",          contentWithReturns          },
                    { "MethodWithInheritedReturns.xml", contentWithInheritedReturns },
                    { "MethodWithoutReturns.xml",       contentWithoutReturns       },
                },
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken)
        {
            var test = new StyleCopCodeFixVerifier <SA1206DeclarationKeywordsMustFollowOrder, SA1206CodeFixProvider> .CSharpTest
            {
                TestCode           = source,
                SolutionTransforms =
                {
                    (solution, projectId) =>
                    {
                        var parseOptions = (CSharpParseOptions)solution.GetProject(projectId).ParseOptions;
                        return(solution.WithProjectParseOptions(projectId, parseOptions.WithLanguageVersion(LanguageVersion.Latest)));
                    },
                },
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
示例#13
0
        private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, CancellationToken cancellationToken)
        {
            string contentWithoutReturns      = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Method>
    <summary>Foo</summary>
  </Method>
</ClassName>
";
            string contentWithReturns         = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Method>
    <summary>Foo</summary>
    <returns>Bar</returns>
  </Method>
</ClassName>
";
            string contentWithInheritdocValue = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
  <Method>
    <inheritdoc/>
  </Method>
</ClassName>
";

            var test = new StyleCopCodeFixVerifier <SA1617VoidReturnValueMustNotBeDocumented, SA1617CodeFixProvider> .CSharpTest
            {
                TestCode      = source,
                FixedCode     = fixedSource,
                XmlReferences =
                {
                    { "MethodWithoutReturns.xml", contentWithoutReturns      },
                    { "MethodWithReturns.xml",    contentWithReturns         },
                    { "MethodWithInheritdoc.xml", contentWithInheritdocValue },
                },
            };

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }
        private static Task VerifyCSharpFixAsync(string source, DiagnosticResult[] expected, string fixedSource, bool offerEmptyFixer, CancellationToken cancellationToken)
        {
            string contentWithoutDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
    <Method>
    </Method>
</ClassName>
";
            string contentWithoutReturns       = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
    <Method>
        <summary>
            Foo
        </summary>
    </Method>
</ClassName>
";
            string contentWithReturns          = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
    <Method>
        <summary>
            Foo
        </summary>
        <returns>Test</returns>
    </Method>
</ClassName>
";
            string contentWithEmptyReturns     = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
    <Method>
        <summary>
            Foo
        </summary>
        <returns>
        
                              </returns>
    </Method>
</ClassName>
";
            string contentWithEmptyReturns2    = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
    <Method>
        <summary>
            Foo
        </summary>
        <returns />
    </Method>
</ClassName>
";
            string contentWithEmptyReturns3    = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
    <Method>
        <summary>
            Foo
        </summary>
        <returns></returns>
    </Method>
</ClassName>
";

            var test = new StyleCopCodeFixVerifier <SA1616ElementReturnValueDocumentationMustHaveText, SA1615SA1616CodeFixProvider> .CSharpTest
            {
                TestCode      = source,
                FixedCode     = fixedSource,
                XmlReferences =
                {
                    { "NoDocumentation.xml",   contentWithoutDocumentation },
                    { "WithoutReturns.xml",    contentWithoutReturns       },
                    { "WithReturns.xml",       contentWithReturns          },
                    { "WithEmptyReturns.xml",  contentWithEmptyReturns     },
                    { "WithEmptyReturns2.xml", contentWithEmptyReturns2    },
                    { "WithEmptyReturns3.xml", contentWithEmptyReturns3    },
                },
            };

            if (source == fixedSource)
            {
                test.FixedState.InheritanceMode      = StateInheritanceMode.AutoInheritAll;
                test.FixedState.MarkupHandling       = MarkupMode.Allow;
                test.BatchFixedState.InheritanceMode = StateInheritanceMode.AutoInheritAll;
                test.BatchFixedState.MarkupHandling  = MarkupMode.Allow;

                if (offerEmptyFixer)
                {
                    test.NumberOfIncrementalIterations = 1;
                    test.NumberOfFixAllIterations      = 1;
                }
            }

            test.ExpectedDiagnostics.AddRange(expected);
            return(test.RunAsync(cancellationToken));
        }