public async Task VerifyCodefixForElsePartOfDirectiveTriviaAsync() { var testCode = @"namespace NamespaceName { #if false using System.Runtime.CompilerServices; #else using System.Collections.Generic; using System.Collections.Concurrent; #endif } "; var fixedTestCode = @"namespace NamespaceName { #if false using System.Runtime.CompilerServices; #else using System.Collections.Concurrent; using System.Collections.Generic; #endif } "; var expected = StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(6, 5); await this.VerifyCSharpFixAsync(testCode, new[] { expected }, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
public async Task VerifyUsingReorderingWithoutMovingWithFileHeaderAsync() { var testCode = @"// This is a file header. using Microsoft.CodeAnalysis; using System; namespace Foo { public class Bar { } } "; var fixedTestCode = @"// This is a file header. using System; using Microsoft.CodeAnalysis; namespace Foo { public class Bar { } } "; this.usingDirectivesPlacement = UsingDirectivesPlacement.OutsideNamespace; var expected = StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(4, 1).WithArguments("System", "Microsoft.CodeAnalysis"); await this.VerifyCSharpFixAsync(testCode, new[] { expected }, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
private static StyleCopDiagnosticVerifier <SA1648InheritDocMustBeUsedWithInheritingClass> .CSharpTest CreateTest(DiagnosticResult[] expected) { string contentClassInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <inheritdoc/> </TestClass> "; string contentMethodInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <inheritdoc/> </TestMethod> </TestClass> "; string contentDelegateInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestDelegate> <inheritdoc/> </TestDelegate> "; var test = new StyleCopDiagnosticVerifier <SA1648InheritDocMustBeUsedWithInheritingClass> .CSharpTest { XmlReferences = { { "ClassInheritDoc.xml", contentClassInheritDoc }, { "MethodInheritDoc.xml", contentMethodInheritDoc }, { "DelegateInheritDoc.xml", contentDelegateInheritDoc }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test); }
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> </ClassName> "; string contentWithSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <summary> Foo </summary> </ClassName> "; string contentWithDefaultSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <summary> Summary description for the ClassName class. </summary> </ClassName> "; var test = new StyleCopDiagnosticVerifier <SA1608ElementDocumentationMustNotHaveDefaultSummary> .CSharpTest { TestCode = source, XmlReferences = { { "ClassWithoutSummary.xml", contentWithoutSummary }, { "ClassWithSummary.xml", contentWithSummary }, { "ClassWithDefaultSummary.xml", contentWithDefaultSummary }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
public async Task VerifyRegressionFor2027Async() { this.disableSA1200 = true; var testCode = @"using System; using System.Reflection; using System.Net; namespace MyNamespace { using System.Threading.Tasks; } "; var fixedTestCode = @"using System; using System.Net; using System.Reflection; namespace MyNamespace { using System.Threading.Tasks; } "; var expected = StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(2, 1); await this.VerifyCSharpFixAsync(testCode, new[] { expected }, fixedTestCode, CancellationToken.None).ConfigureAwait(false); }
private static StyleCopDiagnosticVerifier <SA1627DocumentationTextMustNotBeEmpty> .CSharpTest CreateTest(DiagnosticResult[] expected) { string contentAllFilled = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary>This is a test method.</summary> <param name=""first"">The first parameter.</param> <remarks>Test remarks</remarks> <example>Test example</example> <permission>Test permission</permission> <exception>Test exception</exception> </TestMethod> </TestClass> "; string contentInheritDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <inheritdoc/> </TestMethod> </TestClass> "; string contentAllButOneFilled = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary>This is a test method.</summary> <param name=""first"">The first parameter.</param> <remarks>Test remarks</remarks> <example>Test example</example> <permission></permission> <exception>Test exception</exception> </TestMethod> </TestClass> "; string contentNoneFilled = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary>This is a test method.</summary> <param name=""first"">The first parameter.</param> <remarks></remarks> <example></example> <permission></permission> <exception></exception> </TestMethod> </TestClass> "; var test = new StyleCopDiagnosticVerifier <SA1627DocumentationTextMustNotBeEmpty> .CSharpTest { XmlReferences = { { "AllFilled.xml", contentAllFilled }, { "InheritDoc.xml", contentInheritDoc }, { "AllButOneFilled.xml", contentAllButOneFilled }, { "NoneFilled.xml", contentNoneFilled }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test); }
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentClassWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <summary>Test class</summary> <typeparam name=""T"">Param 1</typeparam> </TestClass> "; string contentMethodWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary>Test class</summary> <typeparam name=""T"">Param 1</typeparam> </TestMethod> </TestClass> "; string contentClassWithoutTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <summary>Test class</summary> </TestClass> "; string contentMethodWithoutTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary>Test class</summary> </TestMethod> </TestClass> "; string contentClassInheritdoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <inheritdoc/> </TestClass> "; string contentMethodWithInheritdoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <inheritdoc/> </TestMethod> </TestClass> "; var test = new StyleCopDiagnosticVerifier <SA1618GenericTypeParametersMustBeDocumented> .CSharpTest { TestCode = source, XmlReferences = { { "ClassWithTypeparamDoc.xml", contentClassWithTypeparamDoc }, { "MethodWithTypeparamDoc.xml", contentMethodWithTypeparamDoc }, { "ClassWithoutTypeparamDoc.xml", contentClassWithoutTypeparamDoc }, { "MethodWithoutTypeparamDoc.xml", contentMethodWithoutTypeparamDoc }, { "ClassWithIneheritdoc.xml", contentClassInheritdoc }, { "MethodWithInheritdoc.xml", contentMethodWithInheritdoc }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
public async Task VerifyUsingReorderingAsync() { var testCode = @"using Microsoft.CodeAnalysis; using SystemAction = System.Action; using static System.Math; using System; using static System.String; using MyFunc = System.Func<int,bool>; using System.Collections.Generic; using System.Collections; namespace Foo { public class Bar { } } "; var fixedTestCode = @"namespace Foo { using System; using System.Collections; using System.Collections.Generic; using Microsoft.CodeAnalysis; using static System.Math; using static System.String; using MyFunc = System.Func<int,bool>; using SystemAction = System.Action; public class Bar { } } "; DiagnosticResult[] expected = { Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(1, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(2, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(3, 1), StyleCopDiagnosticVerifier <SA1216UsingStaticDirectivesMustBePlacedAtTheCorrectLocation> .Diagnostic().WithLocation(3, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(4, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(4, 1).WithArguments("System","System.Math"), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(6, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(7, 1), StyleCopDiagnosticVerifier <SA1209UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives> .Diagnostic().WithLocation(7, 1), StyleCopDiagnosticVerifier <SA1211UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName> .Diagnostic().WithLocation(7, 1).WithArguments("MyFunc","SystemAction"), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(9, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(9, 1).WithArguments("System.Collections.Generic","System.Math"), StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(9, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(10, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(10, 1).WithArguments("System.Collections","System.Math"), }; await this.VerifyCSharpFixAsync(testCode, expected, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary> Foo </summary> </TestMethod> </TestClass> "; string contentWithElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary> Foo </summary> <param name=""param1"">Param 1</param> <param name=""param2"">Param 2</param> <param name=""param3"">Param 3</param> </TestMethod> </TestClass> "; string contentWithPartialElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <summary> Foo </summary> <param name=""param2"">Param 2</param> <param name=""param3"">Param 3</param> </TestMethod> </TestClass> "; string contentWithInheritedDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <TestMethod> <inheritdoc /> </TestMethod> </TestClass> "; var test = new StyleCopDiagnosticVerifier <SA1611ElementParametersMustBeDocumented> .CSharpTest { TestCode = source, XmlReferences = { { "MissingElementDocumentation.xml", contentWithoutElementDocumentation }, { "WithElementDocumentation.xml", contentWithElementDocumentation }, { "WithPartialElementDocumentation.xml", contentWithPartialElementDocumentation }, { "InheritedDocumentation.xml", contentWithInheritedDocumentation }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken) { var test = new StyleCopDiagnosticVerifier <SA1601PartialElementsMustBeDocumented> .CSharpTest { TestCode = source, Settings = testSettings, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
public async Task VerifyUsingReorderingWithGlobalAttributesAsync() { var testCode = @"using Microsoft.CodeAnalysis; using SystemAction = System.Action; using static System.Math; using System.Reflection; using static System.String; using MyFunc = System.Func<int,bool>; using System.Collections.Generic; using System.Collections; [assembly: AssemblyVersion(""1.0.0.0"")] namespace NamespaceName { public class Bar { } } "; var fixedTestCode = @"using Microsoft.CodeAnalysis; using System.Collections; using System.Collections.Generic; using System.Reflection; using static System.Math; using static System.String; using MyFunc = System.Func<int,bool>; using SystemAction = System.Action; [assembly: AssemblyVersion(""1.0.0.0"")] namespace NamespaceName { public class Bar { } } "; DiagnosticResult[] expected = { StyleCopDiagnosticVerifier <SA1216UsingStaticDirectivesMustBePlacedAtTheCorrectLocation> .Diagnostic().WithLocation(3, 1), StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(4, 1), StyleCopDiagnosticVerifier <SA1209UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives> .Diagnostic().WithLocation(7, 1), StyleCopDiagnosticVerifier <SA1211UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName> .Diagnostic().WithLocation(7, 1).WithArguments("MyFunc","SystemAction"), StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(9, 1), }; await this.VerifyCSharpFixAsync(testCode, expected, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
private static StyleCopDiagnosticVerifier <GenericTypeParameterDocumentationAnalyzer> .CSharpTest CreateTest(DiagnosticResult[] expected) { string contentTypeWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <Foo> <summary>Test class</summary> <typeparam name=""Ta"">Param 1</typeparam> <typeparam name=""Tb"">Param 2</typeparam> </Foo> "; string contentTypeWithEmptyTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <Foo> <summary>Test class</summary> <typeparam name=""Ta""></typeparam> <typeparam name=""Tb""/> </Foo> "; string contentMethodWithTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Foo> <summary>Test class</summary> <typeparam name=""Ta"">Param 1</typeparam> <typeparam name=""Tb"">Param 2</typeparam> </Foo> </TestClass> "; string contentMethodWithEmptyTypeparamDoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Foo> <summary>Test class</summary> <typeparam name=""Ta""/> <typeparam name=""Tb""></typeparam> </Foo> </TestClass> "; var test = new StyleCopDiagnosticVerifier <GenericTypeParameterDocumentationAnalyzer> .CSharpTest { XmlReferences = { { "TypeWithTypeparamsDoc.xml", contentTypeWithTypeparamDoc }, { "TypeWithEmptyTypeparamsDoc.xml", contentTypeWithEmptyTypeparamDoc }, { "MethodWithTypeparamsDoc.xml", contentMethodWithTypeparamDoc }, { "MethodWithEmptyTypeparamsDoc.xml", contentMethodWithEmptyTypeparamDoc }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test); }
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithSummary = @"<?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 contentWithInheritedSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <Class1> <MethodName> <inheritdoc/> </MethodName> </Class1> "; string contentWithEmptySummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <Class1> <MethodName> <summary> </summary> <returns> A <see cref=""Task""/> representing the asynchronous operation. </returns> </MethodName> </Class1> "; var test = new StyleCopDiagnosticVerifier <SA1606ElementDocumentationMustHaveSummaryText> .CSharpTest { TestCode = source, XmlReferences = { { "ClassWithSummary.xml", contentWithSummary }, { "ClassWithInheritedSummary.xml", contentWithInheritedSummary }, { "ClassWithEmptySummary.xml", contentWithEmptySummary }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
private static Task VerifyCSharpDiagnosticAsync(string source, string testSettings, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> </ClassName> "; string contentWithInheritdoc = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <inheritdoc/> </ClassName> "; string contentWithSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <summary> Foo </summary> </ClassName> "; string contentWithContent = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <content> Foo </content> </ClassName> "; var test = new StyleCopDiagnosticVerifier <SA1605PartialElementDocumentationMustHaveSummary> .CSharpTest { TestCode = source, Settings = testSettings, XmlReferences = { { "ClassWithoutSummary.xml", contentWithoutSummary }, { "ClassWithInheritdoc.xml", contentWithInheritdoc }, { "ClassWithSummary.xml", contentWithSummary }, { "ClassWithContent.xml", contentWithContent }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
public async Task VerifyUsingReorderingWithoutMovingWithMultiLineCommentAsync() { var testCode = @"/* * Copyright by FooCorp Inc. */ using System; using Microsoft.CodeAnalysis; namespace Foo { public class Bar { } } "; var fixedTestCode = @"/* * Copyright by FooCorp Inc. */ using Microsoft.CodeAnalysis; using System; namespace Foo { public class Bar { } } "; this.usingDirectivesPlacement = UsingDirectivesPlacement.OutsideNamespace; var expected = StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(5, 1); await this.VerifyCSharpFixAsync(testCode, new[] { expected }, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
public async Task VerifyUsingReorderingWithoutMovingWithMultiLineFileHeaderAsync() { var testCode = @"// <copyright file=""Test0.cs"" company=""FooCorp""> // Copyright (c) FooCorp. All rights reserved. // </copyright> using Microsoft.CodeAnalysis; using System; namespace Foo { public class Bar { } } "; var fixedTestCode = @"// <copyright file=""Test0.cs"" company=""FooCorp""> // Copyright (c) FooCorp. All rights reserved. // </copyright> using System; using Microsoft.CodeAnalysis; namespace Foo { public class Bar { } } "; this.usingDirectivesPlacement = UsingDirectivesPlacement.OutsideNamespace; var expected = StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(6, 1).WithArguments("System", "Microsoft.CodeAnalysis"); await this.VerifyCSharpFixAsync(testCode, new[] { expected }, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
public async Task VerifyUsingReorderingWithFileHeaderAsync() { var testCode = @"// This is a file header. using Microsoft.CodeAnalysis; using System; namespace Foo { public class Bar { } } "; var fixedTestCode = @"// This is a file header. namespace Foo { using System; using Microsoft.CodeAnalysis; public class Bar { } } "; DiagnosticResult[] expected = { Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(3, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(4, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(4, 1).WithArguments("System","Microsoft.CodeAnalysis"), }; await this.VerifyCSharpFixAsync(testCode, expected, fixedTestCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false); }
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> </Method> </ClassName> "; string contentWithParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> <param name=""foo"">Param 1</param> <param name=""bar"">Param 2</param> </Method> </ClassName> "; string contentWithInvalidParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> <param>Test</param> <param/> <param name="""">Test</param> <param name="" "">Test</param> </Method> </ClassName> "; string contentWithInheritedDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <inheritdoc /> <param>Test</param> <param/> <param name="""">Test</param> <param name="" "">Test</param> </Method> </ClassName> "; var test = new StyleCopDiagnosticVerifier <SA1613ElementParameterDocumentationMustDeclareParameterName> .CSharpTest { TestCode = source, XmlReferences = { { "MissingParamDocumentation.xml", contentWithoutParamDocumentation }, { "WithParamDocumentation.xml", contentWithParamDocumentation }, { "WithInvalidParamDocumentation.xml", contentWithInvalidParamDocumentation }, { "WithInheritedDocumentation.xml", contentWithInheritedDocumentation }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
public async Task VerifyRegressionFor2026Async() { var testCode = @"// Copyright (c) 2015 ACME, Inc. All rights reserved worldwide. #if !VS2012 using System; using System.Runtime.InteropServices; using System.ComponentModel; #if VS2008 using System.Collections.ObjectModel; #elif VS2010 using System.Collections.Concurrent; #endif using Math = System.Math; using Queue = System.Collections.Queue; namespace Microsoft.VisualStudio.Shell { #pragma warning disable SA1200 // Using directives should be placed correctly // This is required to work around accessibility issues in documentation comments. using NativeMethods = System; #pragma warning restore SA1200 // Using directives should be placed correctly } #endif "; var fixedTestCode = @"// Copyright (c) 2015 ACME, Inc. All rights reserved worldwide. #if !VS2012 using System; using System.ComponentModel; using System.Runtime.InteropServices; #if VS2008 using System.Collections.ObjectModel; #elif VS2010 using System.Collections.Concurrent; #endif using Math = System.Math; using Queue = System.Collections.Queue; namespace Microsoft.VisualStudio.Shell { #pragma warning disable SA1200 // Using directives should be placed correctly // This is required to work around accessibility issues in documentation comments. using NativeMethods = System; #pragma warning restore SA1200 // Using directives should be placed correctly } #endif "; var expected = StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(6, 1); await this.VerifyCSharpFixAsync(testCode, new[] { expected }, fixedTestCode, CancellationToken.None).ConfigureAwait(false); }
private static Task VerifyCSharpDiagnosticAsync(string source, DiagnosticResult[] expected, CancellationToken cancellationToken) { string contentWithoutDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> </Method> </ClassName> "; string contentWithoutParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> </Method> </ClassName> "; string contentWithParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> <param name=""foo"">Test</param> <param name=""bar"">Test</param> </Method> </ClassName> "; string contentWithEmptyParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> <param name=""foo""></param> <param name=""bar""> </param> </Method> </ClassName> "; string contentWithEmptyParamDocumentation2 = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <ClassName> <Method> <summary> Foo </summary> <param name=""foo""/> <param name=""bar""> <para> </para> </param> </Method> </ClassName> "; var test = new StyleCopDiagnosticVerifier <SA1614ElementParameterDocumentationMustHaveText> .CSharpTest { TestCode = source, XmlReferences = { { "NoDocumentation.xml", contentWithoutDocumentation }, { "NoParamDocumentation.xml", contentWithoutParamDocumentation }, { "ParamDocumentation.xml", contentWithParamDocumentation }, { "EmptyParamDocumentation.xml", contentWithEmptyParamDocumentation }, { "EmptyParamDocumentation2.xml", contentWithEmptyParamDocumentation2 }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test.RunAsync(cancellationToken)); }
private static StyleCopDiagnosticVerifier <SA1625ElementDocumentationMustNotBeCopiedAndPasted> .CSharpTest CreateTest(DiagnosticResult[] expected) { string correctDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary> Some documentation. </summary> <remark>Some remark.</remark> </Test> </TestClass> "; string correctWithEmptyReferenceElements = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary> Some documentation <see cref=""TestClass""/>. </summary> <summary> Some documentation <see cref=""TestClass2""/>. </summary> <remark>Some remark.</remark> </Test> </TestClass> "; string correctWithEmptyElements = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary></summary> <remark></remark> </Test> </TestClass> "; string inherited = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <inheritdoc /> </Test> </TestClass> "; string badWithNormalization = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary> Some documentation <see cref=""TestClass""/>. </summary> <summary> Some documentation <see cref = ""TestClass"" />. </summary> <remark>Some remark.</remark> </Test> </TestClass> "; string badWithDuplicates = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary>Some documentation.</summary> <remark>Some documentation.</remark> </Test> </TestClass> "; string badWithDuplicates2 = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary> Some documentation. </summary> <remark> Some documentation. </remark> </Test> </TestClass> "; string withIgnoredParameters = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <TestClass> <Test> <summary>The parameter is not used.</summary> <remark>The parameter is not used.</remark> </Test> </TestClass> "; var test = new StyleCopDiagnosticVerifier <SA1625ElementDocumentationMustNotBeCopiedAndPasted> .CSharpTest { XmlReferences = { { "Correct.xml", correctDocumentation }, { "CorrectWithEmptyElements.xml", correctWithEmptyReferenceElements }, { "CorrectEmpty.xml", correctWithEmptyElements }, { "Inherited.xml", inherited }, { "BadWithNormalization.xml", badWithNormalization }, { "BadWithDuplicates.xml", badWithDuplicates }, { "BadWithDuplicates2.xml", badWithDuplicates2 }, { "WithIgnoredParameters.xml", withIgnoredParameters }, }, }; test.ExpectedDiagnostics.AddRange(expected); return(test); }
public async Task VerifyCodefixForDirectiveTriviaOutsideOfNamespacesAsync() { var testCode = @"// <copyright file=""Program.cs"" company=""PlaceholderCompany"" > // Copyright (c) PlaceholderCompany. All rights reserved. // </copyright> #if DEBUG using Fish; #else using Fish.Face; #endif using System.Text; using System; namespace StyleCopBugRepro { class Program { static void Main(string[] args) { Int32 q; Haddock h; StringBuilder sb; } } } namespace Fish { public class Haddock { } namespace Face { public class Haddock { } } } "; var fixedTestCode = @"// <copyright file=""Program.cs"" company=""PlaceholderCompany"" > // Copyright (c) PlaceholderCompany. All rights reserved. // </copyright> #if DEBUG using Fish; #else using Fish.Face; #endif using System; using System.Text; namespace StyleCopBugRepro { class Program { static void Main(string[] args) { Int32 q; Haddock h; StringBuilder sb; } } } namespace Fish { public class Haddock { } namespace Face { public class Haddock { } } } "; DiagnosticResult[] expected = { Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(8, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(10, 1), StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(10, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(11, 1), }; DiagnosticResult[] fixedExpected = { Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(8, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(10, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(11, 1), }; await this.VerifyCSharpFixAsync(testCode, expected, fixedTestCode, fixedExpected, cancellationToken : CancellationToken.None).ConfigureAwait(false); }
protected static DiagnosticResult Diagnostic() => StyleCopDiagnosticVerifier <SA1402FileMayOnlyContainASingleType> .Diagnostic();
public async Task VerifyUsingReorderingWithMultipleNamespacesAsync() { var testCode = @"using Microsoft.CodeAnalysis; using SystemAction = System.Action; using static System.Math; using System; using static System.String; using MyFunc = System.Func<int,bool>; using System.Collections.Generic; using System.Collections; namespace TestNamespace1 { public class TestClass1 { } } namespace TestNamespace2 { } "; var fixedTestCode = @"using System; using System.Collections; using System.Collections.Generic; using Microsoft.CodeAnalysis; using static System.Math; using static System.String; using MyFunc = System.Func<int,bool>; using SystemAction = System.Action; namespace TestNamespace1 { public class TestClass1 { } } namespace TestNamespace2 { } "; DiagnosticResult[] expected = { Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(1, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(2, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(3, 1), StyleCopDiagnosticVerifier <SA1216UsingStaticDirectivesMustBePlacedAtTheCorrectLocation> .Diagnostic().WithLocation(3, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(4, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(4, 1).WithArguments("System","System.Math"), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(6, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(7, 1), StyleCopDiagnosticVerifier <SA1209UsingAliasDirectivesMustBePlacedAfterOtherUsingDirectives> .Diagnostic().WithLocation(7, 1), StyleCopDiagnosticVerifier <SA1211UsingAliasDirectivesMustBeOrderedAlphabeticallyByAliasName> .Diagnostic().WithLocation(7, 1).WithArguments("MyFunc","SystemAction"), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(9, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(9, 1).WithArguments("System.Collections.Generic","System.Math"), StyleCopDiagnosticVerifier <SA1210UsingDirectivesMustBeOrderedAlphabeticallyByNamespace> .Diagnostic().WithLocation(9, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(10, 1), StyleCopDiagnosticVerifier <SA1208SystemUsingDirectivesMustBePlacedBeforeOtherUsingDirectives> .Diagnostic().WithLocation(10, 1).WithArguments("System.Collections","System.Math"), }; // The code fix is not able to correct all violations due to the use of multiple namespaces in a single file DiagnosticResult[] remainingDiagnostics = { Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(1, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(2, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(3, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(4, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(5, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(6, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(7, 1), Diagnostic(SA1200UsingDirectivesMustBePlacedCorrectly.DescriptorInside).WithLocation(8, 1), }; await this.VerifyCSharpFixAsync(testCode, expected, fixedTestCode, remainingDiagnostics, cancellationToken : CancellationToken.None).ConfigureAwait(false); }