From af240fdd8539aeb1f5bac197086bc8fb4681021a Mon Sep 17 00:00:00 2001 From: Brad Wilson Date: Sun, 1 Dec 2024 13:22:30 -0800 Subject: [PATCH] Normalize inline source with tabs instead of spaces --- ...DataAttributeMustPointAtValidClassTests.cs | 108 ++-- ...actAttributeSubclassShouldBePublicTests.cs | 80 +-- ...DataAttributeShouldBeUsedOnATheoryTests.cs | 20 +- .../DoNotUseAsyncVoidForTestMethodsTests.cs | 34 +- .../DoNotUseBlockingTaskOperationsTests.cs | 510 +++++++-------- .../X1000/DoNotUseConfigureAwaitTests.cs | 184 +++--- .../X1000/EnsureFixturesHaveASourceTests.cs | 80 +-- .../FactMethodMustNotHaveParametersTests.cs | 12 +- .../FactMethodShouldNotHaveTestDataTests.cs | 22 +- ...nlineDataMustMatchTheoryParametersTests.cs | 505 +++++++-------- ...lineDataShouldBeUniqueWithinTheoryTests.cs | 230 +++---- ...ocalFunctionsCannotBeTestFunctionsTests.cs | 16 +- ...mberDataShouldReferenceValidMemberTests.cs | 458 +++++++------- .../PublicMethodShouldBeMarkedAsTestTests.cs | 144 ++--- ...tClassCannotBeNestedInGenericClassTests.cs | 32 +- .../X1000/TestClassMustBePublicTests.cs | 40 +- ...estClassShouldHaveTFixtureArgumentTests.cs | 16 +- .../TestMethodCannotHaveOverloadsTests.cs | 42 +- ...dMustNotHaveMultipleFactAttributesTests.cs | 16 +- .../TestMethodShouldNotBeSkippedTests.cs | 8 +- .../TestMethodSupportedReturnTypeTests.cs | 26 +- ...taRowArgumentsShouldBeSerializableTests.cs | 146 ++--- ...aTypeArgumentsShouldBeSerializableTests.cs | 116 ++-- ...ryMethodCannotHaveDefaultParameterTests.cs | 8 +- .../TheoryMethodCannotHaveParamsArrayTests.cs | 16 +- .../TheoryMethodMustHaveTestDataTests.cs | 14 +- .../TheoryMethodShouldHaveParametersTests.cs | 12 +- ...TheoryMethodShouldUseAllParametersTests.cs | 72 +-- .../X1000/UseCancellationTokenTests.cs | 78 +-- ...ctionContainsShouldNotUseBoolCheckTests.cs | 72 +-- ...mptyCollectionCheckShouldNotBeUsedTests.cs | 16 +- ...tyShouldNotBeUsedForContainsChecksTests.cs | 30 +- ...otBeUsedForCollectionContainsCheckTests.cs | 6 +- ...nericShouldNotBeUsedForStringValueTests.cs | 24 +- ...sertEqualLiteralValueShouldBeFirstTests.cs | 52 +- ...AssertEqualPrecisionShouldBeInRangeTest.cs | 6 +- ...ShouldNotBeUsedForBoolLiteralCheckTests.cs | 40 +- ...uldNotBeUsedForCollectionSizeCheckTests.cs | 92 +-- ...rtEqualShouldNotBeUsedForNullCheckTests.cs | 64 +- .../X2000/AssertEqualsShouldNotBeUsedTests.cs | 6 +- ...TypeShouldNotBeUsedForAbstractTypeTests.cs | 64 +- ...IsTypeShouldUseGenericOverloadTypeTests.cs | 48 +- ...tNullShouldNotBeCalledOnValueTypesTests.cs | 66 +- ...xMatchShouldNotUseBoolLiteralCheckTests.cs | 20 +- ...tSameShouldNotBeCalledOnValueTypesTests.cs | 66 +- ...ngleShouldBeUsedForSingleParameterTests.cs | 16 +- ...sertSingleShouldUseTwoArgumentCallTests.cs | 20 +- ...gEqualityCheckShouldNotUseBoolCheckTest.cs | 48 +- ...ubstringCheckShouldNotUseBoolCheckTests.cs | 108 ++-- ...ShouldNotBeUsedForAsyncThrowsCheckTests.cs | 130 ++-- ...hrowsShouldUseGenericOverloadCheckTests.cs | 54 +- ...bleFromAssertionIsConfusinglyNamedTests.cs | 16 +- .../X2000/AsyncAssertsShouldBeAwaitedTests.cs | 26 +- .../BooleanAssertsShouldNotBeNegatedTests.cs | 10 +- ...uldNotBeUsedForSimpleEqualityCheckTests.cs | 72 +-- ...UseAssertEmptyWithProblematicTypesTests.cs | 24 +- .../X2000/SetEqualityAnalyzerTests.cs | 193 +++--- ...seAssertFailInsteadOfBooleanAssertTests.cs | 18 +- ...oncreteTypeOfJsonSerializableTypesTests.cs | 2 +- ...ssMustHaveParameterlessConstructorTests.cs | 24 +- ...ttributeMustPointAtValidClassFixerTests.cs | 86 +-- .../Fixes/X1000/ConvertToFactFixTests.cs | 16 +- .../Fixes/X1000/ConvertToTheoryFixTests.cs | 20 +- ...ttributeShouldBeUsedOnATheoryFixerTests.cs | 16 +- ...NotUseAsyncVoidForTestMethodsFixerTests.cs | 64 +- .../X1000/DoNotUseConfigureAwaitFixerTests.cs | 288 ++++----- ...ctMethodMustNotHaveParametersFixerTests.cs | 8 +- ...ctMethodShouldNotHaveTestDataFixerTests.cs | 10 +- ...chTheoryParameters_ExtraValueFixerTests.cs | 36 +- ...eUsedForIncompatibleParameterFixerTests.cs | 24 +- ...TheoryParameters_TooFewValuesFixerTests.cs | 12 +- ...ataShouldBeUniqueWithinTheoryFixerTests.cs | 14 +- ...unctionsCannotBeTestFunctionsFixerTests.cs | 18 +- ...ferenceValidMember_ExtraValueFixerTests.cs | 48 +- ...ldReferenceValidMember_NameOfFixerTests.cs | 16 +- ...eUsedForIncompatibleParameterFixerTests.cs | 32 +- ...alidMember_ParamsForNonMethodFixerTests.cs | 16 +- ...ferenceValidMember_ReturnTypeFixerTests.cs | 32 +- ...ldReferenceValidMember_StaticFixerTests.cs | 16 +- ...ferenceValidMember_VisibilityFixerTests.cs | 16 +- ...licMethodShouldBeMarkedAsTestFixerTests.cs | 28 +- .../X1000/RemoveMethodParameterFixTests.cs | 24 +- ...sCannotBeNestedInGenericClassFixerTests.cs | 14 +- .../X1000/TestClassMustBePublicFixerTests.cs | 24 +- ...assShouldHaveTFixtureArgumentFixerTests.cs | 36 +- ...NotHaveMultipleFactAttributesFixerTests.cs | 10 +- .../TestMethodShouldNotBeSkippedFixerTests.cs | 8 +- ...hodCannotHaveDefaultParameterFixerTests.cs | 12 +- .../X1000/UseCancellationTokenFixerTests.cs | 160 ++--- ...ContainsShouldNotUseBoolCheckFixerTests.cs | 10 +- ...ollectionCheckShouldNotBeUsedFixerTests.cs | 30 +- ...uldNotBeUsedForContainsChecksFixerTests.cs | 10 +- ...sedForCollectionContainsCheckFixerTests.cs | 10 +- ...ShouldNotBeUsedForStringValueFixerTests.cs | 10 +- ...qualLiteralValueShouldBeFirstFixerTests.cs | 10 +- ...EqualPrecisionShouldBeInRangeFixerTests.cs | 8 +- ...dNotBeUsedForBoolLiteralCheckFixerTests.cs | 10 +- ...tBeUsedForCollectionSizeCheckFixerTests.cs | 10 +- ...alShouldNotBeUsedForNullCheckFixerTests.cs | 10 +- .../AssertEqualsShouldNotBeUsedFixerTests.cs | 10 +- ...houldNotBeUsedForAbstractTypeFixerTests.cs | 96 +-- ...ShouldNotBeCalledOnValueTypesFixerTests.cs | 56 +- ...hShouldNotUseBoolLiteralCheckFixerTests.cs | 10 +- ...ShouldNotBeCalledOnValueTypesFixerTests.cs | 10 +- ...houldBeUsedForSingleParameterFixerTests.cs | 144 ++--- ...ingleShouldUseTwoArgumentCallFixerTests.cs | 10 +- ...ityCheckShouldNotUseBoolCheckFixerTests.cs | 10 +- ...ingCheckShouldNotUseBoolCheckFixerTests.cs | 10 +- ...dNotBeUsedForAsyncThrowsCheckFixerTests.cs | 596 +++++++++--------- ...omAssertionIsConfusinglyNamedFixerTests.cs | 24 +- .../AsyncAssertsShouldBeAwaitedFixerTests.cs | 18 +- ...leanAssertsShouldNotBeNegatedFixerTests.cs | 10 +- ...ForSimpleEqualityCheckBooleanFixerTests.cs | 10 +- ...SimpleEqualityCheckNonBooleanFixerTests.cs | 10 +- ...ertFailInsteadOfBooleanAssertFixerTests.cs | 8 +- .../Fixes/X2000/UseGenericOverloadFixTests.cs | 60 +- ...tHaveParameterlessConstructorFixerTests.cs | 206 +++--- ...derCallingConfigureAwaitSuppressorTests.cs | 34 +- .../MakeTypesInternalSuppressorTests.cs | 6 +- ...yncSuffixForAsyncMethodsSuppressorTests.cs | 6 +- .../Utility/CSharpVerifier.cs | 12 + 121 files changed, 3535 insertions(+), 3521 deletions(-) diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/ClassDataAttributeMustPointAtValidClassTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/ClassDataAttributeMustPointAtValidClassTests.cs index 3e92eb8d..d57edd3c 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/ClassDataAttributeMustPointAtValidClassTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/ClassDataAttributeMustPointAtValidClassTests.cs @@ -11,9 +11,9 @@ static string TestMethodSource(string testMethodParams = "(int n)") => string.Fo using Xunit; public class TestClass {{ - [Theory] - [ClassData(typeof(DataClass))] - public void TestMethod{0} {{ }} + [Theory] + [ClassData(typeof(DataClass))] + public void TestMethod{0} {{ }} }} """, testMethodParams); @@ -27,8 +27,8 @@ public async Task SuccessCaseV2() using System.Collections.Generic; class DataClass: IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """; @@ -46,8 +46,8 @@ class DataClass: IEnumerable { using Xunit; class DataClass: IEnumerable> { - public IEnumerator> GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator> GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """ }, @@ -60,7 +60,7 @@ class DataClass: IEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -73,7 +73,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -86,7 +86,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -99,7 +99,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -112,7 +112,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -125,7 +125,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -138,7 +138,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -151,7 +151,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -164,7 +164,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -178,7 +178,7 @@ public class DataClass : IAsyncEnumerable> { using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """ }, @@ -217,8 +217,8 @@ class DataClass: IEnumerable { using System.Collections.Generic; abstract class DataClass: IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, @@ -229,9 +229,9 @@ abstract class DataClass: IEnumerable { using System.Collections.Generic; class DataClass: IEnumerable { - public DataClass(string parameter) { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public DataClass(string parameter) { } + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, @@ -242,9 +242,9 @@ public DataClass(string parameter) { } using System.Collections.Generic; class DataClass: IEnumerable { - internal DataClass() { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + internal DataClass() { } + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, @@ -255,9 +255,9 @@ internal DataClass() { } using System.Collections.Generic; class DataClass: IEnumerable { - private DataClass() { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + private DataClass() { } + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, ]; @@ -266,8 +266,8 @@ private DataClass() { } [MemberData(nameof(FailureCasesData))] public async Task FailureCases(string dataClassSource) { - var expectedV2 = Verify.Diagnostic("xUnit1007").WithSpan(7, 6, 7, 34).WithArguments("DataClass", "IEnumerable"); - var expectedV3 = Verify.Diagnostic("xUnit1007").WithSpan(7, 6, 7, 34).WithArguments("DataClass", "IEnumerable, IAsyncEnumerable, IEnumerable, or IAsyncEnumerable"); + var expectedV2 = Verify.Diagnostic("xUnit1007").WithSpan(7, 3, 7, 31).WithArguments("DataClass", "IEnumerable"); + var expectedV3 = Verify.Diagnostic("xUnit1007").WithSpan(7, 3, 7, 31).WithArguments("DataClass", "IEnumerable, IAsyncEnumerable, IEnumerable, or IAsyncEnumerable"); await Verify.VerifyAnalyzerV2(LanguageVersion.CSharp9, [TestMethodSource(), dataClassSource], expectedV2); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource(), dataClassSource], expectedV3); @@ -281,10 +281,10 @@ public async Task IAsyncEnumerableNotSupportedInV2() using System.Threading; public class DataClass : IAsyncEnumerable { - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1007").WithSpan(7, 6, 7, 34).WithArguments("DataClass", "IEnumerable"); + var expected = Verify.Diagnostic("xUnit1007").WithSpan(7, 3, 7, 31).WithArguments("DataClass", "IEnumerable"); await Verify.VerifyAnalyzerV2(LanguageVersion.CSharp9, [TestMethodSource(), dataClassSource], expected); } @@ -301,10 +301,10 @@ public async Task NotEnoughTypeParameters_Triggers() using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1037").WithSpan(7, 6, 7, 34).WithArguments("Xunit.TheoryDataRow"); + var expected = Verify.Diagnostic("xUnit1037").WithSpan(7, 3, 7, 31).WithArguments("Xunit.TheoryDataRow"); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource("(int n, string f)"), dataClassSource], expected); } @@ -321,10 +321,10 @@ public async Task TooManyTypeParameters_Triggers() using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1038").WithSpan(7, 6, 7, 34).WithArguments("Xunit.TheoryDataRow"); + var expected = Verify.Diagnostic("xUnit1038").WithSpan(7, 3, 7, 31).WithArguments("Xunit.TheoryDataRow"); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource("(int n)"), dataClassSource], expected); } @@ -338,10 +338,10 @@ public async Task ExtraDataPastParamsArray_Triggers() using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1038").WithSpan(7, 6, 7, 34).WithArguments("Xunit.TheoryDataRow"); + var expected = Verify.Diagnostic("xUnit1038").WithSpan(7, 3, 7, 31).WithArguments("Xunit.TheoryDataRow"); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource("(int n, params double[] d)"), dataClassSource], expected); } @@ -358,10 +358,10 @@ public async Task WithIncompatibleType_Triggers() using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1039").WithSpan(8, 35, 8, 41).WithArguments("string", "DataClass", "d"); + var expected = Verify.Diagnostic("xUnit1039").WithSpan(8, 32, 8, 38).WithArguments("string", "DataClass", "d"); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource("(int n, double d)"), dataClassSource], expected); } @@ -375,10 +375,10 @@ public async Task WithExtraValueNotCompatibleWithParamsArray_Triggers() using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1039").WithSpan(8, 42, 8, 50).WithArguments("int", "DataClass", "s"); + var expected = Verify.Diagnostic("xUnit1039").WithSpan(8, 39, 8, 47).WithArguments("int", "DataClass", "s"); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource("(int n, params string[] s)"), dataClassSource], expected); } @@ -395,10 +395,10 @@ public async Task ValidTheoryDataRowMemberWithMismatchedNullability_Triggers() using Xunit; public class DataClass : IAsyncEnumerable> { - public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator> GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """; - var expected = Verify.Diagnostic("xUnit1040").WithSpan(8, 28, 8, 34).WithArguments("string?", "DataClass", "s"); + var expected = Verify.Diagnostic("xUnit1040").WithSpan(8, 25, 8, 31).WithArguments("string?", "DataClass", "s"); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource("(string s)"), dataClassSource], expected); } @@ -415,8 +415,8 @@ public class X1050_ClassDataTheoryDataRowIsRecommendedForStronglyTypedAnalysis using Xunit; public class DataClass : IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, @@ -428,7 +428,7 @@ public class DataClass : IEnumerable { using Xunit; public class DataClass : IAsyncEnumerable { - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """, @@ -440,8 +440,8 @@ public class DataClass : IAsyncEnumerable { using Xunit; public class DataClass : IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, @@ -453,7 +453,7 @@ public class DataClass : IEnumerable { using Xunit; public class DataClass : IAsyncEnumerable { - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """, @@ -465,8 +465,8 @@ public class DataClass : IAsyncEnumerable { using Xunit; public class DataClass : IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } """, @@ -478,7 +478,7 @@ public class DataClass : IEnumerable { using Xunit; public class DataClass : IAsyncEnumerable { - public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; + public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) => null; } """, ]; @@ -487,7 +487,7 @@ public class DataClass : IAsyncEnumerable { [MemberData(nameof(FailureCasesData))] public async Task FailureCases(string dataClassSource) { - var expected = Verify.Diagnostic("xUnit1050").WithSpan(7, 6, 7, 34); + var expected = Verify.Diagnostic("xUnit1050").WithSpan(7, 3, 7, 31); await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [TestMethodSource(), dataClassSource], expected); } diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/ConstructorsOnFactAttributeSubclassShouldBePublicTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/ConstructorsOnFactAttributeSubclassShouldBePublicTests.cs index 76a67055..3d7aaf8b 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/ConstructorsOnFactAttributeSubclassShouldBePublicTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/ConstructorsOnFactAttributeSubclassShouldBePublicTests.cs @@ -15,11 +15,11 @@ public async Task DefaultConstructor_DoesNotTrigger() internal sealed class CustomFactAttribute : FactAttribute { } public class Tests { - [CustomFact] - public void TestCustomFact() { } + [CustomFact] + public void TestCustomFact() { } - [Fact] - public void TestFact() { } + [Fact] + public void TestFact() { } } """; @@ -35,17 +35,17 @@ public async Task ParameterlessPublicConstructor_DoesNotTrigger() [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] internal sealed class CustomFactAttribute : FactAttribute { - public CustomFactAttribute() { - this.Skip = "xxx"; - } + public CustomFactAttribute() { + this.Skip = "xxx"; + } } public class Tests { - [CustomFact] - public void TestCustomFact() { } + [CustomFact] + public void TestCustomFact() { } - [Fact] - public void TestFact() { } + [Fact] + public void TestFact() { } } """; @@ -61,17 +61,17 @@ public async Task PublicConstructorWithParameters_DoesNotTrigger() [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] internal sealed class CustomFactAttribute : FactAttribute { - public CustomFactAttribute(string skip) { - this.Skip = skip; - } + public CustomFactAttribute(string skip) { + this.Skip = skip; + } } public class Tests { - [CustomFact("blah")] - public void TestCustomFact() { } + [CustomFact("blah")] + public void TestCustomFact() { } - [Fact] - public void TestFact() { } + [Fact] + public void TestFact() { } } """; @@ -87,21 +87,21 @@ public async Task PublicConstructorWithOtherConstructors_DoesNotTrigger() [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] internal sealed class CustomFactAttribute : FactAttribute { - public CustomFactAttribute() { - this.Skip = "xxx"; - } + public CustomFactAttribute() { + this.Skip = "xxx"; + } - internal CustomFactAttribute(string skip) { - this.Skip = skip; - } + internal CustomFactAttribute(string skip) { + this.Skip = skip; + } } public class Tests { - [CustomFact] - public void TestCustomFact() { } + [CustomFact] + public void TestCustomFact() { } - [Fact] - public void TestFact() { } + [Fact] + public void TestFact() { } } """; @@ -117,15 +117,15 @@ public async Task InternalConstructor_Triggers() [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] internal sealed class CustomFactAttribute : FactAttribute { - internal CustomFactAttribute(string skip, params int[] values) { } + internal CustomFactAttribute(string skip, params int[] values) { } } public class Tests { - [{|#0:CustomFact("Skip", 42)|}] - public void TestCustomFact() { } + [{|#0:CustomFact("Skip", 42)|}] + public void TestCustomFact() { } - [Fact] - public void TestFact() { } + [Fact] + public void TestFact() { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("CustomFactAttribute.CustomFactAttribute(string, params int[])"); @@ -142,17 +142,17 @@ public async Task ProtectedInternalConstructor_Triggers() [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] internal sealed class CustomFactAttribute : FactAttribute { - protected internal CustomFactAttribute() { - this.Skip = "xxx"; - } + protected internal CustomFactAttribute() { + this.Skip = "xxx"; + } } public class Tests { - [{|#0:CustomFact|}] - public void TestCustomFact() { } + [{|#0:CustomFact|}] + public void TestCustomFact() { } - [Fact] - public void TestFact() { } + [Fact] + public void TestFact() { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("CustomFactAttribute.CustomFactAttribute()"); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/DataAttributeShouldBeUsedOnATheoryTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/DataAttributeShouldBeUsedOnATheoryTests.cs index c314db68..b1964499 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/DataAttributeShouldBeUsedOnATheoryTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/DataAttributeShouldBeUsedOnATheoryTests.cs @@ -9,8 +9,8 @@ public async Task FactMethodWithNoDataAttributes_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -25,9 +25,9 @@ public async Task FactMethodWithDataAttributes_DoesNotTrigger(string dataAttribu { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Fact] - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.Fact] + [Xunit.{0}] + public void TestMethod() {{ }} }} """, dataAttribute); @@ -42,9 +42,9 @@ public async Task TheoryMethodWithDataAttributes_DoesNotTrigger(string dataAttri { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.Theory] + [Xunit.{0}] + public void TestMethod() {{ }} }} """, dataAttribute); @@ -59,8 +59,8 @@ public async Task MethodsWithDataAttributesButNotFactOrTheory_Triggers(string da { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.{0}] - public void [|TestMethod|]() {{ }} + [Xunit.{0}] + public void [|TestMethod|]() {{ }} }} """, dataAttribute); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseAsyncVoidForTestMethodsTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseAsyncVoidForTestMethodsTests.cs index a325a6f6..6aee7a18 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseAsyncVoidForTestMethodsTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseAsyncVoidForTestMethodsTests.cs @@ -11,9 +11,9 @@ public async Task NonTestMethod_DoesNotTrigger() using System.Threading.Tasks; public class MyClass { - public async void MyMethod() { - await Task.Yield(); - } + public async void MyMethod() { + await Task.Yield(); + } } """; @@ -27,8 +27,8 @@ public async Task NonAsyncTestMethod_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; @@ -43,10 +43,10 @@ public async Task AsyncTaskMethod_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - await Task.Yield(); - } + [Fact] + public async Task TestMethod() { + await Task.Yield(); + } } """; @@ -61,10 +61,10 @@ public async Task AsyncValueTaskMethod_V3_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async ValueTask TestMethod() { - await Task.Yield(); - } + [Fact] + public async ValueTask TestMethod() { + await Task.Yield(); + } } """; @@ -79,10 +79,10 @@ public async Task AsyncVoidMethod_Triggers() using Xunit; public class TestClass { - [Fact] - public async void {|#0:TestMethod|}() { - await Task.Yield(); - } + [Fact] + public async void {|#0:TestMethod|}() { + await Task.Yield(); + } } """; var expectedV2 = Verify.Diagnostic("xUnit1048").WithLocation(0); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseBlockingTaskOperationsTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseBlockingTaskOperationsTests.cs index 276128a6..890a7226 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseBlockingTaskOperationsTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseBlockingTaskOperationsTests.cs @@ -13,10 +13,10 @@ public async Task SuccessCase() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - await Task.Delay(1); - } + [Fact] + public async Task TestMethod() { + await Task.Delay(1); + } } """; @@ -34,14 +34,14 @@ public async Task GetResult_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - default(IValueTaskSource).[|GetResult(0)|]; - Action _ = vts => vts.GetResult(0); - void LocalFunction() { - default(IValueTaskSource).GetResult(0); - } - } + [Fact] + public void TestMethod() { + default(IValueTaskSource).[|GetResult(0)|]; + Action _ = vts => vts.GetResult(0); + void LocalFunction() { + default(IValueTaskSource).GetResult(0); + } + } } """; @@ -60,14 +60,14 @@ public async Task GetResult_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - default(IValueTaskSource).[|GetResult(0)|]; - Func, int> _ = vts => vts.GetResult(0); - void LocalFunction() { - default(IValueTaskSource).GetResult(0); - } - } + [Fact] + public void TestMethod() { + default(IValueTaskSource).[|GetResult(0)|]; + Func, int> _ = vts => vts.GetResult(0); + void LocalFunction() { + default(IValueTaskSource).GetResult(0); + } + } } """; @@ -88,14 +88,14 @@ public async Task Wait_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Task.Delay(1).[|Wait()|]; - Action _ = t => t.Wait(); - void LocalFunction() { - Task.Delay(1).Wait(); - } - } + [Fact] + public void TestMethod() { + Task.Delay(1).[|Wait()|]; + Action _ = t => t.Wait(); + void LocalFunction() { + Task.Delay(1).Wait(); + } + } } """; @@ -110,14 +110,14 @@ public async Task Wait_BeforeWhenAll_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task = Task.Delay(1); + [Fact] + public async Task TestMethod() { + var task = Task.Delay(1); - task.[|Wait()|]; + task.[|Wait()|]; - await Task.WhenAll(task); - } + await Task.WhenAll(task); + } } """; @@ -132,16 +132,16 @@ public async Task Wait_ForUnawaitedTask_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() { + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - await Task.WhenAll(new[] { task1 }); + await Task.WhenAll(new[] { task1 }); - task1.Wait(); - task2.[|Wait()|]; - } + task1.Wait(); + task2.[|Wait()|]; + } } """; @@ -156,10 +156,10 @@ public async Task Wait_InLambda_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Task.CompletedTask.ContinueWith(x => x.Wait()); - } + [Fact] + public void TestMethod() { + Task.CompletedTask.ContinueWith(x => x.Wait()); + } } """; @@ -174,16 +174,16 @@ public async Task Wait_AfterWhenAll_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() { + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - await Task.WhenAll(task1, task2); + await Task.WhenAll(task1, task2); - task1.Wait(); - task2.Wait(); - } + task1.Wait(); + task2.Wait(); + } } """; @@ -198,15 +198,15 @@ public async Task Wait_AfterWhenAny_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() { + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - var finishedTask = await Task.WhenAny(task1, task2); + var finishedTask = await Task.WhenAny(task1, task2); - finishedTask.Wait(); - } + finishedTask.Wait(); + } } """; @@ -227,14 +227,14 @@ public async Task WaitMethod_Triggers(string waitMethod) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - Task.[|{0}(Task.Delay(1))|]; - Action _ = t => Task.{0}(t); - void LocalFunction() {{ - Task.{0}(Task.Delay(1)); - }} - }} + [Fact] + public void TestMethod() {{ + Task.[|{0}(Task.Delay(1))|]; + Action _ = t => Task.{0}(t); + void LocalFunction() {{ + Task.{0}(Task.Delay(1)); + }} + }} }} """, waitMethod); @@ -251,14 +251,14 @@ public async Task WaitMethod_BeforeWhenAll_Triggers(string waitMethod) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var task = Task.Delay(1); + [Fact] + public async Task TestMethod() {{ + var task = Task.Delay(1); - Task.[|{0}(task)|]; + Task.[|{0}(task)|]; - await Task.WhenAll(task); - }} + await Task.WhenAll(task); + }} }} """, waitMethod); @@ -275,17 +275,17 @@ public async Task WaitMethod_ForUnawaitedTask_Triggers(string waitMethod) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() {{ + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - await Task.WhenAll(new[] {{ task1 }}); + await Task.WhenAll(new[] {{ task1 }}); - Task.{0}(task1); - Task.[|{0}(task2)|]; - Task.[|{0}(task1, task2)|]; - }} + Task.{0}(task1); + Task.[|{0}(task2)|]; + Task.[|{0}(task1, task2)|]; + }} }} """, waitMethod); @@ -302,10 +302,10 @@ public async Task WaitMethod_InLambda_DoesNotTrigger(string waitMethod) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - Task.CompletedTask.ContinueWith(x => Task.{0}(x)); - }} + [Fact] + public void TestMethod() {{ + Task.CompletedTask.ContinueWith(x => Task.{0}(x)); + }} }} """, waitMethod); @@ -322,17 +322,17 @@ public async Task WaitMethod_AfterWhenAll_DoesNotTrigger(string waitMethod) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() {{ + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - await Task.WhenAll(task1, task2); + await Task.WhenAll(task1, task2); - Task.{0}(task1); - Task.{0}(task2); - Task.{0}(task1, task2); - }} + Task.{0}(task1); + Task.{0}(task2); + Task.{0}(task1, task2); + }} }} """, waitMethod); @@ -349,15 +349,15 @@ public async Task WaitMethod_AfterWhenAny_DoesNotTrigger(string waitMethod) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() {{ + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - var finishedTask = await Task.WhenAny(task1, task2); + var finishedTask = await Task.WhenAny(task1, task2); - Task.{0}(finishedTask); - }} + Task.{0}(finishedTask); + }} }} """, waitMethod); @@ -376,14 +376,14 @@ public async Task GetResult_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Task.CompletedTask.GetAwaiter().[|GetResult()|]; - Action _ = t => t.GetAwaiter().GetResult(); - void LocalFunction() { - Task.CompletedTask.GetAwaiter().GetResult(); - } - } + [Fact] + public void TestMethod() { + Task.CompletedTask.GetAwaiter().[|GetResult()|]; + Action _ = t => t.GetAwaiter().GetResult(); + void LocalFunction() { + Task.CompletedTask.GetAwaiter().GetResult(); + } + } } """; @@ -398,14 +398,14 @@ public async Task GetResult_BeforeWhenAll_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task = Task.Delay(1); + [Fact] + public async Task TestMethod() { + var task = Task.Delay(1); - task.GetAwaiter().[|GetResult()|]; + task.GetAwaiter().[|GetResult()|]; - await Task.WhenAll(task); - } + await Task.WhenAll(task); + } } """; @@ -420,16 +420,16 @@ public async Task GetResult_OnUnawaitedTask_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() { + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - await Task.WhenAll(new[] { task1 }); + await Task.WhenAll(new[] { task1 }); - task1.GetAwaiter().GetResult(); - task2.GetAwaiter().[|GetResult()|]; - } + task1.GetAwaiter().GetResult(); + task2.GetAwaiter().[|GetResult()|]; + } } """; @@ -444,10 +444,10 @@ public async Task GetResult_InLambda_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Task.CompletedTask.ContinueWith(x => x.GetAwaiter().GetResult()); - } + [Fact] + public void TestMethod() { + Task.CompletedTask.ContinueWith(x => x.GetAwaiter().GetResult()); + } } """; @@ -462,16 +462,16 @@ public async Task GetResult_AfterWhenAll_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() { + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - await Task.WhenAll(task1, task2); + await Task.WhenAll(task1, task2); - task1.GetAwaiter().GetResult(); - task2.GetAwaiter().GetResult(); - } + task1.GetAwaiter().GetResult(); + task2.GetAwaiter().GetResult(); + } } """; @@ -486,15 +486,15 @@ public async Task GetResult_AfterWhenAny_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.Delay(1); - var task2 = Task.Delay(2); + [Fact] + public async Task TestMethod() { + var task1 = Task.Delay(1); + var task2 = Task.Delay(2); - var finishedTask = await Task.WhenAny(task1, task2); + var finishedTask = await Task.WhenAny(task1, task2); - finishedTask.GetAwaiter().GetResult(); - } + finishedTask.GetAwaiter().GetResult(); + } } """; @@ -516,14 +516,14 @@ public async Task Result_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var _ = Task.FromResult(42).[|Result|]; - Func, int> _2 = t => t.Result; - void LocalFunction() { - var _3 = Task.FromResult(42).Result; - } - } + [Fact] + public void TestMethod() { + var _ = Task.FromResult(42).[|Result|]; + Func, int> _2 = t => t.Result; + void LocalFunction() { + var _3 = Task.FromResult(42).Result; + } + } } """; @@ -538,14 +538,14 @@ public async Task Result_BeforeWhenAll_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task = Task.FromResult(42); + [Fact] + public async Task TestMethod() { + var task = Task.FromResult(42); - Assert.Equal(42, task.[|Result|]); + Assert.Equal(42, task.[|Result|]); - await Task.WhenAll(task); - } + await Task.WhenAll(task); + } } """; @@ -560,17 +560,17 @@ public async Task Result_ForUnawaitedTask_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.FromResult(42); - var task2 = Task.FromResult(2112); + [Fact] + public async Task TestMethod() { + var task1 = Task.FromResult(42); + var task2 = Task.FromResult(2112); - await Task.WhenAll(new[] { task1 }); + await Task.WhenAll(new[] { task1 }); - Assert.Equal(42, task1.Result); - Assert.Equal(2112, task2.[|Result|]); - Assert.Equal(2154, task1.Result + task2.[|Result|]); - } + Assert.Equal(42, task1.Result); + Assert.Equal(2112, task2.[|Result|]); + Assert.Equal(2154, task1.Result + task2.[|Result|]); + } } """; @@ -585,10 +585,10 @@ public async Task Result_InLambda_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var _ = Task.FromResult(42).ContinueWith(x => x.Result); - } + [Fact] + public void TestMethod() { + var _ = Task.FromResult(42).ContinueWith(x => x.Result); + } } """; @@ -603,17 +603,17 @@ public async Task Result_AfterWhenAll_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.FromResult(42); - var task2 = Task.FromResult(2112); + [Fact] + public async Task TestMethod() { + var task1 = Task.FromResult(42); + var task2 = Task.FromResult(2112); - await Task.WhenAll(task1, task2); + await Task.WhenAll(task1, task2); - Assert.Equal(42, task1.Result); - Assert.Equal(2112, task2.Result); - Assert.Equal(2154, task1.Result + task2.Result); - } + Assert.Equal(42, task1.Result); + Assert.Equal(2112, task2.Result); + Assert.Equal(2154, task1.Result + task2.Result); + } } """; @@ -628,15 +628,15 @@ public async Task Result_AfterWhenAny_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.FromResult(42); - var task2 = Task.FromResult(2112); + [Fact] + public async Task TestMethod() { + var task1 = Task.FromResult(42); + var task2 = Task.FromResult(2112); - var finishedTask = await Task.WhenAny(task1, task2); + var finishedTask = await Task.WhenAny(task1, task2); - Assert.Equal(2600, finishedTask.Result); - } + Assert.Equal(2600, finishedTask.Result); + } } """; @@ -655,14 +655,14 @@ public async Task GetResult_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var _ = Task.FromResult(42).GetAwaiter().[|GetResult()|]; - Func, int> _2 = t => t.GetAwaiter().GetResult(); - void LocalFunction() { - var _3 = Task.FromResult(42).GetAwaiter().GetResult(); - } - } + [Fact] + public void TestMethod() { + var _ = Task.FromResult(42).GetAwaiter().[|GetResult()|]; + Func, int> _2 = t => t.GetAwaiter().GetResult(); + void LocalFunction() { + var _3 = Task.FromResult(42).GetAwaiter().GetResult(); + } + } } """; @@ -678,14 +678,14 @@ public async Task GetResult_BeforeWhenAll_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task = Task.FromResult(42); + [Fact] + public async Task TestMethod() { + var task = Task.FromResult(42); - Assert.Equal(42, task.GetAwaiter().[|GetResult()|]); + Assert.Equal(42, task.GetAwaiter().[|GetResult()|]); - await Task.WhenAll(task); - } + await Task.WhenAll(task); + } } """; @@ -700,17 +700,17 @@ public async Task GetResult_OnUnawaitedTask_Triggers() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.FromResult(42); - var task2 = Task.FromResult(2112); + [Fact] + public async Task TestMethod() { + var task1 = Task.FromResult(42); + var task2 = Task.FromResult(2112); - await Task.WhenAll(new[] { task1 }); + await Task.WhenAll(new[] { task1 }); - Assert.Equal(42, task1.GetAwaiter().GetResult()); - Assert.Equal(2112, task2.GetAwaiter().[|GetResult()|]); - Assert.Equal(2154, task1.GetAwaiter().GetResult() + task2.GetAwaiter().[|GetResult()|]); - } + Assert.Equal(42, task1.GetAwaiter().GetResult()); + Assert.Equal(2112, task2.GetAwaiter().[|GetResult()|]); + Assert.Equal(2154, task1.GetAwaiter().GetResult() + task2.GetAwaiter().[|GetResult()|]); + } } """; @@ -725,10 +725,10 @@ public async Task GetResult_InLambda_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var _ = Task.FromResult(42).ContinueWith(x => x.GetAwaiter().GetResult()); - } + [Fact] + public void TestMethod() { + var _ = Task.FromResult(42).ContinueWith(x => x.GetAwaiter().GetResult()); + } } """; @@ -743,17 +743,17 @@ public async Task GetResult_AfterWhenAll_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.FromResult(42); - var task2 = Task.FromResult(2112); + [Fact] + public async Task TestMethod() { + var task1 = Task.FromResult(42); + var task2 = Task.FromResult(2112); - await Task.WhenAll(task1, task2); + await Task.WhenAll(task1, task2); - Assert.Equal(42, task1.GetAwaiter().GetResult()); - Assert.Equal(2112, task2.GetAwaiter().GetResult()); - Assert.Equal(2154, task1.GetAwaiter().GetResult() + task2.GetAwaiter().GetResult()); - } + Assert.Equal(42, task1.GetAwaiter().GetResult()); + Assert.Equal(2112, task2.GetAwaiter().GetResult()); + Assert.Equal(2154, task1.GetAwaiter().GetResult() + task2.GetAwaiter().GetResult()); + } } """; @@ -768,15 +768,15 @@ public async Task GetResult_AfterWhenAny_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var task1 = Task.FromResult(42); - var task2 = Task.FromResult(2112); + [Fact] + public async Task TestMethod() { + var task1 = Task.FromResult(42); + var task2 = Task.FromResult(2112); - var finishedTask = await Task.WhenAny(task1, task2); + var finishedTask = await Task.WhenAny(task1, task2); - Assert.Equal(2600, finishedTask.GetAwaiter().GetResult()); - } + Assert.Equal(2600, finishedTask.GetAwaiter().GetResult()); + } } """; @@ -796,14 +796,14 @@ public async Task GetResult_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - default(ValueTask).GetAwaiter().[|GetResult()|]; - Action _ = vt => vt.GetAwaiter().GetResult(); - void LocalFunction() { - default(ValueTask).GetAwaiter().GetResult(); - } - } + [Fact] + public void TestMethod() { + default(ValueTask).GetAwaiter().[|GetResult()|]; + Action _ = vt => vt.GetAwaiter().GetResult(); + void LocalFunction() { + default(ValueTask).GetAwaiter().GetResult(); + } + } } """; @@ -822,14 +822,14 @@ public async Task Result_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var _ = new ValueTask(42).[|Result|]; - Func, int> _2 = vt => vt.Result; - void LocalFunction() { - var _3 = new ValueTask(42).Result; - } - } + [Fact] + public void TestMethod() { + var _ = new ValueTask(42).[|Result|]; + Func, int> _2 = vt => vt.Result; + void LocalFunction() { + var _3 = new ValueTask(42).Result; + } + } } """; @@ -845,14 +845,14 @@ public async Task GetResult_Triggers() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var _ = new ValueTask(42).GetAwaiter().[|GetResult()|]; - Func, int> _2 = vt => vt.GetAwaiter().GetResult(); - void LocalFunction() { - var _3 = new ValueTask(42).GetAwaiter().GetResult(); - } - } + [Fact] + public void TestMethod() { + var _ = new ValueTask(42).GetAwaiter().[|GetResult()|]; + Func, int> _2 = vt => vt.GetAwaiter().GetResult(); + void LocalFunction() { + var _3 = new ValueTask(42).GetAwaiter().GetResult(); + } + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseConfigureAwaitTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseConfigureAwaitTests.cs index 9a55c7d4..3dcc64f6 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseConfigureAwaitTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/DoNotUseConfigureAwaitTests.cs @@ -13,10 +13,10 @@ public async Task NoCall_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - await Task.Delay(1); - } + [Fact] + public async Task TestMethod() { + await Task.Delay(1); + } } """; @@ -33,9 +33,9 @@ public async Task NonTestMethod_DoesNotTrigger() using Xunit; public class NonTestClass { - public async Task NonTestMethod() { - await Task.Delay(1).ConfigureAwait(false); - } + public async Task NonTestMethod() { + await Task.Delay(1).ConfigureAwait(false); + } } """; @@ -50,10 +50,10 @@ public async Task True_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - await Task.Delay(1).ConfigureAwait(true); - } + [Fact] + public async Task TestMethod() { + await Task.Delay(1).ConfigureAwait(true); + } } """; @@ -77,14 +77,14 @@ public async Task InvalidValue_InsideLambda_DoesNotTrigger(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var t = Task.Run(async () => {{ - await Task.Delay(1).ConfigureAwait({0}); - }}); - await t; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var t = Task.Run(async () => {{ + await Task.Delay(1).ConfigureAwait({0}); + }}); + await t; + }} }} """, argumentValue); @@ -100,13 +100,13 @@ public async Task InvalidValue_InsideLocalFunction_DoesNotTrigger(string argumen using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - async Task AssertEventStateAsync() {{ - await Task.Delay(1).ConfigureAwait({0}); - }} - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + async Task AssertEventStateAsync() {{ + await Task.Delay(1).ConfigureAwait({0}); + }} + }} }} """, argumentValue); @@ -122,11 +122,11 @@ public async Task InvalidValue_TaskWithAwait_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - await Task.Delay(1).{{|#0:ConfigureAwait({0})|}}; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + await Task.Delay(1).{{|#0:ConfigureAwait({0})|}}; + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Omit ConfigureAwait, or use ConfigureAwait(true) to avoid CA2007."); @@ -143,11 +143,11 @@ public async Task InvalidValue_TaskWithoutAwait_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var booleanVar = true; - Task.Delay(1).{{|#0:ConfigureAwait({0})|}}.GetAwaiter().GetResult(); - }} + [Fact] + public void TestMethod() {{ + var booleanVar = true; + Task.Delay(1).{{|#0:ConfigureAwait({0})|}}.GetAwaiter().GetResult(); + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Omit ConfigureAwait, or use ConfigureAwait(true) to avoid CA2007."); @@ -164,12 +164,12 @@ public async Task InvalidValue_TaskOfT_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var task = Task.FromResult(42); - await task.{{|#0:ConfigureAwait({0})|}}; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var task = Task.FromResult(42); + await task.{{|#0:ConfigureAwait({0})|}}; + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Omit ConfigureAwait, or use ConfigureAwait(true) to avoid CA2007."); @@ -186,12 +186,12 @@ public async Task InvalidValue_ValueTask_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.{{|#0:ConfigureAwait({0})|}}; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.{{|#0:ConfigureAwait({0})|}}; + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Omit ConfigureAwait, or use ConfigureAwait(true) to avoid CA2007."); @@ -208,12 +208,12 @@ public async Task InvalidValue_ValueTaskOfT_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.{{|#0:ConfigureAwait({0})|}}; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.{{|#0:ConfigureAwait({0})|}}; + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Omit ConfigureAwait, or use ConfigureAwait(true) to avoid CA2007."); @@ -234,9 +234,9 @@ public async Task NonTestMethod_DoesNotTrigger() using Xunit; public class NonTestClass { - public async Task NonTestMethod() { - await Task.Delay(1).ConfigureAwait(ConfigureAwaitOptions.None); - } + public async Task NonTestMethod() { + await Task.Delay(1).ConfigureAwait(ConfigureAwaitOptions.None); + } } """; @@ -254,10 +254,10 @@ public async Task ValidValue_DoesNotTrigger(string enumValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - await Task.Delay(1).ConfigureAwait({0}); - }} + [Fact] + public async Task TestMethod() {{ + await Task.Delay(1).ConfigureAwait({0}); + }} }} """, enumValue); @@ -283,14 +283,14 @@ public async Task InvalidValue_InsideLambda_DoesNotTrigger(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - var t = Task.Run(async () => {{ - await Task.Delay(1).ConfigureAwait({0}); - }}); - await t; - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + var t = Task.Run(async () => {{ + await Task.Delay(1).ConfigureAwait({0}); + }}); + await t; + }} }} """, argumentValue); @@ -306,13 +306,13 @@ public async Task InvalidValue_InsideLocalFunction_DoesNotTrigger(string argumen using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - async Task AssertEventStateAsync() {{ - await Task.Delay(1).ConfigureAwait({0}); - }} - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + async Task AssertEventStateAsync() {{ + await Task.Delay(1).ConfigureAwait({0}); + }} + }} }} """, argumentValue); @@ -328,11 +328,11 @@ public async Task InvalidValue_TaskWithAwait_Triggers(string enumValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - await Task.Delay(1).{{|#0:ConfigureAwait({0})|}}; - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + await Task.Delay(1).{{|#0:ConfigureAwait({0})|}}; + }} }} """, enumValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(enumValue, "Ensure ConfigureAwaitOptions.ContinueOnCapturedContext in the flags."); @@ -349,11 +349,11 @@ public async Task InvalidValue_TaskWithoutAwait_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - Task.Delay(1).{{|#0:ConfigureAwait({0})|}}.GetAwaiter().GetResult(); - }} + [Fact] + public void TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + Task.Delay(1).{{|#0:ConfigureAwait({0})|}}.GetAwaiter().GetResult(); + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Ensure ConfigureAwaitOptions.ContinueOnCapturedContext in the flags."); @@ -370,12 +370,12 @@ public async Task InvalidValue_TaskOfT_Triggers(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - var task = Task.FromResult(42); - await task.{{|#0:ConfigureAwait({0})|}}; - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + var task = Task.FromResult(42); + await task.{{|#0:ConfigureAwait({0})|}}; + }} }} """, argumentValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(argumentValue, "Ensure ConfigureAwaitOptions.ContinueOnCapturedContext in the flags."); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/EnsureFixturesHaveASourceTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/EnsureFixturesHaveASourceTests.cs index b8e7d168..58869300 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/EnsureFixturesHaveASourceTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/EnsureFixturesHaveASourceTests.cs @@ -12,7 +12,7 @@ public async Task DoesNotTrigger() { var source = /* lang=c#-test */ """ public class NonTestClass { - public NonTestClass(object _) { } + public NonTestClass(object _) { } } """; @@ -32,9 +32,9 @@ public async Task SupportedTypes_V2_DoesNotTrigger(string attribute) using Xunit.Abstractions; {0} public class TestClass {{ - public TestClass(ITestOutputHelper _) {{ }} + public TestClass(ITestOutputHelper _) {{ }} - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """, attribute); @@ -51,9 +51,9 @@ public async Task SupportedTypes_V3_DoesNotTrigger(string attribute) using Xunit.v3; {0} public class TestClass {{ - public TestClass(ITestOutputHelper _1, ITestContextAccessor _2) {{ }} + public TestClass(ITestOutputHelper _1, ITestContextAccessor _2) {{ }} - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """, attribute); @@ -67,9 +67,9 @@ public async Task OptionalParameter_DoesNotTrigger() using Xunit; public class TestClass { - public TestClass(bool value = true) { } + public TestClass(bool value = true) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; @@ -110,9 +110,9 @@ public abstract class BaseClass {1} {{ }} {2} public class TestClass : BaseClass {3} {{ - public TestClass(object _) {{ }} + public TestClass(object _) {{ }} - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """, baseAttribute, baseInterface, derivedAttribute, derivedInterface); @@ -130,9 +130,9 @@ public class TestCollection : IClassFixture { } [Collection(nameof(TestCollection))] public class TestClass { - public TestClass(object _) { } + public TestClass(object _) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; @@ -146,9 +146,9 @@ public async Task MissingClassFixtureDefinition_Triggers() using Xunit; public class TestClass { - public TestClass(object [|_|]) { } + public TestClass(object [|_|]) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; @@ -171,7 +171,7 @@ public class TestCollection {{ }} [Collection(nameof(TestCollection))] public class TestClass {{ - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """, definitionAttribute); @@ -199,15 +199,15 @@ public class Fixture {{ }} public class TestCollection : ICollectionFixture {{ }} public abstract class TestContext {{ - protected TestContext(Fixture fixture) {{ }} + protected TestContext(Fixture fixture) {{ }} }} {1} public class TestClass : TestContext {{ - public TestClass(Fixture fixture) : base(fixture) {{ }} + public TestClass(Fixture fixture) : base(fixture) {{ }} - [Fact] - public void TestMethod() {{ }} + [Fact] + public void TestMethod() {{ }} }} """, collectionDefinition, collectionReference); @@ -229,10 +229,10 @@ public class TestCollection : ICollectionFixture {|#0:fixture|}) { } + public TestClass(Fixture {|#0:fixture|}) { } - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; var expectedV2 = Verify.Diagnostic().WithLocation(0).WithArguments("fixture"); @@ -254,14 +254,14 @@ public class TestCollection : ICollectionFixture { - protected TestContext(Fixture fixture) { } + protected TestContext(Fixture fixture) { } } public class TestClass : TestContext { - public TestClass(Fixture {|#0:fixture|}) : base(fixture) { } + public TestClass(Fixture {|#0:fixture|}) : base(fixture) { } - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; var expectedV2 = Verify.Diagnostic().WithLocation(0).WithArguments("fixture"); @@ -288,7 +288,7 @@ public abstract class BaseClass {{ }} {1} public class TestClass : BaseClass {{ - public TestClass(object _) {{ }} + public TestClass(object _) {{ }} }} """, baseAttribute, derivedAttribute); @@ -306,9 +306,9 @@ public class TestCollection : ICollectionFixture { } [Collection(nameof(TestCollection))] public class TestClass { - public TestClass(object _) { } + public TestClass(object _) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; @@ -328,9 +328,9 @@ public class TestCollection {{ }} [Collection(nameof(TestCollection))] public class TestClass {{ - public TestClass(object [|_|]) {{ }} + public TestClass(object [|_|]) {{ }} - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """, definitionAttribute); @@ -349,9 +349,9 @@ public async Task WithAssemblyFixture_DoesNotTrigger() [assembly: AssemblyFixture(typeof(object))] public class TestClass { - public TestClass(object _) { } + public TestClass(object _) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; @@ -374,9 +374,9 @@ public class TestCollection {{ }} [Collection(nameof(TestCollection))] public class TestClass : IClassFixture {{ - public TestClass(object _) {{ }} + public TestClass(object _) {{ }} - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """, definitionAttribute); @@ -397,9 +397,9 @@ public class TestCollection : ICollectionFixture {{ }} [Collection(nameof(TestCollection))] public class TestClass : IClassFixture {{ - public TestClass(ClassFixture _1, CollectionFixture _2, {0} _3) {{ }} + public TestClass(ClassFixture _1, CollectionFixture _2, {0} _3) {{ }} - [Fact] public void TestMethod() {{ }} + [Fact] public void TestMethod() {{ }} }} """; @@ -421,9 +421,9 @@ public class TestCollection : ICollectionFixture { } [Collection(nameof(TestCollection))] public class TestClass { - public TestClass(ClassFixture [|_1|], CollectionFixture _2) { } + public TestClass(ClassFixture [|_1|], CollectionFixture _2) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; @@ -444,9 +444,9 @@ public class TestCollection { } [Collection(nameof(TestCollection))] public class TestClass : IClassFixture { - public TestClass(ClassFixture _1, CollectionFixture [|_2|]) { } + public TestClass(ClassFixture _1, CollectionFixture [|_2|]) { } - [Fact] public void TestMethod() { } + [Fact] public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodMustNotHaveParametersTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodMustNotHaveParametersTests.cs index 4e64e254..ed7262a0 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodMustNotHaveParametersTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodMustNotHaveParametersTests.cs @@ -9,8 +9,8 @@ public async Task FactWithNoParameters_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -22,8 +22,8 @@ public async Task TheoryWithParameters_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - public void TestMethod(string p) { } + [Xunit.Theory] + public void TestMethod(string p) { } } """; @@ -35,8 +35,8 @@ public async Task FactWithParameters_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void [|TestMethod|](string p) { } + [Xunit.Fact] + public void [|TestMethod|](string p) { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodShouldNotHaveTestDataTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodShouldNotHaveTestDataTests.cs index 41f41d5a..6e359308 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodShouldNotHaveTestDataTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/FactMethodShouldNotHaveTestDataTests.cs @@ -9,8 +9,8 @@ public async Task FactWithNoDataAttributes_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -25,9 +25,9 @@ public async Task TheoryWithDataAttributes_DoesNotTrigger(string dataAttribute) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.Theory] + [Xunit.{0}] + public void TestMethod() {{ }} }} """, dataAttribute); @@ -43,9 +43,9 @@ public async Task FactDerivedMethodWithDataAttributes_DoesNotTrigger(string data var source1 = /* lang=c#-test */ "public class DerivedFactAttribute: Xunit.FactAttribute {}"; var source2 = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [DerivedFactAttribute] - [Xunit.{0}] - public void TestMethod() {{ }} + [DerivedFactAttribute] + [Xunit.{0}] + public void TestMethod() {{ }} }} """, dataAttribute); @@ -60,9 +60,9 @@ public async Task FactWithDataAttributes_Triggers(string dataAttribute) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Fact] - [Xunit.{0}] - public void [|TestMethod|]() {{ }} + [Xunit.Fact] + [Xunit.{0}] + public void [|TestMethod|]() {{ }} }} """, dataAttribute); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs index be8339a0..3bc32517 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataMustMatchTheoryParametersTests.cs @@ -18,9 +18,9 @@ public async Task MethodUsingParamsArgument() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc", "xyz")] - public void TestMethod(params string[] args) { } + [Xunit.Theory] + [Xunit.InlineData("abc", "xyz")] + public void TestMethod(params string[] args) { } } """; @@ -32,9 +32,9 @@ public async Task MethodUsingNullParamsArgument_NonNullable() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(null)] - public void TestMethod(params string[] args) { } + [Xunit.Theory] + [Xunit.InlineData(null)] + public void TestMethod(params string[] args) { } } """; @@ -48,9 +48,9 @@ public async Task MethodUsingNullParamsArgument_Nullable() #nullable enable public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(null)] - public void TestMethod(params string[]? args) { } + [Xunit.Theory] + [Xunit.InlineData(null)] + public void TestMethod(params string[]? args) { } } """; @@ -62,9 +62,9 @@ public async Task MethodUsingNormalAndParamsArgument() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc", "xyz")] - public void TestMethod(string first, params string[] args) { } + [Xunit.Theory] + [Xunit.InlineData("abc", "xyz")] + public void TestMethod(string first, params string[] args) { } } """; @@ -76,9 +76,9 @@ public async Task MethodUsingNormalAndNullParamsArgument_NonNullable() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc", null)] - public void TestMethod(string first, params string[] args) { } + [Xunit.Theory] + [Xunit.InlineData("abc", null)] + public void TestMethod(string first, params string[] args) { } } """; @@ -92,9 +92,9 @@ public async Task MethodUsingNormalAndNullParamsArgument_Nullable() #nullable enable public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc", null)] - public void TestMethod(string first, params string[]? args) { } + [Xunit.Theory] + [Xunit.InlineData("abc", null)] + public void TestMethod(string first, params string[]? args) { } } """; @@ -106,9 +106,9 @@ public async Task MethodUsingNormalAndUnusedParamsArgument() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc")] - public void TestMethod(string first, params string[] args) { } + [Xunit.Theory] + [Xunit.InlineData("abc")] + public void TestMethod(string first, params string[] args) { } } """; @@ -120,9 +120,9 @@ public async Task MethodUsingEmptyArrayForParams() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new int[] { })] - public void VariableArgumentsTest(params int[] sq) { } + [Xunit.Theory] + [Xunit.InlineData(new int[] { })] + public void VariableArgumentsTest(params int[] sq) { } } """; @@ -134,9 +134,9 @@ public async Task MethodUsingMixedArgumentsAndEmptyArrayForParams() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(21.12, new int[] { })] - public void VariableArgumentsTest(double d, params int[] sq) { } + [Xunit.Theory] + [Xunit.InlineData(21.12, new int[] { })] + public void VariableArgumentsTest(double d, params int[] sq) { } } """; @@ -148,9 +148,9 @@ public async Task MethodUsingNonEmptyArrayForParams() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new int[] { 1, 2, 3 })] - public void VariableArgumentsTest(params int[] sq) { } + [Xunit.Theory] + [Xunit.InlineData(new int[] { 1, 2, 3 })] + public void VariableArgumentsTest(params int[] sq) { } } """; @@ -162,9 +162,9 @@ public async Task MethodUsingMixedArgumentsAndNonEmptyArrayForParams() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(21.12, new int[] { 1, 2, 3 })] - public void VariableArgumentsTest(double d, params int[] sq) { } + [Xunit.Theory] + [Xunit.InlineData(21.12, new int[] { 1, 2, 3 })] + public void VariableArgumentsTest(double d, params int[] sq) { } } """; @@ -176,9 +176,9 @@ public async Task UsingParameters() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc", 1, null)] - public void TestMethod(string a, int b, object c) { } + [Xunit.Theory] + [Xunit.InlineData("abc", 1, null)] + public void TestMethod(string a, int b, object c) { } } """; @@ -190,9 +190,9 @@ public async Task UsingParametersWithDefaultValues() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc")] - public void TestMethod(string a, string b = "default", string c = null) { } + [Xunit.Theory] + [Xunit.InlineData("abc")] + public void TestMethod(string a, string b = "default", string c = null) { } } """; @@ -204,9 +204,9 @@ public async Task UsingParametersWithDefaultValuesAndParamsArgument() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc")] - public void TestMethod(string a, string b = "default", string c = null, params string[] d) { } + [Xunit.Theory] + [Xunit.InlineData("abc")] + public void TestMethod(string a, string b = "default", string c = null, params string[] d) { } } """; @@ -218,9 +218,9 @@ public async Task UsingParameterWithOptionalAttribute() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData("abc")] - public void TestMethod(string a, [System.Runtime.InteropServices.Optional] string b) { } + [Xunit.Theory] + [Xunit.InlineData("abc")] + public void TestMethod(string a, [System.Runtime.InteropServices.Optional] string b) { } } """; @@ -232,12 +232,13 @@ public async Task UsingMultipleParametersWithOptionalAttributes() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData] - [Xunit.InlineData("abc")] - [Xunit.InlineData("abc", "def")] - public void TestMethod([System.Runtime.InteropServices.Optional] string a, - [System.Runtime.InteropServices.Optional] string b) { } + [Xunit.Theory] + [Xunit.InlineData] + [Xunit.InlineData("abc")] + [Xunit.InlineData("abc", "def")] + public void TestMethod( + [System.Runtime.InteropServices.Optional] string a, + [System.Runtime.InteropServices.Optional] string b) { } } """; @@ -249,9 +250,9 @@ public async Task UsingExplicitArray() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new object[] { "abc", 1, null })] - public void TestMethod(string a, int b, object c) { } + [Xunit.Theory] + [Xunit.InlineData(new object[] { "abc", 1, null })] + public void TestMethod(string a, int b, object c) { } } """; @@ -263,9 +264,9 @@ public async Task UsingExplicitNamedArray() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(data: new object[] { "abc", 1, null })] - public void TestMethod(string a, int b, object c) { } + [Xunit.Theory] + [Xunit.InlineData(data: new object[] { "abc", 1, null })] + public void TestMethod(string a, int b, object c) { } } """; @@ -277,9 +278,9 @@ public async Task UsingImplicitArray() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new[] { (object)"abc", 1, null })] - public void TestMethod(string a, int b, object c) { } + [Xunit.Theory] + [Xunit.InlineData(new[] { (object)"abc", 1, null })] + public void TestMethod(string a, int b, object c) { } } """; @@ -291,9 +292,9 @@ public async Task UsingImplicitNamedArray() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(data: new[] { (object)"abc", 1, null })] - public void TestMethod(string a, int b, object c) { } + [Xunit.Theory] + [Xunit.InlineData(data: new[] { (object)"abc", 1, null })] + public void TestMethod(string a, int b, object c) { } } """; @@ -305,9 +306,9 @@ public async Task EmptyArray() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new byte[0])] - public void TestMethod(byte[] input) { } + [Xunit.Theory] + [Xunit.InlineData(new byte[0])] + public void TestMethod(byte[] input) { } } """; @@ -340,9 +341,9 @@ public async Task IgnoresFact() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [Xunit.InlineData] - public void TestMethod(string a) { } + [Xunit.Fact] + [Xunit.InlineData] + public void TestMethod(string a) { } } """; @@ -356,9 +357,9 @@ public async Task NoArguments(string attribute) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [{{|xUnit1009:{0}|}}] - public void TestMethod(int a) {{ }} + [Xunit.Theory] + [{{|xUnit1009:{0}|}}] + public void TestMethod(int a) {{ }} }} """, attribute); @@ -370,9 +371,9 @@ public async Task TooFewArguments() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [{|xUnit1009:Xunit.InlineData(1)|}] - public void TestMethod(int a, int b, string c) { } + [Xunit.Theory] + [{|xUnit1009:Xunit.InlineData(1)|}] + public void TestMethod(int a, int b, string c) { } } """; @@ -384,9 +385,9 @@ public async Task TooFewArguments_WithParams() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [{|xUnit1009:Xunit.InlineData(1)|}] - public void TestMethod(int a, int b, params string[] value) { } + [Xunit.Theory] + [{|xUnit1009:Xunit.InlineData(1)|}] + public void TestMethod(int a, int b, params string[] value) { } } """; @@ -401,9 +402,9 @@ public async Task MethodUsingIncompatibleExplicitArrayForParams() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(21.12, {|xUnit1010:new object[] { }|})] - public void VariableArgumentsTest(double d, params int[] sq) { } + [Xunit.Theory] + [Xunit.InlineData(21.12, {|xUnit1010:new object[] { }|})] + public void VariableArgumentsTest(double d, params int[] sq) { } } """; @@ -441,9 +442,9 @@ public async Task CompatibleNumericValue_NonNullableType( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod({1} a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod({1} a) {{ }} }} """, value, type); @@ -458,9 +459,9 @@ public async Task CompatibleNumericValue_NullableType( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod({1}? a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod({1}? a) {{ }} }} """, value, type); @@ -475,9 +476,9 @@ public async Task BooleanValue_NumericType( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod({1} a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod({1} a) {{ }} }} """, value, type); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", type); @@ -491,9 +492,9 @@ public async Task CharValue_NumericType(string type) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData('a')] - public void TestMethod({0} a) {{ }} + [Xunit.Theory] + [Xunit.InlineData('a')] + public void TestMethod({0} a) {{ }} }} """, type); @@ -506,9 +507,9 @@ public async Task EnumValue_NumericType(string type) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:System.StringComparison.InvariantCulture|}})] - public void TestMethod({0} a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:System.StringComparison.InvariantCulture|}})] + public void TestMethod({0} a) {{ }} }} """, type); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", type); @@ -525,9 +526,9 @@ public async Task FromBooleanValue_ToNonNullable(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(bool a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(bool a) {{ }} }} """, value); @@ -540,9 +541,9 @@ public async Task FromBooleanValue_ToNullable(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(bool? a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(bool? a) {{ }} }} """, value); @@ -559,9 +560,9 @@ public async Task FromIncompatibleValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(bool a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(bool a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "bool"); @@ -579,9 +580,9 @@ public async Task FromCharOrIntegerValue_ToNonNullable(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(char a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(char a) {{ }} }} """, value); @@ -595,9 +596,9 @@ public async Task FromCharOrIntegerValue_ToNullable(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(char? a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(char? a) {{ }} }} """, value); @@ -614,9 +615,9 @@ public async Task FromIncompatibleValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(char a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(char a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "char"); @@ -632,9 +633,9 @@ public async Task FromEnumValue_ToNonNullable() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(System.StringComparison.Ordinal)] - public void TestMethod(System.StringComparison a) { } + [Xunit.Theory] + [Xunit.InlineData(System.StringComparison.Ordinal)] + public void TestMethod(System.StringComparison a) { } } """; @@ -646,9 +647,9 @@ public async Task FromEnumValue_ToNullable() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(System.StringComparison.Ordinal)] - public void TestMethod(System.StringComparison? a) { } + [Xunit.Theory] + [Xunit.InlineData(System.StringComparison.Ordinal)] + public void TestMethod(System.StringComparison? a) { } } """; @@ -665,9 +666,9 @@ public async Task FromIncompatibleValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(System.StringComparison a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(System.StringComparison a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "System.StringComparison"); @@ -685,9 +686,9 @@ public async Task FromTypeValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(System.Type a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(System.Type a) {{ }} }} """, value); @@ -701,9 +702,9 @@ public async Task FromTypeValue_ToParams(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(params System.Type[] a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(params System.Type[] a) {{ }} }} """, value); @@ -720,9 +721,9 @@ public async Task FromIncompatibleValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(System.Type a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(System.Type a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "System.Type"); @@ -740,9 +741,9 @@ public async Task FromIncompatibleValue_ToParams(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(params System.Type[] a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(params System.Type[] a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "System.Type"); @@ -760,9 +761,9 @@ public async Task FromStringValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(string a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(string a) {{ }} }} """, value); @@ -779,9 +780,9 @@ public async Task FromIncompatibleValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(string a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(string a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "string"); @@ -800,9 +801,9 @@ public async Task FromTypeImplementingInterface(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(System.IFormattable a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(System.IFormattable a) {{ }} }} """, value); @@ -820,9 +821,9 @@ public async Task FromIncompatibleValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(System.IFormattable a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(System.IFormattable a) {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "System.IFormattable"); @@ -845,9 +846,9 @@ public async Task FromAnyValue(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(object a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(object a) {{ }} }} """, value); @@ -866,9 +867,9 @@ public async Task FromAnyValue_ToParams(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(params object[] a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(params object[] a) {{ }} }} """, value); @@ -890,9 +891,9 @@ public async Task FromAnyValue_NoConstraint(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(T a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(T a) {{ }} }} """, value); @@ -908,9 +909,9 @@ public async Task FromValueTypeValue_WithStructConstraint(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(T a) where T: struct {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(T a) where T: struct {{ }} }} """, value); @@ -924,9 +925,9 @@ public async Task FromReferenceTypeValue_WithStructConstraint(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(T a) where T: struct {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(T a) where T: struct {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "T"); @@ -942,9 +943,9 @@ public async Task FromReferenceTypeValue_WithClassConstraint(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(T a) where T: class {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(T a) where T: class {{ }} }} """, value); @@ -960,9 +961,9 @@ public async Task FromValueTypeValue_WithClassConstraint(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(T a) where T: class {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(T a) where T: class {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "T"); @@ -978,9 +979,9 @@ public async Task FromCompatibleValue_WithTypeConstraint(string value) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(T a) where T: System.IConvertible, System.IFormattable {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(T a) where T: System.IConvertible, System.IFormattable {{ }} }} """, value); @@ -999,9 +1000,9 @@ public async Task FromIncompatibleValue_WithTypeConstraint(string value) var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(T a) where T: System.IConvertible, System.IFormattable {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(T a) where T: System.IConvertible, System.IFormattable {{ }} }} """, value); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "T"); @@ -1014,9 +1015,9 @@ public async Task FromIncompatibleArray() { var source =/* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new int[] { {|#0:1|}, 2, 3 })] - public void TestMethod(T a) where T: System.IConvertible, System.IFormattable { } + [Xunit.Theory] + [Xunit.InlineData(new int[] { {|#0:1|}, 2, 3 })] + public void TestMethod(T a) where T: System.IConvertible, System.IFormattable { } } """; var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("a", "T"); @@ -1029,9 +1030,9 @@ public async Task FromCompatibleArray() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new int[] { 1, 2, 3 })] - public void TestMethod(T[] a) { } + [Xunit.Theory] + [Xunit.InlineData(new int[] { 1, 2, 3 })] + public void TestMethod(T[] a) { } } """; @@ -1046,9 +1047,9 @@ public async Task FromNegativeInteger_ToUnsignedInteger( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:({0})-1|}})] - public void TestMethod({1} value) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:({0})-1|}})] + public void TestMethod({1} value) {{ }} }} """, signedType, unsignedType); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("value", unsignedType); @@ -1062,9 +1063,9 @@ public async Task FromLongMinValue_ToUnsignedInteger(string unsignedType) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:long.MinValue|}})] - public void TestMethod({0} value) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:long.MinValue|}})] + public void TestMethod({0} value) {{ }} }} """, unsignedType); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("value", unsignedType); @@ -1097,11 +1098,11 @@ public async Task NonStringValue( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - const int MyConstInt = 1; + const int MyConstInt = 1; - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod({1} parameter) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod({1} parameter) {{ }} }} """, data, parameterType); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("parameter", parameterType); @@ -1141,11 +1142,11 @@ static string CreateSourceWithStringConst( string data, string parameterType) => string.Format(/* lang=c#-test */ """ public class TestClass {{ - const string MyConstString = "some string"; + const string MyConstString = "some string"; - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod({1} parameter) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod({1} parameter) {{ }} }} """, data, parameterType); } @@ -1168,11 +1169,11 @@ public async Task NonStringValue(string data) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - private const int MyConstInt = 1; + private const int MyConstInt = 1; - [Xunit.Theory] - [Xunit.InlineData({{|#0:{0}|}})] - public void TestMethod(System.Guid parameter) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:{0}|}})] + public void TestMethod(System.Guid parameter) {{ }} }} """, data); var expected = Verify.Diagnostic("xUnit1010").WithLocation(0).WithArguments("parameter", "System.Guid"); @@ -1201,9 +1202,9 @@ public async Task StringValue_Pre240(string data) static string CreateSource(string data) => string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - public void TestMethod(System.Guid parameter) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + public void TestMethod(System.Guid parameter) {{ }} }} """, data); } @@ -1217,15 +1218,15 @@ public async Task SupportsImplicitConversion() using Xunit; public class TestClass { - [Theory] - [InlineData("abc")] - public void ParameterDeclaredImplicitConversion(Implicit i) => Assert.Equal("abc", i.Value); - - public class Implicit { - public string Value { get; set; } - public static implicit operator Implicit(string value) => new Implicit() { Value = value }; - public static implicit operator string(Implicit i) => i.Value; - } + [Theory] + [InlineData("abc")] + public void ParameterDeclaredImplicitConversion(Implicit i) => Assert.Equal("abc", i.Value); + + public class Implicit { + public string Value { get; set; } + public static implicit operator Implicit(string value) => new Implicit() { Value = value }; + public static implicit operator string(Implicit i) => i.Value; + } } """; @@ -1239,15 +1240,15 @@ public async Task SupportsExplicitConversion() using Xunit; public class TestClass { - [Theory] - [InlineData("abc")] - public void ParameterDeclaredExplicitConversion(Explicit i) => Assert.Equal("abc", i.Value); - - public class Explicit { - public string Value { get; set; } - public static explicit operator Explicit(string value) => new Explicit() { Value = value }; - public static explicit operator string(Explicit i) => i.Value; - } + [Theory] + [InlineData("abc")] + public void ParameterDeclaredExplicitConversion(Explicit i) => Assert.Equal("abc", i.Value); + + public class Explicit { + public string Value { get; set; } + public static explicit operator Explicit(string value) => new Explicit() { Value = value }; + public static explicit operator string(Explicit i) => i.Value; + } } """; @@ -1307,9 +1308,9 @@ public async Task IgnoresFact() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [Xunit.InlineData(1, 2, "abc")] - public void TestMethod(int a) { } + [Xunit.Fact] + [Xunit.InlineData(1, 2, "abc")] + public void TestMethod(int a) { } } """; @@ -1321,9 +1322,9 @@ public async Task ExtraArguments() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(1, {|#0:2|}, {|#1:"abc"|})] - public void TestMethod(int a) { } + [Xunit.Theory] + [Xunit.InlineData(1, {|#0:2|}, {|#1:"abc"|})] + public void TestMethod(int a) { } } """; var expected = new[] @@ -1343,9 +1344,9 @@ public async Task IgnoresFact() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [Xunit.InlineData(null)] - public void TestMethod(int a) { } + [Xunit.Fact] + [Xunit.InlineData(null)] + public void TestMethod(int a) { } } """; @@ -1359,9 +1360,9 @@ public async Task SingleNullValue(string type) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({{|#0:null|}})] - public void TestMethod({0} a) {{ }} + [Xunit.Theory] + [Xunit.InlineData({{|#0:null|}})] + public void TestMethod({0} a) {{ }} }} """, type); var expected = Verify.Diagnostic("xUnit1012").WithLocation(0).WithArguments("a", "int"); @@ -1375,9 +1376,9 @@ public async Task NonNullableValueTypes(string type) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, {{|#0:null|}}, {{|#1:null|}})] - public void TestMethod(int a, {0} b, params {0}[] c) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, {{|#0:null|}}, {{|#1:null|}})] + public void TestMethod(int a, {0} b, params {0}[] c) {{ }} }} """, type); var expected = new[] @@ -1395,9 +1396,9 @@ public async Task NullableValueTypes(string type) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, null)] - public void TestMethod(int a, {0}? b) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, null)] + public void TestMethod(int a, {0}? b) {{ }} }} """, type); @@ -1412,9 +1413,9 @@ public async Task ReferenceTypes(string type) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, null)] - public void TestMethod(int a, {0} b) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, null)] + public void TestMethod(int a, {0} b) {{ }} }} """, type); @@ -1431,9 +1432,9 @@ public async Task NonNullableReferenceTypes(string type) #nullable enable public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, {{|#0:null|}})] - public void TestMethod(int a, {0} b) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, {{|#0:null|}})] + public void TestMethod(int a, {0} b) {{ }} }} """, type); var expected = Verify.Diagnostic("xUnit1012").WithLocation(0).WithArguments("b", type); @@ -1451,9 +1452,9 @@ public async Task NullableReferenceTypes(string type) #nullable enable public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, null)] - public void TestMethod(int a, {0}? b) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, null)] + public void TestMethod(int a, {0}? b) {{ }} }} """, type); @@ -1471,9 +1472,9 @@ public async Task NullableParamsReferenceTypes( #nullable enable public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, {0}, null, null)] - public void TestMethod(int a, params {1}?[] b) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, {0}, null, null)] + public void TestMethod(int a, params {1}?[] b) {{ }} }} """, param, type); @@ -1491,9 +1492,9 @@ public async Task NonNullableParamsReferenceTypes( #nullable enable public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, {0}, {{|#0:null|}}, {{|#1:null|}})] - public void TestMethod(int a, params {1}[] b) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, {0}, {{|#0:null|}}, {{|#1:null|}})] + public void TestMethod(int a, params {1}[] b) {{ }} }} """, param, type); var expected = new[] diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataShouldBeUniqueWithinTheoryTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataShouldBeUniqueWithinTheoryTests.cs index b826a78b..9e1935a2 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataShouldBeUniqueWithinTheoryTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/InlineDataShouldBeUniqueWithinTheoryTests.cs @@ -12,8 +12,8 @@ public async Task WithNoDataAttributes_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -28,9 +28,9 @@ public async Task WithDataAttributesOtherThanInline_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.Theory] + [Xunit.{0}] + public void TestMethod() {{ }} }} """, dataAttribute); @@ -45,9 +45,9 @@ public async Task NonTheory_SingleInlineData_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [Xunit.InlineData] - public void TestMethod(int x) { } + [Xunit.Fact] + [Xunit.InlineData] + public void TestMethod(int x) { } } """; @@ -59,10 +59,10 @@ public async Task NonTheory_DoubledInlineData_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [Xunit.InlineData] - [Xunit.InlineData] - public void TestMethod(int x) { } + [Xunit.Fact] + [Xunit.InlineData] + [Xunit.InlineData] + public void TestMethod(int x) { } } """; @@ -74,9 +74,9 @@ public async Task SingleInlineData_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(10)] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData(10)] + public void TestMethod(int x) { } } """; @@ -88,10 +88,10 @@ public async Task MultipleInlineData_DifferentValues_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(10)] - [Xunit.InlineData(20)] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData(10)] + [Xunit.InlineData(20)] + public void TestMethod(int x) { } } """; @@ -107,10 +107,10 @@ public async Task UniqueValues_WithParamsInitializerValues_DoesNotTrigger(string { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1, 2)] - [Xunit.InlineData({0})] - public void TestMethod(params int[] args) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1, 2)] + [Xunit.InlineData({0})] + public void TestMethod(params int[] args) {{ }} }} """, data); @@ -122,10 +122,10 @@ public async Task UniqueValues_WithOverridingDefaultValues_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(1)] - [Xunit.InlineData(1, "non-default-val")] - public void TestMethod(int x, string a = "default-val") { } + [Xunit.Theory] + [Xunit.InlineData(1)] + [Xunit.InlineData(1, "non-default-val")] + public void TestMethod(int x, string a = "default-val") { } } """; @@ -137,10 +137,10 @@ public async Task NullAndEmpty_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(null)] - [Xunit.InlineData] - public void TestMethod(string s) { } + [Xunit.Theory] + [Xunit.InlineData(null)] + [Xunit.InlineData] + public void TestMethod(string s) { } } """; @@ -152,10 +152,10 @@ public async Task NullAndArray_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass{ - [Xunit.Theory] - [Xunit.InlineData(new[] { 0 })] - [Xunit.InlineData(null)] - public void TestMethod(int[] arr) { } + [Xunit.Theory] + [Xunit.InlineData(new[] { 0 })] + [Xunit.InlineData(null)] + public void TestMethod(int[] arr) { } } """; @@ -171,10 +171,10 @@ public async Task ArrayOrderVariance_DoesNotTrigger() // would cause the other parameters to not be evaluated for equality at all. var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new int[] { 1 }, new int[0], new int[] { 1 })] - [Xunit.InlineData(new int[] { 1 }, new int[] { 1 }, new int[0])] - public static void Test(int[] x, int[] y, int[] z) { } + [Xunit.Theory] + [Xunit.InlineData(new int[] { 1 }, new int[0], new int[] { 1 })] + [Xunit.InlineData(new int[] { 1 }, new int[] { 1 }, new int[0])] + public static void Test(int[] x, int[] y, int[] z) { } } """; @@ -189,10 +189,10 @@ public async Task DoubleEmptyInlineData_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData] - [{|#0:Xunit.InlineData|}] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData] + [{|#0:Xunit.InlineData|}] + public void TestMethod(int x) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -205,10 +205,10 @@ public async Task DoubleNullInlineData_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(null)] - [{|#0:Xunit.InlineData(null)|}] - public void TestMethod(string x) { } + [Xunit.Theory] + [Xunit.InlineData(null)] + [{|#0:Xunit.InlineData(null)|}] + public void TestMethod(string x) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -221,10 +221,10 @@ public async Task DoubleValues_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(10)] - [{|#0:Xunit.InlineData(10)|}] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData(10)] + [{|#0:Xunit.InlineData(10)|}] + public void TestMethod(int x) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -237,12 +237,12 @@ public async Task ValueFromConstant_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - private const int X = 10; + private const int X = 10; - [Xunit.Theory] - [Xunit.InlineData(10)] - [{|#0:Xunit.InlineData(X)|}] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData(10)] + [{|#0:Xunit.InlineData(X)|}] + public void TestMethod(int x) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -257,10 +257,10 @@ public async Task TwoParams_RawValuesVsArgumentArray_Triggers(string data) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(10, 20)] - [{{|#0:Xunit.InlineData({0})|}}] - public void TestMethod(int x, int y) {{ }} + [Xunit.Theory] + [Xunit.InlineData(10, 20)] + [{{|#0:Xunit.InlineData({0})|}}] + public void TestMethod(int x, int y) {{ }} }} """, data); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -275,10 +275,10 @@ public async Task ParamsArray_RawValuesVsArgumentArray_Triggers(string data) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(10, 20)] - [{{|#0:Xunit.InlineData({0})|}}] - public void TestMethod(params int[] args) {{ }} + [Xunit.Theory] + [Xunit.InlineData(10, 20)] + [{{|#0:Xunit.InlineData({0})|}}] + public void TestMethod(params int[] args) {{ }} }} """, data); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -291,10 +291,10 @@ public async Task DoubledArgumentArrays_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new object[] { 10, 20 })] - [{|#0:Xunit.InlineData(new object[] { 10, 20 })|}] - public void TestMethod(int x, int y) { } + [Xunit.Theory] + [Xunit.InlineData(new object[] { 10, 20 })] + [{|#0:Xunit.InlineData(new object[] { 10, 20 })|}] + public void TestMethod(int x, int y) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -307,10 +307,10 @@ public async Task DoubledComplexValuesForObject_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(new object[] {10, new object[] { new object[] {20}, 30}})] - [{|#0:Xunit.InlineData(new object[] {10, new object[] { new object[] {20}, 30}})|}] - public void TestMethod(object x, object y) { } + [Xunit.Theory] + [Xunit.InlineData(new object[] {10, new object[] { new object[] {20}, 30}})] + [{|#0:Xunit.InlineData(new object[] {10, new object[] { new object[] {20}, 30}})|}] + public void TestMethod(object x, object y) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -323,10 +323,10 @@ public async Task DoubledComplexValues_RawValuesVsArgumentArray_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(10, new object[] { new object[] {20}, 30}, 40)] - [{|#0:Xunit.InlineData(new object[] {10, new object[] { new object[] {20}, 30}})|}] - public void TestMethod(object x, object y, int z = 40) { } + [Xunit.Theory] + [Xunit.InlineData(10, new object[] { new object[] {20}, 30}, 40)] + [{|#0:Xunit.InlineData(new object[] {10, new object[] { new object[] {20}, 30}})|}] + public void TestMethod(object x, object y, int z = 40) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -343,10 +343,10 @@ public async Task DefaultValueVsExplicitValue_Triggers(int defaultValue) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData] - [{{|#0:Xunit.InlineData({0})|}}] - public void TestMethod(int y = {0}) {{ }} + [Xunit.Theory] + [Xunit.InlineData] + [{{|#0:Xunit.InlineData({0})|}}] + public void TestMethod(int y = {0}) {{ }} }} """, defaultValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -360,10 +360,10 @@ public async Task ExplicitValueVsDefaultValue_Triggers(int defaultValue) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - [{{|#0:Xunit.InlineData|}}] - public void TestMethod(int y = {0}) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + [{{|#0:Xunit.InlineData|}}] + public void TestMethod(int y = {0}) {{ }} }} """, defaultValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -377,10 +377,10 @@ public async Task DefaultValueVsDefaultValue_Triggers(int defaultValue) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData] - [{{|#0:Xunit.InlineData|}}] - public void TestMethod(int y = {0}) {{ }} + [Xunit.Theory] + [Xunit.InlineData] + [{{|#0:Xunit.InlineData|}}] + public void TestMethod(int y = {0}) {{ }} }} """, defaultValue); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -399,10 +399,10 @@ public async Task DefaultValueVsNull_Triggers( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData({0})] - [{{|#0:Xunit.InlineData({1})|}}] - public void TestMethod(string x = null) {{ }} + [Xunit.Theory] + [Xunit.InlineData({0})] + [{{|#0:Xunit.InlineData({1})|}}] + public void TestMethod(string x = null) {{ }} }} """, firstArg, secondArg); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -415,10 +415,10 @@ public async Task Null_RawValuesVsExplicitArray_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(1, null)] - [{|#0:Xunit.InlineData(new object[] { 1, null })|}] - public void TestMethod(object x, object y) { } + [Xunit.Theory] + [Xunit.InlineData(1, null)] + [{|#0:Xunit.InlineData(new object[] { 1, null })|}] + public void TestMethod(object x, object y) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -437,10 +437,10 @@ public async Task DefaultOfStruct_Triggers( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1{0})] - [{{|#0:Xunit.InlineData(1{1})|}}] - public void TestMethod(int x, System.DateTime date = default) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1{0})] + [{{|#0:Xunit.InlineData(1{1})|}}] + public void TestMethod(int x, System.DateTime date = default) {{ }} }} """, firstDefaultOverride, secondDefaultOverride); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -459,10 +459,10 @@ public async Task DefaultOfString_Triggers( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.InlineData(1{0})] - [{{|#0:Xunit.InlineData(1{1})|}}] - public void TestMethod(int x, string y = null) {{ }} + [Xunit.Theory] + [Xunit.InlineData(1{0})] + [{{|#0:Xunit.InlineData(1{1})|}}] + public void TestMethod(int x, string y = null) {{ }} }} """, firstDefaultOverride, secondDefaultOverride); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass"); @@ -475,11 +475,11 @@ public async Task Tripled_TriggersTwice() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(10)] - [{|#0:Xunit.InlineData(10)|}] - [{|#1:Xunit.InlineData(10)|}] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData(10)] + [{|#0:Xunit.InlineData(10)|}] + [{|#1:Xunit.InlineData(10)|}] + public void TestMethod(int x) { } } """; var expected = new[] @@ -496,12 +496,12 @@ public async Task DoubledTwice_TriggersTwice() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - [Xunit.InlineData(10)] - [Xunit.InlineData(20)] - [{|#0:Xunit.InlineData(10)|}] - [{|#1:Xunit.InlineData(20)|}] - public void TestMethod(int x) { } + [Xunit.Theory] + [Xunit.InlineData(10)] + [Xunit.InlineData(20)] + [{|#0:Xunit.InlineData(10)|}] + [{|#1:Xunit.InlineData(20)|}] + public void TestMethod(int x) { } } """; var expected = new[] diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/LocalFunctionsCannotBeTestFunctionsTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/LocalFunctionsCannotBeTestFunctionsTests.cs index 10ef1fa2..775dd110 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/LocalFunctionsCannotBeTestFunctionsTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/LocalFunctionsCannotBeTestFunctionsTests.cs @@ -10,9 +10,9 @@ public async Task NoTestAttribute_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - public void Method() { - void LocalFunction() { } - } + public void Method() { + void LocalFunction() { } + } } """; @@ -32,12 +32,12 @@ public async Task TestAttribute_Triggers(string attribute) using Xunit; public class TestClass {{ - public void Method() {{ - [{{|#0:{0}|}}] - void LocalFunction() {{ }} - }} + public void Method() {{ + [{{|#0:{0}|}}] + void LocalFunction() {{ }} + }} - public static IEnumerable MyData; + public static IEnumerable MyData; }} """, attribute); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"[{attribute}]"); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/MemberDataShouldReferenceValidMemberTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/MemberDataShouldReferenceValidMemberTests.cs index 7e8a55e5..0f247d77 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/MemberDataShouldReferenceValidMemberTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/MemberDataShouldReferenceValidMemberTests.cs @@ -13,11 +13,11 @@ public class X1014_MemberDataShouldUseNameOfOperator using Xunit; public partial class TestClass { - public static TheoryData Data { get; set; } + public static TheoryData Data { get; set; } } public class OtherClass { - public static TheoryData OtherData { get; set; } + public static TheoryData OtherData { get; set; } } """; @@ -26,8 +26,8 @@ public async Task NameofOnSameClass_DoesNotTrigger() { var source = /* lang=c#-test */ """ public partial class TestClass { - [Xunit.MemberData(nameof(Data))] - public void TestMethod(int _) { } + [Xunit.MemberData(nameof(Data))] + public void TestMethod(int _) { } } """; @@ -39,8 +39,8 @@ public async Task NameofOnOtherClass_DoesNotTrigger() { var source = /* lang=c#-test */ """ public partial class TestClass { - [Xunit.MemberData(nameof(OtherClass.OtherData), MemberType = typeof(OtherClass))] - public void TestMethod(int _) { } + [Xunit.MemberData(nameof(OtherClass.OtherData), MemberType = typeof(OtherClass))] + public void TestMethod(int _) { } } """; @@ -52,8 +52,8 @@ public async Task StringNameOnSameClass_Triggers() { var source = /* lang=c#-test */ """ public partial class TestClass { - [Xunit.MemberData({|#0:"Data"|})] - public void TestMethod(int _) { } + [Xunit.MemberData({|#0:"Data"|})] + public void TestMethod(int _) { } } """; var expected = Verify.Diagnostic("xUnit1014").WithLocation(0).WithArguments("Data", "TestClass"); @@ -66,8 +66,8 @@ public async Task StringNameOnOtherClass_Triggers() { var source = /* lang=c#-test */ """ public partial class TestClass { - [Xunit.MemberData({|#0:"OtherData"|}, MemberType = typeof(OtherClass))] - public void TestMethod(int _) { } + [Xunit.MemberData({|#0:"OtherData"|}, MemberType = typeof(OtherClass))] + public void TestMethod(int _) { } } """; var expected = Verify.Diagnostic("xUnit1014").WithLocation(0).WithArguments("OtherData", "OtherClass"); @@ -85,8 +85,8 @@ public async Task InvalidStringNameOnSameClass_Triggers(string memberType) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [{{|#0:Xunit.MemberData("BogusName"{0})|}}] - public void TestMethod() {{ }} + [{{|#0:Xunit.MemberData("BogusName"{0})|}}] + public void TestMethod() {{ }} }} """, memberType); var expected = Verify.Diagnostic("xUnit1015").WithLocation(0).WithArguments("BogusName", "TestClass"); @@ -99,8 +99,8 @@ public async Task InvalidStringNameOnOtherClass_Triggers() { var source1 = /* lang=c#-test */ """ public class TestClass { - [{|#0:Xunit.MemberData("BogusName", MemberType = typeof(OtherClass))|}] - public void TestMethod() { } + [{|#0:Xunit.MemberData("BogusName", MemberType = typeof(OtherClass))|}] + public void TestMethod() { } } """; var source2 = /* lang=c#-test */ """ @@ -116,8 +116,8 @@ public async Task InvalidNameofOnOtherClass_Triggers() { var source1 = /* lang=c#-test */ """ public class TestClass { - [{|#0:Xunit.MemberData(nameof(TestClass.TestMethod), MemberType = typeof(OtherClass))|}] - public void TestMethod() { } + [{|#0:Xunit.MemberData(nameof(TestClass.TestMethod), MemberType = typeof(OtherClass))|}] + public void TestMethod() { } } """; var source2 = /* lang=c#-test */ """ @@ -136,10 +136,10 @@ public async Task PublicMember_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - public static Xunit.TheoryData Data = null; + public static Xunit.TheoryData Data = null; - [Xunit.MemberData(nameof(Data))] - public void TestMethod(int _) { } + [Xunit.MemberData(nameof(Data))] + public void TestMethod(int _) { } } """; @@ -163,13 +163,13 @@ public async Task NonPublicNameExpression_Triggers( var source1 = string.Format(/* lang=c#-test */ """ public class TestClass {{ - const string DataNameConst = "Data"; - const string DataNameofConst = nameof(Data); + const string DataNameConst = "Data"; + const string DataNameofConst = nameof(Data); - {0} static Xunit.TheoryData Data = null; + {0} static Xunit.TheoryData Data = null; - [{{|xUnit1016:Xunit.MemberData({1})|}}] - public void TestMethod(int _) {{ }} + [{{|xUnit1016:Xunit.MemberData({1})|}}] + public void TestMethod(int _) {{ }} }} """, accessModifier, dataNameExpression); var source2 = /* lang=c#-test */ """ @@ -187,10 +187,10 @@ public async Task StaticMember_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - public static Xunit.TheoryData Data = null; + public static Xunit.TheoryData Data = null; - [Xunit.MemberData(nameof(Data))] - public void TestMethod(int _) { } + [Xunit.MemberData(nameof(Data))] + public void TestMethod(int _) { } } """; @@ -202,10 +202,10 @@ public async Task InstanceMember_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - public Xunit.TheoryData Data = null; + public Xunit.TheoryData Data = null; - [{|xUnit1017:Xunit.MemberData(nameof(Data))|}] - public void TestMethod(int _) { } + [{|xUnit1017:Xunit.MemberData(nameof(Data))|}] + public void TestMethod(int _) { } } """; @@ -223,10 +223,10 @@ public async Task ValidMemberKind_DoesNotTrigger(string member) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public static Xunit.TheoryData {0} + public static Xunit.TheoryData {0} - [Xunit.MemberData(nameof(Data))] - public void TestMethod(int _) {{ }} + [Xunit.MemberData(nameof(Data))] + public void TestMethod(int _) {{ }} }} """, member); @@ -241,10 +241,10 @@ public async Task InvalidMemberKind_Triggers(string member) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - {0} + {0} - [{{|xUnit1018:Xunit.MemberData(nameof(Data))|}}] - public void TestMethod() {{ }} + [{{|xUnit1018:Xunit.MemberData(nameof(Data))|}}] + public void TestMethod() {{ }} }} """, member); @@ -266,10 +266,10 @@ public async Task TheoryData_DoesNotTrigger() using Xunit; public class TestClass { - public static TheoryData Data; + public static TheoryData Data; - [MemberData(nameof(Data))] - public void TestMethod(int _) { } + [MemberData(nameof(Data))] + public void TestMethod(int _) { } } """; @@ -287,10 +287,10 @@ public async Task Async_TheoryData_TriggersInV2_DoesNotTriggerInV3(string taskTy using Xunit; public class TestClass {{ - public static {0}> Data; + public static {0}> Data; - [{{|#0:MemberData(nameof(Data))|}}] - public void TestMethod(int _) {{ }} + [{{|#0:MemberData(nameof(Data))|}}] + public void TestMethod(int _) {{ }} }} """, taskType); var expectedV2 = Verify.Diagnostic("xUnit1019").WithLocation(0).WithArguments("'System.Collections.Generic.IEnumerable'", $"System.Threading.Tasks.{taskType}>"); @@ -311,13 +311,13 @@ public async Task GenericTheoryDataRow_DoesNotTrigger(string dataType) using Xunit.Sdk; public class TestClass {{ - [Theory] - [MemberData(nameof(DataRowSource))] - public void SkippedDataRow(int x, string y) {{ }} + [Theory] + [MemberData(nameof(DataRowSource))] + public void SkippedDataRow(int x, string y) {{ }} - public static {0} DataRowSource() {{ - throw new NotImplementedException(); - }} + public static {0} DataRowSource() {{ + throw new NotImplementedException(); + }} }} """, dataType); @@ -337,13 +337,13 @@ public async Task Async_GenericTheoryDataRow_DoesNotTrigger(string taskType) using Xunit.Sdk; public class TestClass {{ - [Theory] - [MemberData(nameof(DataRowSource))] - public void SkippedDataRow(int x, string y) {{ }} + [Theory] + [MemberData(nameof(DataRowSource))] + public void SkippedDataRow(int x, string y) {{ }} - public static async {0} DataRowSource() {{ - throw new NotImplementedException(); - }} + public static async {0} DataRowSource() {{ + throw new NotImplementedException(); + }} }} """, taskType); @@ -360,10 +360,10 @@ public async Task InvalidMemberType_Triggers(string memberType) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public static {0} Data; + public static {0} Data; - [{{|#0:Xunit.MemberData(nameof(Data))|}}] - public void TestMethod() {{ }} + [{{|#0:Xunit.MemberData(nameof(Data))|}}] + public void TestMethod() {{ }} }} """, memberType); var expectedV2 = Verify.Diagnostic("xUnit1019").WithLocation(0).WithArguments("'System.Collections.Generic.IEnumerable'", memberType); @@ -381,10 +381,10 @@ public async Task PropertyWithoutGetter_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - public static Xunit.TheoryData Data { set { } } + public static Xunit.TheoryData Data { set { } } - [{|xUnit1020:Xunit.MemberData(nameof(Data))|}] - public void TestMethod(int _) { } + [{|xUnit1020:Xunit.MemberData(nameof(Data))|}] + public void TestMethod(int _) { } } """; @@ -399,10 +399,10 @@ public async Task PropertyWithNonPublicGetter_Triggers(string visibility) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public static Xunit.TheoryData Data {{ {0} get {{ return null; }} set {{ }} }} + public static Xunit.TheoryData Data {{ {0} get {{ return null; }} set {{ }} }} - [{{|xUnit1020:Xunit.MemberData(nameof(Data))|}}] - public void TestMethod(int _) {{ }} + [{{|xUnit1020:Xunit.MemberData(nameof(Data))|}}] + public void TestMethod(int _) {{ }} }} """, visibility); @@ -419,12 +419,12 @@ public async Task MethodMemberWithParameters_DoesNotTrigger(string parameter) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - private static void TestData() {{ }} + private static void TestData() {{ }} - public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; + public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; - [Xunit.MemberData(nameof(TestData), {0})] - public void TestMethod(int n) {{ }} + [Xunit.MemberData(nameof(TestData), {0})] + public void TestMethod(int n) {{ }} }} """, parameter); await Verify.VerifyAnalyzer(source); @@ -437,10 +437,10 @@ public async Task MethodMemberWithParamsArrayParameters_DoesNotTrigger(string pa { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public static Xunit.TheoryData TestData(params int[] n) => new Xunit.TheoryData {{ n[0] }}; + public static Xunit.TheoryData TestData(params int[] n) => new Xunit.TheoryData {{ n[0] }}; - [Xunit.MemberData(nameof(TestData), {0})] - public void TestMethod(int n) {{ }} + [Xunit.MemberData(nameof(TestData), {0})] + public void TestMethod(int n) {{ }} }} """, parameters); @@ -454,14 +454,14 @@ public async Task MethodMemberOnBaseType_DoesNotTrigger(string parameter) { var source = string.Format(/* lang=c#-test */ """ public class TestClassBase {{ - public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; + public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; }} public class TestClass : TestClassBase {{ - private static void TestData() {{ }} + private static void TestData() {{ }} - [Xunit.MemberData(nameof(TestData), {0})] - public void TestMethod(int n) {{ }} + [Xunit.MemberData(nameof(TestData), {0})] + public void TestMethod(int n) {{ }} }} """, parameter); @@ -476,10 +476,10 @@ public async Task FieldMemberWithParameters_Triggers(string paramsArgument) { var sourceTemplate = /* lang=c#-test */ """ public class TestClass {{ - public static Xunit.TheoryData Data; + public static Xunit.TheoryData Data; - [Xunit.MemberData(nameof(Data), {{|xUnit1021:{0}|}}, MemberType = typeof(TestClass))] - public void TestMethod(int _) {{ }} + [Xunit.MemberData(nameof(Data), {{|xUnit1021:{0}|}}, MemberType = typeof(TestClass))] + public void TestMethod(int _) {{ }} }} """; @@ -495,10 +495,10 @@ public async Task PropertyMemberWithParameters_Triggers(string paramsArgument) { var sourceTemplate = /* lang=c#-test */ """ public class TestClass {{ - public static Xunit.TheoryData Data {{ get; set; }} + public static Xunit.TheoryData Data {{ get; set; }} - [Xunit.MemberData(nameof(Data), {{|xUnit1021:{0}|}}, MemberType = typeof(TestClass))] - public void TestMethod(int _) {{ }} + [Xunit.MemberData(nameof(Data), {{|xUnit1021:{0}|}}, MemberType = typeof(TestClass))] + public void TestMethod(int _) {{ }} }} """; @@ -520,10 +520,10 @@ public async Task PassingNullForNullableReferenceType_DoesNotTrigger( {0} public class TestClass {{ - public static Xunit.TheoryData TestData({1} f) => new Xunit.TheoryData {{ 42 }}; + public static Xunit.TheoryData TestData({1} f) => new Xunit.TheoryData {{ 42 }}; - [Xunit.MemberData(nameof(TestData), new object[] {{ null }})] - public void TestMethod(int _) {{ }} + [Xunit.MemberData(nameof(TestData), new object[] {{ null }})] + public void TestMethod(int _) {{ }} }} """, header, argumentType); @@ -535,10 +535,10 @@ public async Task PassingNullForStructType_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData { n }; + public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData { n }; - [Xunit.MemberData(nameof(TestData), new object[] { {|#0:null|} })] - public void TestMethod(int _) { } + [Xunit.MemberData(nameof(TestData), new object[] { {|#0:null|} })] + public void TestMethod(int _) { } } """; var expected = Verify.Diagnostic("xUnit1034").WithLocation(0).WithArguments("n", "int"); @@ -553,10 +553,10 @@ public async Task PassingNullForNonNullableReferenceType_Triggers() #nullable enable public class TestClass { - public static Xunit.TheoryData TestData(string f) => new Xunit.TheoryData { f }; + public static Xunit.TheoryData TestData(string f) => new Xunit.TheoryData { f }; - [Xunit.MemberData(nameof(TestData), new object[] { {|#0:null|} })] - public void TestMethod(string _) { } + [Xunit.MemberData(nameof(TestData), new object[] { {|#0:null|} })] + public void TestMethod(string _) { } } """; var expected = Verify.Diagnostic("xUnit1034").WithLocation(0).WithArguments("f", "string"); @@ -579,13 +579,13 @@ public async Task ValidEnumValue_DoesNotTrigger(string enumValue) using Xunit; public class TestClass {{ - [Theory] - [MemberData(nameof(SomeData), {0})] - public void TestMethod(int _) {{ }} + [Theory] + [MemberData(nameof(SomeData), {0})] + public void TestMethod(int _) {{ }} - public enum Foo {{ Bar }} + public enum Foo {{ Bar }} - public static Xunit.TheoryData SomeData(Foo foo) => new Xunit.TheoryData(); + public static Xunit.TheoryData SomeData(Foo foo) => new Xunit.TheoryData(); }} """, enumValue); @@ -605,11 +605,11 @@ public async Task ArrayInitializerWithCorrectType_DoesNotTrigger(string header) using Xunit; public class TestClass {{ - public static TheoryData GetSequences(IEnumerable seq) => new TheoryData {{ 42, 2112 }}; + public static TheoryData GetSequences(IEnumerable seq) => new TheoryData {{ 42, 2112 }}; - [Theory] - [MemberData(nameof(GetSequences), new int[] {{ 1, 2 }})] - public void Test(int value) {{ }} + [Theory] + [MemberData(nameof(GetSequences), new int[] {{ 1, 2 }})] + public void Test(int value) {{ }} }} """, header); @@ -628,11 +628,11 @@ public async Task ArrayInitializerWithIncorrectType_Triggers(string header) using Xunit; public class TestClass {{ - public static TheoryData GetSequences(IEnumerable seq) => new TheoryData {{ 42, 2112 }}; + public static TheoryData GetSequences(IEnumerable seq) => new TheoryData {{ 42, 2112 }}; - [Theory] - [MemberData(nameof(GetSequences), {{|#0:new char[] {{ 'a', 'b' }}|}})] - public void Test(int value) {{ }} + [Theory] + [MemberData(nameof(GetSequences), {{|#0:new char[] {{ 'a', 'b' }}|}})] + public void Test(int value) {{ }} }} """, header); var expected = Verify.Diagnostic("xUnit1035").WithLocation(0).WithArguments("seq", "System.Collections.Generic.IEnumerable"); @@ -645,10 +645,10 @@ public async Task ValidMemberWithIncorrectArgumentTypes_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - public static Xunit.TheoryData TestData(string n) => new Xunit.TheoryData { n.Length }; + public static Xunit.TheoryData TestData(string n) => new Xunit.TheoryData { n.Length }; - [Xunit.MemberData(nameof(TestData), new object[] { {|#0:1|} })] - public void TestMethod(int n) { } + [Xunit.MemberData(nameof(TestData), new object[] { {|#0:1|} })] + public void TestMethod(int n) { } } """; var expected = Verify.Diagnostic("xUnit1035").WithLocation(0).WithArguments("n", "string"); @@ -661,10 +661,10 @@ public async Task ValidMemberWithIncorrectArgumentTypesParams_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - public static Xunit.TheoryData TestData(params int[] n) => new Xunit.TheoryData { n[0] }; + public static Xunit.TheoryData TestData(params int[] n) => new Xunit.TheoryData { n[0] }; - [Xunit.MemberData(nameof(TestData), new object[] { 1, {|#0:"bob"|} })] - public void TestMethod(int n) { } + [Xunit.MemberData(nameof(TestData), new object[] { 1, {|#0:"bob"|} })] + public void TestMethod(int n) { } } """; var expected = Verify.Diagnostic("xUnit1035").WithLocation(0).WithArguments("n", "int"); @@ -682,12 +682,12 @@ public async Task ValidArgumentCount_DoesNotTrigger(string parameter) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - private static void TestData() {{ }} + private static void TestData() {{ }} - public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; + public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; - [Xunit.MemberData(nameof(TestData), {0})] - public void TestMethod(int n) {{ }} + [Xunit.MemberData(nameof(TestData), {0})] + public void TestMethod(int n) {{ }} }} """, parameter); @@ -703,10 +703,10 @@ public async Task ValidArgumentCount_InNullableContext_DoesNotTrigger(string par #nullable enable public class TestClass {{ - public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; + public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; - [Xunit.MemberData(nameof(TestData), {0})] - public void TestMethod(int n) {{ }} + [Xunit.MemberData(nameof(TestData), {0})] + public void TestMethod(int n) {{ }} }} """, parameter); @@ -720,10 +720,10 @@ public async Task TooManyArguments_Triggers(string parameters) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; + public static Xunit.TheoryData TestData(int n) => new Xunit.TheoryData {{ n }}; - [Xunit.MemberData(nameof(TestData), {0})] - public void TestMethod(int n) {{ }} + [Xunit.MemberData(nameof(TestData), {0})] + public void TestMethod(int n) {{ }} }} """, parameters); var expected = Verify.Diagnostic("xUnit1036").WithLocation(0).WithArguments("2"); @@ -752,10 +752,10 @@ public async Task ValidTheoryDataMemberWithNotEnoughTypeParameters_Triggers( using Xunit; public class TestClass {{ - public static TheoryData TestData{0}new TheoryData(); + public static TheoryData TestData{0}new TheoryData(); - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void TestMethod(int n, string f) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void TestMethod(int n, string f) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1037").WithLocation(0).WithArguments("Xunit.TheoryData"); @@ -774,10 +774,10 @@ public async Task ValidTheoryDataRowMemberWithNotEnoughTypeParameters_Triggers( using Xunit; public class TestClass {{ - public static IEnumerable> TestData{0}null; + public static IEnumerable> TestData{0}null; - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void TestMethod(int n, string f) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void TestMethod(int n, string f) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1037").WithLocation(0).WithArguments("Xunit.TheoryDataRow"); @@ -797,10 +797,10 @@ public async Task ValidSubclassedTheoryDataMemberWithNotEnoughTypeParameters_Tri public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static DerivedTheoryData TestData{0}new DerivedTheoryData(); + public static DerivedTheoryData TestData{0}new DerivedTheoryData(); - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void TestMethod(int n, string f) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void TestMethod(int n, string f) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1037").WithLocation(0).WithArguments("Xunit.TheoryData"); @@ -846,10 +846,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n) {{ }} }} """, member.syntax, member.args, theoryDataType); @@ -867,10 +867,10 @@ public async Task ValidTheoryDataRow_DoesNotTrigger( using Xunit; public class TestClass {{ - public static IEnumerable> TestData{0}new List>(); + public static IEnumerable> TestData{0}new List>(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n) {{ }} }} """, memberSyntax, memberArgs); @@ -890,10 +890,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n, int a = 0) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n, int a = 0) {{ }} }} """, member.syntax, member.args, theoryDataType); @@ -911,10 +911,10 @@ public async Task ValidTheoryDataRowWithOptionalParameters_DoesNotTrigger( using Xunit; public class TestClass {{ - public static TheoryDataRow[] TestData{0}new TheoryDataRow[0]; + public static TheoryDataRow[] TestData{0}new TheoryDataRow[0]; - [MemberData(nameof(TestData){1})] - public void TestMethod(int n, int a = 0) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n, int a = 0) {{ }} }} """, memberSyntax, memberArgs); @@ -934,10 +934,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n, params int[] a) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n, params int[] a) {{ }} }} """, member.syntax, member.args, theoryDataType); @@ -955,10 +955,10 @@ public async Task ValidTheoryDataRowWithNoValuesForParamsArray_DoesNotTrigger( using Xunit; public class TestClass {{ - public static ICollection> TestData{0}new List>(); + public static ICollection> TestData{0}new List>(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n, params int[] a) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n, params int[] a) {{ }} }} """, memberSyntax, memberArgs); @@ -978,10 +978,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n, params int[] a) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n, params int[] a) {{ }} }} """, member.syntax, member.args, theoryDataType); @@ -999,10 +999,10 @@ public async Task ValidTheoryDataRowWithSingleValueForParamsArray_DoesNotTrigger using Xunit; public class TestClass {{ - public static IEnumerable> TestData{0}new List>(); + public static IEnumerable> TestData{0}new List>(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n, params int[] a) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n, params int[] a) {{ }} }} """, memberSyntax, memberArgs); @@ -1022,10 +1022,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [MemberData(nameof(TestData){1})] - public void TestMethod(T n) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(T n) {{ }} }} """, member.syntax, member.args, theoryDataType); @@ -1043,10 +1043,10 @@ public async Task ValidTheoryDataRowWithGenericTestParameter_DoesNotTrigger( using Xunit; public class TestClass {{ - public static ISet> TestData{0}new HashSet>(); + public static ISet> TestData{0}new HashSet>(); - [MemberData(nameof(TestData){1})] - public void TestMethod(T n) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(T n) {{ }} }} """, memberSyntax, memberArgs); @@ -1068,10 +1068,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [Xunit.MemberData(nameof(TestData){1})] - public void TestMethod(T? n) {{ }} + [Xunit.MemberData(nameof(TestData){1})] + public void TestMethod(T? n) {{ }} }} """, member.syntax, member.args, theoryDataType); @@ -1091,10 +1091,10 @@ public async Task ValidTheoryDataRowWithNullableGenericTestParameter_DoesNotTrig using Xunit; public class TestClass {{ - public static IEnumerable> TestData{0}new List>(); + public static IEnumerable> TestData{0}new List>(); - [Xunit.MemberData(nameof(TestData){1})] - public void TestMethod(T? n) {{ }} + [Xunit.MemberData(nameof(TestData){1})] + public void TestMethod(T? n) {{ }} }} """, memberSyntax, memberArgs); @@ -1113,10 +1113,10 @@ public async Task ValidTheoryDataDoubleGenericSubclassMember_DoesNotTrigger( public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static DerivedTheoryData TestData{0}new DerivedTheoryData(); + public static DerivedTheoryData TestData{0}new DerivedTheoryData(); - [MemberData(nameof(TestData){1})] - public void TestMethod(int n) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod(int n) {{ }} }} """, memberSyntax, memberArgs); @@ -1137,8 +1137,8 @@ public class TestClass { [MemberData(nameof(GetSequences), new[] { 1, 2 })] [MemberData(nameof(GetSequences), new[] { 3, 4, 5 })] public void Test(IEnumerable seq) { - Assert.NotEmpty(seq); - } + Assert.NotEmpty(seq); + } } """; @@ -1158,10 +1158,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void TestMethod(int n) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void TestMethod(int n) {{ }} }} """, member.syntax, member.args, theoryDataType); var expected = Verify.Diagnostic("xUnit1038").WithLocation(0).WithArguments("Xunit.TheoryData"); @@ -1180,10 +1180,10 @@ public async Task ValidSubclassTheoryDataRowMemberWithTooManyTypeParameters_Trig using Xunit; public class TestClass {{ - public static IEnumerable> TestData{0}new List>(); + public static IEnumerable> TestData{0}new List>(); - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void TestMethod(int n) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void TestMethod(int n) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1038").WithLocation(0).WithArguments("Xunit.TheoryDataRow"); @@ -1204,10 +1204,10 @@ public class DerivedTheoryData : TheoryData {{ }} public class DerivedTheoryData : TheoryData {{ }} public class TestClass {{ - public static {2} TestData{0}new {2}(); + public static {2} TestData{0}new {2}(); - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void PuzzleOne(int _1, params string[] _2) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void PuzzleOne(int _1, params string[] _2) {{ }} }} """, member.syntax, member.args, theoryDataType); var expected = Verify.Diagnostic("xUnit1038").WithLocation(0).WithArguments("Xunit.TheoryData"); @@ -1226,10 +1226,10 @@ public async Task ExtraTheoryDataRowTypeExistsPastArrayForParamsArray_Triggers( using Xunit; public class TestClass {{ - public static ICollection> TestData{0}new TheoryDataRow[0]; + public static ICollection> TestData{0}new TheoryDataRow[0]; - [{{|#0:MemberData(nameof(TestData){1})|}}] - public void PuzzleOne(int _1, params string[] _2) {{ }} + [{{|#0:MemberData(nameof(TestData){1})|}}] + public void PuzzleOne(int _1, params string[] _2) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1038").WithLocation(0).WithArguments("Xunit.TheoryDataRow"); @@ -1262,8 +1262,8 @@ public async Task WhenPassingMultipleValuesForParamsArray_TheoryData_DoesNotTrig public class TestClass { public static TheoryData TestData = new TheoryData(); - [MemberData(nameof(TestData))] - public void PuzzleOne(int _1, params string[] _2) { } + [MemberData(nameof(TestData))] + public void PuzzleOne(int _1, params string[] _2) { } } """; @@ -1280,8 +1280,8 @@ public async Task WhenPassingMultipleValuesForParamsArray_TheoryDataRow_DoesNotT public class TestClass { public static IEnumerable> TestData = new List>(); - [MemberData(nameof(TestData))] - public void PuzzleOne(int _1, params string[] _2) { } + [MemberData(nameof(TestData))] + public void PuzzleOne(int _1, params string[] _2) { } } """; @@ -1297,8 +1297,8 @@ public async Task WhenPassingArrayForParamsArray_TheoryData_DoesNotTrigger() public class TestClass { public static TheoryData TestData = new TheoryData(); - [MemberData(nameof(TestData))] - public void PuzzleOne(int _1, params string[] _2) { } + [MemberData(nameof(TestData))] + public void PuzzleOne(int _1, params string[] _2) { } } """; @@ -1314,8 +1314,8 @@ public async Task WhenPassingArrayForParamsArray_TheoryDataRow_DoesNotTrigger() public class TestClass { public static TheoryDataRow[] TestData = new TheoryDataRow[0]; - [MemberData(nameof(TestData))] - public void PuzzleOne(int _1, params string[] _2) { } + [MemberData(nameof(TestData))] + public void PuzzleOne(int _1, params string[] _2) { } } """; @@ -1331,8 +1331,8 @@ public async Task WhenPassingTupleWithoutFieldNames_TheoryData_DoesNotTrigger() public class TestClass { public static TheoryData<(int, int)> TestData = new TheoryData<(int, int)>(); - [MemberData(nameof(TestData))] - public void TestMethod((int a, int b) x) { } + [MemberData(nameof(TestData))] + public void TestMethod((int a, int b) x) { } } """; @@ -1349,8 +1349,8 @@ public async Task WhenPassingTupleWithoutFieldNames_TheoryDataRow_DoesNotTrigger public class TestClass { public static IList> TestData = new List>(); - [MemberData(nameof(TestData))] - public void TestMethod((int a, int b) x) { } + [MemberData(nameof(TestData))] + public void TestMethod((int a, int b) x) { } } """; @@ -1366,8 +1366,8 @@ public async Task WhenPassingTupleWithDifferentFieldNames_TheoryData_DoesNotTrig public class TestClass { public static TheoryData<(int c, int d)> TestData = new TheoryData<(int, int)>(); - [MemberData(nameof(TestData))] - public void TestMethod((int a, int b) x) { } + [MemberData(nameof(TestData))] + public void TestMethod((int a, int b) x) { } } """; @@ -1384,8 +1384,8 @@ public async Task WhenPassingTupleWithDifferentFieldNames_TheoryDataRow_DoesNotT public class TestClass { public static IEnumerable> TestData = new List>(); - [MemberData(nameof(TestData))] - public void TestMethod((int a, int b) x) { } + [MemberData(nameof(TestData))] + public void TestMethod((int a, int b) x) { } } """; @@ -1422,8 +1422,8 @@ public async Task WithExtraValueNotCompatibleWithParamsArray_TheoryData_Triggers public class TestClass { public static TheoryData TestData = new TheoryData(); - [MemberData(nameof(TestData))] - public void PuzzleOne(int _1, params {|#0:string[]|} _2) { } + [MemberData(nameof(TestData))] + public void PuzzleOne(int _1, params {|#0:string[]|} _2) { } } """; var expected = Verify.Diagnostic("xUnit1039").WithLocation(0).WithArguments("int", "TestClass.TestData", "_2"); @@ -1441,8 +1441,8 @@ public async Task WithExtraValueNotCompatibleWithParamsArray_TheoryDataRow_Trigg public class TestClass { public static IEnumerable> TestData = new List>(); - [MemberData(nameof(TestData))] - public void PuzzleOne(int _1, params {|#0:string[]|} _2) { } + [MemberData(nameof(TestData))] + public void PuzzleOne(int _1, params {|#0:string[]|} _2) { } } """; var expected = Verify.Diagnostic("xUnit1039").WithLocation(0).WithArguments("int", "TestClass.TestData", "_2"); @@ -1460,10 +1460,10 @@ public async Task ValidTheoryDataMemberWithIncompatibleTypeParameters_Triggers( using Xunit; public class TestClass {{ - public static TheoryData<{2}> TestData{0}new TheoryData<{2}>(); + public static TheoryData<{2}> TestData{0}new TheoryData<{2}>(); - [MemberData(nameof(TestData){1})] - public void TestMethod({{|#0:string|}} f) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod({{|#0:string|}} f) {{ }} }} """, member.syntax, member.args, type); var expected = Verify.Diagnostic("xUnit1039").WithLocation(0).WithArguments(type, "TestClass.TestData", "f"); @@ -1482,10 +1482,10 @@ public async Task ValidTheoryDataRowMemberWithIncompatibleTypeParameters_Trigger using Xunit; public class TestClass {{ - public static IList> TestData{0}new List>(); + public static IList> TestData{0}new List>(); - [MemberData(nameof(TestData){1})] - public void TestMethod({{|#0:string|}} f) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod({{|#0:string|}} f) {{ }} }} """, member.syntax, member.args, type); var expected = Verify.Diagnostic("xUnit1039").WithLocation(0).WithArguments(type, "TestClass.TestData", "f"); @@ -1516,10 +1516,10 @@ public async Task ValidTheoryDataMemberWithMismatchedNullability_Triggers( using Xunit; public class TestClass {{ - public static TheoryData TestData{0}new TheoryData(); + public static TheoryData TestData{0}new TheoryData(); - [MemberData(nameof(TestData){1})] - public void TestMethod({{|#0:string|}} f) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod({{|#0:string|}} f) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1040").WithLocation(0).WithArguments("string?", "TestClass.TestData", "f"); @@ -1540,10 +1540,10 @@ public async Task ValidTheoryDataRowMemberWithMismatchedNullability_Triggers( using Xunit; public class TestClass {{ - public static IEnumerable> TestData{0}new List>(); + public static IEnumerable> TestData{0}new List>(); - [MemberData(nameof(TestData){1})] - public void TestMethod({{|#0:string|}} f) {{ }} + [MemberData(nameof(TestData){1})] + public void TestMethod({{|#0:string|}} f) {{ }} }} """, memberSyntax, memberArgs); var expected = Verify.Diagnostic("xUnit1040").WithLocation(0).WithArguments("string?", "TestClass.TestData", "f"); @@ -1562,10 +1562,10 @@ public async Task TheoryData_DoesNotTrigger() using Xunit; public class TestClass { - public static TheoryData Data; + public static TheoryData Data; - [MemberData(nameof(Data))] - public void TestMethod(int _) { } + [MemberData(nameof(Data))] + public void TestMethod(int _) { } } """; @@ -1580,10 +1580,10 @@ public async Task MatrixTheoryData_DoesNotTrigger() using Xunit; public class TestClass { - public static MatrixTheoryData Data; + public static MatrixTheoryData Data; - [MemberData(nameof(Data))] - public void TestMethod(int _1, string _2) { } + [MemberData(nameof(Data))] + public void TestMethod(int _1, string _2) { } } """; @@ -1603,10 +1603,10 @@ public async Task GenericTheoryDataRow_DoesNotTrigger(string memberType) using Xunit.v3; public class TestClass {{ - public static {0} Data; + public static {0} Data; - [MemberData(nameof(Data))] - public void TestMethod(int _) {{ }} + [MemberData(nameof(Data))] + public void TestMethod(int _) {{ }} }} """, memberType); @@ -1623,10 +1623,10 @@ public async Task ValidTypesWhichAreNotTheoryData_Trigger(string memberType) using Xunit; public class TestClass {{ - public static {0} Data; + public static {0} Data; - [{{|#0:MemberData(nameof(Data))|}}] - public void TestMethod(int _) {{ }} + [{{|#0:MemberData(nameof(Data))|}}] + public void TestMethod(int _) {{ }} }} """, memberType); var expectedV2 = Verify.Diagnostic("xUnit1042").WithLocation(0).WithArguments("TheoryData<>"); @@ -1660,15 +1660,15 @@ public async Task ValidTypesWhichAreNotTheoryDataOrGenericTheoryDataRow_Triggers using Xunit; public class TestClass {{ - public static {0} Data; + public static {0} Data; - [{{|#0:MemberData(nameof(Data))|}}] - public void TestMethod(int _) {{ }} + [{{|#0:MemberData(nameof(Data))|}}] + public void TestMethod(int _) {{ }} }} public class EnumerableOfITheoryDataRow : IEnumerable {{ - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; }} """, memberType); var expected = Verify.Diagnostic("xUnit1042").WithLocation(0).WithArguments("TheoryData<> or IEnumerable>"); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/PublicMethodShouldBeMarkedAsTestTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/PublicMethodShouldBeMarkedAsTestTests.cs index 3fbfa4d1..fea67f43 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/PublicMethodShouldBeMarkedAsTestTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/PublicMethodShouldBeMarkedAsTestTests.cs @@ -9,7 +9,7 @@ public async Task PublicMethodInNonTestClass_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - public void TestMethod() { } + public void TestMethod() { } } """; @@ -23,8 +23,8 @@ public async Task TestMethods_DoesNotTrigger(string attribute) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} }} """, attribute); @@ -36,10 +36,10 @@ public async Task IDisposableDisposeMethod_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass: System.IDisposable { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - public void Dispose() { } + public void Dispose() { } } """; @@ -51,10 +51,10 @@ public async Task PublicAbstractMethod_DoesNotTrigger() { var source = /* lang=c#-test */ """ public abstract class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - public abstract void AbstractMethod(); + public abstract void AbstractMethod(); } """; @@ -66,15 +66,15 @@ public async Task DerivedMethodWithFactOnBaseAbstractMethod_DoesNotTrigger() { var source = /* lang=c#-test */ """ public abstract class BaseClass { - [Xunit.Fact] - public abstract void TestMethod(); + [Xunit.Fact] + public abstract void TestMethod(); } public class TestClass : BaseClass { - public override void TestMethod() { } + public override void TestMethod() { } - [Xunit.Fact] - public void TestMethod2() { } + [Xunit.Fact] + public void TestMethod2() { } } """; @@ -86,11 +86,11 @@ public async Task PublicAbstractMethodMarkedWithFact_DoesNotTrigger() { var source = /* lang=c#-test */ """ public abstract class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - [Xunit.Fact] - public abstract void AbstractMethod(); + [Xunit.Fact] + public abstract void AbstractMethod(); } """; @@ -102,14 +102,14 @@ public async Task IDisposableDisposeMethodOverrideFromParentClass_DoesNotTrigger { var source = /* lang=c#-test */ """ public class BaseClass: System.IDisposable { - public virtual void Dispose() { } + public virtual void Dispose() { } } public class TestClass: BaseClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - public override void Dispose() { } + public override void Dispose() { } } """; @@ -121,14 +121,14 @@ public async Task IDisposableDisposeMethodOverrideFromParentClassWithRepeatedInt { var source = /* lang=c#-test */ """ public class BaseClass: System.IDisposable { - public virtual void Dispose() { } + public virtual void Dispose() { } } public class TestClass: BaseClass, System.IDisposable { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - public override void Dispose() { } + public override void Dispose() { } } """; @@ -140,16 +140,16 @@ public async Task IDisposableDisposeMethodOverrideFromGrandParentClass_DoesNotTr { var source = /* lang=c#-test */ """ public abstract class BaseClass: System.IDisposable { - public abstract void Dispose(); + public abstract void Dispose(); } public abstract class IntermediateClass: BaseClass { } public class TestClass: IntermediateClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - public override void Dispose() { } + public override void Dispose() { } } """; @@ -161,18 +161,18 @@ public async Task IAsyncLifetimeMethods_V2_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass: Xunit.IAsyncLifetime { - [Xunit.Fact] - public void TestMethod() { } - - public System.Threading.Tasks.Task DisposeAsync() - { - throw new System.NotImplementedException(); - } - - public System.Threading.Tasks.Task InitializeAsync() - { - throw new System.NotImplementedException(); - } + [Xunit.Fact] + public void TestMethod() { } + + public System.Threading.Tasks.Task DisposeAsync() + { + throw new System.NotImplementedException(); + } + + public System.Threading.Tasks.Task InitializeAsync() + { + throw new System.NotImplementedException(); + } } """; @@ -184,18 +184,18 @@ public async Task IAsyncLifetimeMethods_V3_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass: Xunit.IAsyncLifetime { - [Xunit.Fact] - public void TestMethod() { } - - public System.Threading.Tasks.ValueTask DisposeAsync() - { - throw new System.NotImplementedException(); - } - - public System.Threading.Tasks.ValueTask InitializeAsync() - { - throw new System.NotImplementedException(); - } + [Xunit.Fact] + public void TestMethod() { } + + public System.Threading.Tasks.ValueTask DisposeAsync() + { + throw new System.NotImplementedException(); + } + + public System.Threading.Tasks.ValueTask InitializeAsync() + { + throw new System.NotImplementedException(); + } } """; @@ -212,11 +212,11 @@ public class IgnoreXunitAnalyzersRule1013Attribute: System.Attribute { } public class CustomTestTypeAttribute: System.Attribute { } public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - [CustomTestType] - public void CustomTestMethod() { } + [CustomTestType] + public void CustomTestMethod() { } } """; @@ -235,11 +235,11 @@ public class BaseCustomTestTypeAttribute: System.Attribute { } public class DerivedCustomTestTypeAttribute: BaseCustomTestTypeAttribute { } public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } - [DerivedCustomTestType] - public void {|#0:CustomTestMethod|}() { } + [DerivedCustomTestType] + public void {|#0:CustomTestMethod|}() { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("CustomTestMethod", "TestClass", "Fact"); @@ -254,10 +254,10 @@ public async Task PublicMethodWithoutParametersInTestClass_Triggers(string attri { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} - public void {{|#0:Method|}}() {{ }} + public void {{|#0:Method|}}() {{ }} }} """, attribute); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Method", "TestClass", "Fact"); @@ -272,10 +272,10 @@ public async Task PublicMethodWithParametersInTestClass_Triggers(string attribut { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} - public void {{|#0:Method|}}(int a) {{ }} + public void {{|#0:Method|}}(int a) {{ }} }} """, attribute); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Method", "TestClass", "Theory"); @@ -292,14 +292,14 @@ public async Task OverridenMethod_FromParentNonTestClass_DoesNotTrigger(string a using Xunit; public abstract class ParentClass {{ - public abstract void ParentMethod(); + public abstract void ParentMethod(); }} public class TestClass : ParentClass {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} - public override void ParentMethod() {{ }} + public override void ParentMethod() {{ }} public override void {{|CS0115:MissingMethod|}}() {{ }} }} diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestClassCannotBeNestedInGenericClassTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestClassCannotBeNestedInGenericClassTests.cs index 00be7a9e..fd80b885 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestClassCannotBeNestedInGenericClassTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestClassCannotBeNestedInGenericClassTests.cs @@ -9,10 +9,10 @@ public async Task WhenTestClassIsNestedInOpenGenericType_Triggers() { var source = /* lang=c#-test */ """ public abstract class OpenGenericType { - public class [|NestedTestClass|] { - [Xunit.Fact] - public void TestMethod() { } - } + public class [|NestedTestClass|] { + [Xunit.Fact] + public void TestMethod() { } + } } """; @@ -24,12 +24,12 @@ public async Task WhenDerivedTestClassIsNestedInOpenGenericType_Triggers() { var source = /* lang=c#-test */ """ public abstract class BaseTestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } public abstract class OpenGenericType { - public class [|NestedTestClass|] : BaseTestClass { } + public class [|NestedTestClass|] : BaseTestClass { } } """; @@ -43,10 +43,10 @@ public async Task WhenTestClassIsNestedInClosedGenericType_DoesNotTrigger() public abstract class OpenGenericType { } public abstract class ClosedGenericType : OpenGenericType { - public class NestedTestClass { - [Xunit.Fact] - public void TestMethod() { } - } + public class NestedTestClass { + [Xunit.Fact] + public void TestMethod() { } + } } """; @@ -58,7 +58,7 @@ public async Task WhenNestedClassIsNotTestClass_DoesNotTrigger() { var source = /* lang=c#-test */ """ public abstract class OpenGenericType { - public class NestedClass { } + public class NestedClass { } } """; @@ -70,10 +70,10 @@ public async Task WhenTestClassIsNotNestedInOpenGenericType_DoesNotTrigger() { var source = /* lang=c#-test */ """ public abstract class NonGenericType { - public class NestedTestClass { - [Xunit.Fact] - public void TestMethod() { } - } + public class NestedTestClass { + [Xunit.Fact] + public void TestMethod() { } + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestClassMustBePublicTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestClassMustBePublicTests.cs index 8f67c1a6..f15de356 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestClassMustBePublicTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestClassMustBePublicTests.cs @@ -15,8 +15,8 @@ public async Task ForPublicClass_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -31,8 +31,8 @@ public async Task ForFriendOrInternalClass_Triggers( { var source = string.Format(/* lang=c#-test */ """ {1} class [|TestClass|] {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} }} """, attribute, modifier); @@ -46,13 +46,13 @@ public async Task ForPartialClassInSameFile_WhenClassIsPublic_DoesNotTrigger(str { var source = string.Format(/* lang=c#-test */ """ public partial class TestClass {{ - [Xunit.Fact] - public void Test1() {{ }} + [Xunit.Fact] + public void Test1() {{ }} }} {0} partial class TestClass {{ - [Xunit.Fact] - public void Test2() {{ }} + [Xunit.Fact] + public void Test2() {{ }} }} """, modifier); @@ -66,14 +66,14 @@ public async Task ForPartialClassInOtherFiles_WhenClassIsPublic_DoesNotTrigger(s { var source1 = /* lang=c#-test */ """ public partial class TestClass { - [Xunit.Fact] - public void Test1() { } + [Xunit.Fact] + public void Test1() { } } """; var source2 = string.Format(/* lang=c#-test */ """ {0} partial class TestClass {{ - [Xunit.Fact] - public void Test2() {{ }} + [Xunit.Fact] + public void Test2() {{ }} }} """, modifier); @@ -90,13 +90,13 @@ public async Task ForPartialClassInSameFile_WhenClassIsNonPublic_Triggers( { var source = string.Format(/* lang=c#-test */ """ {0} partial class {{|#0:TestClass|}} {{ - [Xunit.Fact] - public void Test1() {{ }} + [Xunit.Fact] + public void Test1() {{ }} }} {1} partial class {{|#1:TestClass|}} {{ - [Xunit.Fact] - public void Test2() {{ }} + [Xunit.Fact] + public void Test2() {{ }} }} """, modifier1, modifier2); var expected = Verify.Diagnostic().WithLocation(0).WithLocation(1); @@ -114,14 +114,14 @@ public async Task ForPartialClassInOtherFiles_WhenClassIsNonPublic_Triggers( { var source1 = string.Format(/* lang=c#-test */ """ {0} partial class {{|#0:TestClass|}} {{ - [Xunit.Fact] - public void Test1() {{ }} + [Xunit.Fact] + public void Test1() {{ }} }} """, modifier1); var source2 = string.Format(/* lang=c#-test */ """ {0} partial class {{|#1:TestClass|}} {{ - [Xunit.Fact] - public void Test2() {{ }} + [Xunit.Fact] + public void Test2() {{ }} }} """, modifier2); var expected = Verify.Diagnostic().WithLocation(0).WithLocation(1); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestClassShouldHaveTFixtureArgumentTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestClassShouldHaveTFixtureArgumentTests.cs index 02e3534b..d3156c5a 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestClassShouldHaveTFixtureArgumentTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestClassShouldHaveTFixtureArgumentTests.cs @@ -20,8 +20,8 @@ public async Task ForClassWithIClassFixtureWithoutConstructorArg_Triggers( public class FixtureData {{ }} public class {{|#0:TestClass|}}: {1} {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} }} """, attribute, @interface); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestClass", "FixtureData"); @@ -39,10 +39,10 @@ public async Task ForClassWithIClassFixtureWithConstructorArg_DoesNotTrigger( public class FixtureData {{ }} public class TestClass: {1} {{ - public TestClass(FixtureData fixtureData) {{ }} + public TestClass(FixtureData fixtureData) {{ }} - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} }} """, attribute, @interface); @@ -59,10 +59,10 @@ public async Task ForClassWithIClassFixtureWithConstructorMultipleArg_DoesNotTri public class FixtureData {{ }} public class TestClass: {1} {{ - public TestClass(FixtureData fixtureData, {2}.ITestOutputHelper output) {{ }} + public TestClass(FixtureData fixtureData, {2}.ITestOutputHelper output) {{ }} - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} }} """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodCannotHaveOverloadsTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodCannotHaveOverloadsTests.cs index 88776872..41cf7709 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodCannotHaveOverloadsTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodCannotHaveOverloadsTests.cs @@ -9,11 +9,11 @@ public async Task ForInstanceMethodOverloads_InSameInstanceClass_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void {|#0:TestMethod|}() { } + [Xunit.Fact] + public void {|#0:TestMethod|}() { } - [Xunit.Theory] - public void {|#1:TestMethod|}(int a) { } + [Xunit.Theory] + public void {|#1:TestMethod|}(int a) { } } """; var expected = new[] @@ -30,11 +30,11 @@ public async Task ForStaticMethodOverloads_InSameStaticClass_Triggers() { var source = /* lang=c#-test */ """ public static class TestClass { - [Xunit.Fact] - public static void {|#0:TestMethod|}() { } + [Xunit.Fact] + public static void {|#0:TestMethod|}() { } - [Xunit.Theory] - public static void {|#1:TestMethod|}(int a) { } + [Xunit.Theory] + public static void {|#1:TestMethod|}(int a) { } } """; var expected = new[] @@ -51,16 +51,16 @@ public async Task ForInstanceMethodOverload_InDerivedClass_Triggers() { var source1 = /* lang=c#-test */ """ public class TestClass : BaseClass { - [Xunit.Theory] - public void {|#0:TestMethod|}(int a) { } + [Xunit.Theory] + public void {|#0:TestMethod|}(int a) { } - private void {|#1:TestMethod|}(int a, byte c) { } + private void {|#1:TestMethod|}(int a, byte c) { } } """; var source2 = /* lang=c#-test */ """ public class BaseClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; var expected = new[] @@ -77,14 +77,14 @@ public async Task ForStaticAndInstanceMethodOverload_Triggers() { var source1 = /* lang=c#-test */ """ public class TestClass : BaseClass { - [Xunit.Theory] - public void {|#0:TestMethod|}(int a) { } + [Xunit.Theory] + public void {|#0:TestMethod|}(int a) { } } """; var source2 = /* lang=c#-test */ """ public class BaseClass { - [Xunit.Fact] - public static void TestMethod() { } + [Xunit.Fact] + public static void TestMethod() { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass", "BaseClass"); @@ -97,14 +97,14 @@ public async Task ForMethodOverrides_DoesNotTrigger() { var source1 = /* lang=c#-test */ """ public class BaseClass { - [Xunit.Fact] - public virtual void TestMethod() { } + [Xunit.Fact] + public virtual void TestMethod() { } } """; var source2 = /* lang=c#-test */ """ public class TestClass : BaseClass { - [Xunit.Fact] - public override void TestMethod() { } + [Xunit.Fact] + public override void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodMustNotHaveMultipleFactAttributesTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodMustNotHaveMultipleFactAttributesTests.cs index 03dac6e0..49656d75 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodMustNotHaveMultipleFactAttributesTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodMustNotHaveMultipleFactAttributesTests.cs @@ -11,8 +11,8 @@ public async Task MethodWithSingleAttribute_DoesNotTrigger(string attribute) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.{0}] + public void TestMethod() {{ }} }} """, attribute); @@ -24,9 +24,9 @@ public async Task MethodWithFactAndTheory_Triggers() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [Xunit.Theory] - public void [|TestMethod|]() { } + [Xunit.Fact] + [Xunit.Theory] + public void [|TestMethod|]() { } } """; @@ -38,9 +38,9 @@ public async Task MethodWithFactAndCustomFactAttribute_Triggers() { var source1 = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - [CustomFact] - public void [|TestMethod|]() { } + [Xunit.Fact] + [CustomFact] + public void [|TestMethod|]() { } } """; var source2 = /* lang=c#-test */ """ diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodShouldNotBeSkippedTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodShouldNotBeSkippedTests.cs index f2387d6c..7aaad468 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodShouldNotBeSkippedTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodShouldNotBeSkippedTests.cs @@ -11,8 +11,8 @@ public async Task NotSkippedTest_DoesNotTrigger(string attribute) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.{0}] + public void TestMethod() {{ }} }} """, attribute); @@ -26,8 +26,8 @@ public async Task SkippedTest_Triggers(string attribute) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - [Xunit.{0}([|Skip="Lazy"|])] - public void TestMethod() {{ }} + [Xunit.{0}([|Skip="Lazy"|])] + public void TestMethod() {{ }} }} """, attribute); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodSupportedReturnTypeTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodSupportedReturnTypeTests.cs index aab31bce..b58aedd4 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodSupportedReturnTypeTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TestMethodSupportedReturnTypeTests.cs @@ -10,9 +10,9 @@ public async Task NonTestMethod_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class NonTestClass { - public int Add(int x, int y) { - return x + y; - } + public int Add(int x, int y) { + return x + y; + } } """; @@ -30,9 +30,9 @@ public async Task InvalidReturnType_Triggers(string returnType) using Xunit; public class TestClass {{ - [Fact] - public {0} {{|#0:TestMethod|}}() {{ - return default({0}); + [Fact] + public {0} {{|#0:TestMethod|}}() {{ + return default({0}); }} }} """, returnType); @@ -51,10 +51,10 @@ public async Task ValueTask_TriggersInV2_DoesNotTriggerInV3() using Xunit; public class TestClass { - [Fact] - public ValueTask {|#0:TestMethod|}() { - return default(ValueTask); - } + [Fact] + public ValueTask {|#0:TestMethod|}() { + return default(ValueTask); + } } """; var expectedV2 = Verify.Diagnostic().WithLocation(0).WithArguments("void, Task"); @@ -74,9 +74,9 @@ public async Task CustomTestAttribute_DoesNotTrigger(string attribute) class MyTestAttribute : FactAttribute {{ }} public class TestClass {{ - [{0}] - public int TestMethod() {{ - return 0; + [{0}] + public int TestMethod() {{ + return 0; }} }} """, attribute); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataRowArgumentsShouldBeSerializableTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataRowArgumentsShouldBeSerializableTests.cs index 02fee09b..6f6c9d0e 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataRowArgumentsShouldBeSerializableTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataRowArgumentsShouldBeSerializableTests.cs @@ -12,13 +12,13 @@ public async Task ParamArrayArguments_NotUsingTheoryDataRow_DoesNotTrigger() #nullable enable public class Foo { - public Foo(params object[] args) { } + public Foo(params object[] args) { } } public class TestClass { - public void TestMethod() { - var foo = new Foo(new object()); - } + public void TestMethod() { + var foo = new Foo(new object()); + } } """; @@ -64,15 +64,15 @@ public async Task IntrinsicallySerializableValue_DoesNotTrigger( using Xunit; public class MyClass {{ - public IEnumerable MyMethod() {{ - var value = {0}; - var defaultValue = default({1}); - var nullValue = default({1}?); - var arrayValue = new {1}[0]; - - yield return new TheoryDataRow(value, defaultValue, nullValue, arrayValue); - yield return new TheoryDataRow<{1}, {1}?, {1}?, {1}[]>({0}, default({1}), default({1}?), new {1}[0]); - }} + public IEnumerable MyMethod() {{ + var value = {0}; + var defaultValue = default({1}); + var nullValue = default({1}?); + var arrayValue = new {1}[0]; + + yield return new TheoryDataRow(value, defaultValue, nullValue, arrayValue); + yield return new TheoryDataRow<{1}, {1}?, {1}?, {1}[]>({0}, default({1}), default({1}?), new {1}[0]); + }} }} """, value, type); @@ -92,27 +92,27 @@ public async Task IXunitSerializableValue_DoesNotTrigger(string type) using Xunit.Sdk; public class MyClass {{ - public IEnumerable MyMethod() {{ - var value = new {0}(); - var defaultValue = default({0}); - var nullValue = default({0}?); - var arrayValue = new {0}[0]; - - yield return new TheoryDataRow(value, defaultValue, nullValue, arrayValue); - yield return new TheoryDataRow<{0}, {0}?, {0}?, {0}[]>(new {0}(), default({0}), default({0}?), new {0}[0]); - }} + public IEnumerable MyMethod() {{ + var value = new {0}(); + var defaultValue = default({0}); + var nullValue = default({0}?); + var arrayValue = new {0}[0]; + + yield return new TheoryDataRow(value, defaultValue, nullValue, arrayValue); + yield return new TheoryDataRow<{0}, {0}?, {0}?, {0}[]>(new {0}(), default({0}), default({0}?), new {0}[0]); + }} }} public interface ISerializableInterface : IXunitSerializable {{ }} public class SerializableClass : ISerializableInterface {{ - public void Deserialize(IXunitSerializationInfo info) {{ }} - public void Serialize(IXunitSerializationInfo info) {{ }} + public void Deserialize(IXunitSerializationInfo info) {{ }} + public void Serialize(IXunitSerializationInfo info) {{ }} }} public struct SerializableStruct : ISerializableInterface {{ - public void Deserialize(IXunitSerializationInfo info) {{ }} - public void Serialize(IXunitSerializationInfo info) {{ }} + public void Deserialize(IXunitSerializationInfo info) {{ }} + public void Serialize(IXunitSerializationInfo info) {{ }} }} """, type); @@ -135,15 +135,15 @@ public async Task IXunitSerializerValue_DoesNotTrigger(string type) [assembly: RegisterXunitSerializer(typeof(CustomSerializer), typeof(ICustomSerialized))] public class MyClass {{ - public IEnumerable MyMethod() {{ - var value = new {0}(); - var defaultValue = default({0}); - var nullValue = default({0}?); - var arrayValue = new {0}[0]; - - yield return new TheoryDataRow(value, defaultValue, nullValue, arrayValue); - yield return new TheoryDataRow<{0}, {0}?, {0}?, {0}[]>(new {0}(), default({0}), default({0}?), new {0}[0]); - }} + public IEnumerable MyMethod() {{ + var value = new {0}(); + var defaultValue = default({0}); + var nullValue = default({0}?); + var arrayValue = new {0}[0]; + + yield return new TheoryDataRow(value, defaultValue, nullValue, arrayValue); + yield return new TheoryDataRow<{0}, {0}?, {0}?, {0}[]>(new {0}(), default({0}), default({0}?), new {0}[0]); + }} }} public interface ICustomSerialized {{ }} @@ -153,14 +153,14 @@ public class CustomSerialized : ICustomSerialized {{ }} public class CustomSerializedDerived : CustomSerialized {{ }} public class CustomSerializer : IXunitSerializer {{ - public object Deserialize(Type type, string serializedValue) => - throw new NotImplementedException(); + public object Deserialize(Type type, string serializedValue) => + throw new NotImplementedException(); - public bool IsSerializable(Type type, object? value) => - true; + public bool IsSerializable(Type type, object? value) => + true; - public string Serialize(object value) => - throw new NotImplementedException(); + public string Serialize(object value) => + throw new NotImplementedException(); }} """, type); @@ -185,14 +185,14 @@ public async Task KnownNonSerializableValue_Triggers1046( using Xunit; public class MyClass {{ - public IEnumerable MyMethod() {{ - var defaultValue = default({0}); - var nullValue = default({0}?); - var arrayValue = new {0}[0]; - - yield return new TheoryDataRow({{|#0:defaultValue|}}, {{|#1:nullValue|}}, {{|#2:arrayValue|}}); - yield return new TheoryDataRow<{1}, {2}, {0}[]>({{|#3:default({0})|}}, {{|#4:default({0}?)|}}, {{|#5:new {0}[0]|}}); - }} + public IEnumerable MyMethod() {{ + var defaultValue = default({0}); + var nullValue = default({0}?); + var arrayValue = new {0}[0]; + + yield return new TheoryDataRow({{|#0:defaultValue|}}, {{|#1:nullValue|}}, {{|#2:arrayValue|}}); + yield return new TheoryDataRow<{1}, {2}, {0}[]>({{|#3:default({0})|}}, {{|#4:default({0}?)|}}, {{|#5:new {0}[0]|}}); + }} }} public sealed class NonSerializableSealedClass {{ }} @@ -223,14 +223,14 @@ public async Task KnownNonSerializableValue_Constructable_Triggers1046(string ty using Xunit; public class MyClass {{ - public IEnumerable MyMethod() {{ - var value = new {0}(); - - yield return new TheoryDataRow({{|#0:value|}}); - yield return new TheoryDataRow({{|#1:new {0}()|}}); - yield return new TheoryDataRow<{0}>({{|#2:value|}}); - yield return new TheoryDataRow<{0}>({{|#3:new {0}()|}}); - }} + public IEnumerable MyMethod() {{ + var value = new {0}(); + + yield return new TheoryDataRow({{|#0:value|}}); + yield return new TheoryDataRow({{|#1:new {0}()|}}); + yield return new TheoryDataRow<{0}>({{|#2:value|}}); + yield return new TheoryDataRow<{0}>({{|#3:new {0}()|}}); + }} }} public sealed class NonSerializableSealedClass {{ }} @@ -267,14 +267,14 @@ public async Task MaybeNonSerializableValue_Triggers1047(string type) using Xunit; public class MyClass {{ - public IEnumerable MyMethod() {{ - var defaultValue = default({0}); - var nullValue = default({0}?); - var arrayValue = new {0}[0]; - - yield return new TheoryDataRow({{|#0:defaultValue|}}, {{|#1:nullValue|}}, {{|#2:arrayValue|}}); - yield return new TheoryDataRow<{0}, {0}, {0}[]>({{|#3:default({0})|}}, {{|#4:default({0}?)|}}, {{|#5:new {0}[0]|}}); - }} + public IEnumerable MyMethod() {{ + var defaultValue = default({0}); + var nullValue = default({0}?); + var arrayValue = new {0}[0]; + + yield return new TheoryDataRow({{|#0:defaultValue|}}, {{|#1:nullValue|}}, {{|#2:arrayValue|}}); + yield return new TheoryDataRow<{0}, {0}, {0}[]>({{|#3:default({0})|}}, {{|#4:default({0}?)|}}, {{|#5:new {0}[0]|}}); + }} }} public interface IPossiblySerializableInterface {{ }} @@ -306,14 +306,14 @@ public async Task MaybeNonSerializableValue_Constructable_Triggers1047(string ty using Xunit; public class MyClass {{ - public IEnumerable MyMethod() {{ - var value = new {0}(); - - yield return new TheoryDataRow({{|#0:value|}}); - yield return new TheoryDataRow({{|#1:new {0}()|}}); - yield return new TheoryDataRow<{0}>({{|#2:value|}}); - yield return new TheoryDataRow<{0}>({{|#3:new {0}()|}}); - }} + public IEnumerable MyMethod() {{ + var value = new {0}(); + + yield return new TheoryDataRow({{|#0:value|}}); + yield return new TheoryDataRow({{|#1:new {0}()|}}); + yield return new TheoryDataRow<{0}>({{|#2:value|}}); + yield return new TheoryDataRow<{0}>({{|#3:new {0}()|}}); + }} }} public class PossiblySerializableUnsealedClass {{ }} diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataTypeArgumentsShouldBeSerializableTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataTypeArgumentsShouldBeSerializableTests.cs index fdd77a61..0d19ad0e 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataTypeArgumentsShouldBeSerializableTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryDataTypeArgumentsShouldBeSerializableTests.cs @@ -22,9 +22,9 @@ public static TheoryData TheoryDataClass( using Xunit; public class TestClass {{ - [{0}] - [ClassData(typeof(DerivedClass))] - public void TestMethod({1} a, {2} b, {3} c) {{ }} + [{0}] + [ClassData(typeof(DerivedClass))] + public void TestMethod({1} a, {2} b, {3} c) {{ }} }} public class BaseClass : TheoryData {{ }} @@ -75,7 +75,7 @@ public async Task GivenMethodWithoutAttributes_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - public void TestMethod() { } + public void TestMethod() { } } """; @@ -87,8 +87,8 @@ public async Task GivenFact_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -105,18 +105,18 @@ public async Task GivenTheory_WithoutTheoryDataAsDataSource_DoesNotTrigger() using Xunit; public class TestClass { - public static IEnumerable Property1 => Array.Empty(); - public static DataSource Property2 => new DataSource(); + public static IEnumerable Property1 => Array.Empty(); + public static DataSource Property2 => new DataSource(); - [Theory] - [MemberData(nameof(Property1))] - [MemberData(nameof(Property2))] - public void TestMethod(object a, object b) { } + [Theory] + [MemberData(nameof(Property1))] + [MemberData(nameof(Property2))] + public void TestMethod(object a, object b) { } } public class DataSource : IEnumerable { - public IEnumerator GetEnumerator() { yield break; } - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + public IEnumerator GetEnumerator() { yield break; } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } """; @@ -192,11 +192,11 @@ public async Task GivenTheory_WithSerializableTheoryDataMember_DoesNotTrigger( using Xunit; public class TestClass {{ - {0} + {0} - [Theory] - [{1}] - public void TestMethod({2} parameter) {{ }} + [Theory] + [{1}] + public void TestMethod({2} parameter) {{ }} }} public enum SerializableEnumeration {{ Zero }} @@ -233,23 +233,23 @@ string GetSource(string ns) => using {3}; public class TestClass {{ - {0} + {0} - [Theory] - [{1}] - public void TestMethod({2} parameter) {{ }} + [Theory] + [{1}] + public void TestMethod({2} parameter) {{ }} }} public interface ISerializableInterface : IXunitSerializable {{ }} public class SerializableClass : ISerializableInterface {{ - public void Deserialize(IXunitSerializationInfo info) {{ }} - public void Serialize(IXunitSerializationInfo info) {{ }} + public void Deserialize(IXunitSerializationInfo info) {{ }} + public void Serialize(IXunitSerializationInfo info) {{ }} }} public struct SerializableStruct : ISerializableInterface {{ - public void Deserialize(IXunitSerializationInfo info) {{ }} - public void Serialize(IXunitSerializationInfo info) {{ }} + public void Deserialize(IXunitSerializationInfo info) {{ }} + public void Serialize(IXunitSerializationInfo info) {{ }} }} """, member, attribute, type, ns); } @@ -271,11 +271,11 @@ public async Task GivenTheory_WithIXunitSerializerTheoryDataMember_DoesNotTrigge [assembly: RegisterXunitSerializer(typeof(CustomSerializer), typeof(ICustomSerialized))] public class TestClass {{ - {0} + {0} - [Theory] - [{1}] - public void TestMethod({2} parameter) {{ }} + [Theory] + [{1}] + public void TestMethod({2} parameter) {{ }} }} public interface ICustomSerialized {{ }} @@ -285,14 +285,14 @@ public class CustomSerialized : ICustomSerialized {{ }} public class CustomSerializedDerived : CustomSerialized {{ }} public class CustomSerializer : IXunitSerializer {{ - public object Deserialize(Type type, string serializedValue) => - throw new NotImplementedException(); + public object Deserialize(Type type, string serializedValue) => + throw new NotImplementedException(); - public bool IsSerializable(Type type, object? value) => - true; + public bool IsSerializable(Type type, object? value) => + true; - public string Serialize(object value) => - throw new NotImplementedException(); + public string Serialize(object value) => + throw new NotImplementedException(); }} """, member, attribute, type ); @@ -319,11 +319,11 @@ public async Task GivenTheory_WithNonSerializableTheoryDataMember_WithDiscoveryE using Xunit; public class TestClass {{ - {0} + {0} - [Theory(DisableDiscoveryEnumeration = true)] - [{1}] - public void TestMethod({2} parameter) {{ }} + [Theory(DisableDiscoveryEnumeration = true)] + [{1}] + public void TestMethod({2} parameter) {{ }} }} public sealed class NonSerializableSealedClass {{ }} @@ -357,11 +357,11 @@ public async Task GivenTheory_WithNonSerializableTheoryDataMember_WithDiscoveryE using Xunit; public class TestClass {{ - {0} + {0} - [Theory] - [{1}] - public void TestMethod({2} parameter) {{ }} + [Theory] + [{1}] + public void TestMethod({2} parameter) {{ }} }} public sealed class NonSerializableSealedClass {{ }} @@ -424,11 +424,11 @@ public async Task GivenTheory_WithNonSerializableTheoryDataMember_Triggers( using Xunit; public class TestClass {{ - {0} + {0} - [Theory] - [{{|#0:{1}|}}] - public void TestMethod({2} parameter) {{ }} + [Theory] + [{{|#0:{1}|}}] + public void TestMethod({2} parameter) {{ }} }} public sealed class NonSerializableSealedClass {{ }} @@ -449,9 +449,9 @@ public async Task GivenTheory_WithNonSerializableTheoryDataClass_Triggers( string type3) { var expected = new[] { - Verify.Diagnostic("xUnit1044").WithSpan(6, 6, 6, 37).WithArguments(type1), - Verify.Diagnostic("xUnit1044").WithSpan(6, 6, 6, 37).WithArguments(type2), - Verify.Diagnostic("xUnit1044").WithSpan(6, 6, 6, 37).WithArguments(type3), + Verify.Diagnostic("xUnit1044").WithSpan(6, 3, 6, 34).WithArguments(type1), + Verify.Diagnostic("xUnit1044").WithSpan(6, 3, 6, 34).WithArguments(type2), + Verify.Diagnostic("xUnit1044").WithSpan(6, 3, 6, 34).WithArguments(type3), }; await Verify.VerifyAnalyzer(source, expected); @@ -489,11 +489,11 @@ public async Task GivenTheory_WithPossiblySerializableTheoryDataMember_Triggers( using Xunit; public class TestClass {{ - {0} + {0} - [Theory] - [{{|#0:{1}|}}] - public void TestMethod({2} parameter) {{ }} + [Theory] + [{{|#0:{1}|}}] + public void TestMethod({2} parameter) {{ }} }} public interface IPossiblySerializableInterface {{ }} @@ -514,9 +514,9 @@ public async Task GivenTheory_WithPossiblySerializableTheoryDataClass_Triggers( string type3) { var expected = new[] { - Verify.Diagnostic("xUnit1045").WithSpan(6, 6, 6, 37).WithArguments(type1), - Verify.Diagnostic("xUnit1045").WithSpan(6, 6, 6, 37).WithArguments(type2), - Verify.Diagnostic("xUnit1045").WithSpan(6, 6, 6, 37).WithArguments(type3), + Verify.Diagnostic("xUnit1045").WithSpan(6, 3, 6, 34).WithArguments(type1), + Verify.Diagnostic("xUnit1045").WithSpan(6, 3, 6, 34).WithArguments(type2), + Verify.Diagnostic("xUnit1045").WithSpan(6, 3, 6, 34).WithArguments(type3), }; await Verify.VerifyAnalyzer(source, expected); diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveDefaultParameterTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveDefaultParameterTests.cs index 6c67e4c0..bc270928 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveDefaultParameterTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveDefaultParameterTests.cs @@ -13,8 +13,8 @@ public async Task TheoryWithDefaultParameter_WhenDefaultValueNotSupported_Trigge { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void TestMethod(int a, string b, string c {|#0:= ""|}) { } + [Xunit.Theory] + public void TestMethod(int a, string b, string c {|#0:= ""|}) { } } """; var expected = Verify_v2_Pre220.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass", "c"); @@ -27,8 +27,8 @@ public async Task TheoryWithDefaultParameter_WhenDefaultValueSupported_DoesNotTr { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void TestMethod(int a, string b, string c = "") { } + [Xunit.Theory] + public void TestMethod(int a, string b, string c = "") { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveParamsArrayTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveParamsArrayTests.cs index 4d31c8dd..9f9a300b 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveParamsArrayTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodCannotHaveParamsArrayTests.cs @@ -13,8 +13,8 @@ public async Task TheoryWithParamsArrayAsync_WhenParamsArrayNotSupported_DoesNot { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void TestMethod(int a, string b, {|#0:params string[] c|}) { } + [Xunit.Theory] + public void TestMethod(int a, string b, {|#0:params string[] c|}) { } } """; var expected = Verify_v2_Pre220.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass", "c"); @@ -27,8 +27,8 @@ public async Task TheoryWithParamsArrayAsync_WhenParamsArraySupported_DoesNotTri { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void TestMethod(int a, string b, params string[] c) { } + [Xunit.Theory] + public void TestMethod(int a, string b, params string[] c) { } } """; @@ -40,8 +40,8 @@ public async Task TheoryWithNonParamsArrayAsync_WhenParamsArrayNotSupported_Does { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void TestMethod(int a, string b, string[] c) { } + [Xunit.Theory] + public void TestMethod(int a, string b, string[] c) { } } """; @@ -53,8 +53,8 @@ public async Task TheoryWithNonParamsArrayAsync_WhenParamsArraySupported_DoesNot { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void TestMethod(int a, string b, string[] c) { } + [Xunit.Theory] + public void TestMethod(int a, string b, string[] c) { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodMustHaveTestDataTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodMustHaveTestDataTests.cs index 3e895a48..e9b64a3b 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodMustHaveTestDataTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodMustHaveTestDataTests.cs @@ -9,8 +9,8 @@ public async Task FactMethod_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -25,9 +25,9 @@ public async Task TheoryMethodWithDataAttributes_DoesNotTrigger(string dataAttri { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - [Xunit.Theory] - [Xunit.{0}] - public void TestMethod() {{ }} + [Xunit.Theory] + [Xunit.{0}] + public void TestMethod() {{ }} }} """, dataAttribute); @@ -39,8 +39,8 @@ public async Task TheoryMethodMissingData_Triggers() { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void [|TestMethod|]() { } + [Xunit.Theory] + public void [|TestMethod|]() { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldHaveParametersTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldHaveParametersTests.cs index 4e3777a2..99e386f1 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldHaveParametersTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldHaveParametersTests.cs @@ -9,8 +9,8 @@ public async Task FactMethod_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -22,8 +22,8 @@ public async Task TheoryMethodWithParameters_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Theory] - public void TestMethod(string s) { } + [Xunit.Theory] + public void TestMethod(string s) { } } """; @@ -35,8 +35,8 @@ public async Task TheoryMethodWithoutParameters_Triggers() { var source = /* lang=c#-test */ """ class TestClass { - [Xunit.Theory] - public void [|TestMethod|]() { } + [Xunit.Theory] + public void [|TestMethod|]() { } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldUseAllParametersTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldUseAllParametersTests.cs index 8b6fbaa3..f6796a8d 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldUseAllParametersTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/TheoryMethodShouldUseAllParametersTests.cs @@ -11,8 +11,8 @@ public async Task ParameterNotReferenced_Triggers() using Xunit; class TestClass { - [Theory] - void TestMethod(int {|#0:unused|}) { } + [Theory] + void TestMethod(int {|#0:unused|}) { } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass", "unused"); @@ -28,11 +28,11 @@ public async Task ParameterUnread_Triggers() using Xunit; class TestClass { - [Theory] - void TestMethod(int {|#0:unused|}) { - unused = 3; - int.TryParse("123", out unused); - } + [Theory] + void TestMethod(int {|#0:unused|}) { + unused = 3; + int.TryParse("123", out unused); + } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass", "unused"); @@ -47,8 +47,8 @@ public async Task MultipleUnreadParameters_Triggers() using Xunit; class TestClass { - [Theory] - void TestMethod(int {|#0:foo|}, int {|#1:bar|}, int {|#2:baz|}) { } + [Theory] + void TestMethod(int {|#0:foo|}, int {|#1:bar|}, int {|#2:baz|}) { } } """; var expected = new[] @@ -69,11 +69,11 @@ public async Task SomeUnreadParameters_Triggers() using Xunit; class TestClass { - [Theory] - void TestMethod(int {|#0:foo|}, int bar, int {|#1:baz|}) { - Console.WriteLine(bar); - baz = 3; - } + [Theory] + void TestMethod(int {|#0:foo|}, int bar, int {|#1:baz|}) { + Console.WriteLine(bar); + baz = 3; + } } """; var expected = new[] @@ -92,8 +92,8 @@ public async Task ExpressionBodiedMethod_Triggers() using Xunit; class TestClass { - [Theory] - void TestMethod(int {|#0:unused|}) => Assert.Equal(5, 2 + 2); + [Theory] + void TestMethod(int {|#0:unused|}) => Assert.Equal(5, 2 + 2); } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("TestMethod", "TestClass", "unused"); @@ -109,10 +109,10 @@ public async Task ParameterRead_DoesNotTrigger() using Xunit; class TestClass { - [Theory] - void TestMethod(int used) { - Console.WriteLine(used); - } + [Theory] + void TestMethod(int used) { + Console.WriteLine(used); + } } """; @@ -127,13 +127,13 @@ public async Task ParameterCapturedAsOutParameterInMockSetup_DoesNotTrigger() using Xunit; class TestClass { - [Theory] - void TestMethod(string used, int usedOut) { - // mimicking mock setup use case - // var mock = new Mock(); - // mock.Setup(m => m.SomeMethod(out used)); - Action setup = () => int.TryParse(used, out usedOut); - } + [Theory] + void TestMethod(string used, int usedOut) { + // mimicking mock setup use case + // var mock = new Mock(); + // mock.Setup(m => m.SomeMethod(out used)); + Action setup = () => int.TryParse(used, out usedOut); + } } """; @@ -147,8 +147,8 @@ public async Task ExpressionBodiedMethod_DoesNotTrigger() using Xunit; class TestClass { - [Theory] - void TestMethod(int used) => Assert.Equal(used, 2 + 2); + [Theory] + void TestMethod(int used) => Assert.Equal(used, 2 + 2); } """; @@ -163,11 +163,11 @@ public async Task WhenParameterIsDiscardNamed_DoesNotTrigger() using Xunit; class TestClass { - [Theory] - void TestMethod(int used, string _, object _1, DateTime _42, double {|#0:_a|}) - { - Assert.Equal(42, used); - } + [Theory] + void TestMethod(int used, string _, object _1, DateTime _42, double {|#0:_a|}) + { + Assert.Equal(42, used); + } } """; // Only a single warning, for _a; everything else is either used or matches the discard pattern @@ -183,8 +183,8 @@ public async Task DoesNotCrash_MethodWithoutBody() using Xunit; class TestClass { - [Theory] - extern void TestMethod(int foo); + [Theory] + extern void TestMethod(int foo); } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X1000/UseCancellationTokenTests.cs b/src/xunit.analyzers.tests/Analyzers/X1000/UseCancellationTokenTests.cs index 7e1b2cb2..b541155c 100644 --- a/src/xunit.analyzers.tests/Analyzers/X1000/UseCancellationTokenTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X1000/UseCancellationTokenTests.cs @@ -13,10 +13,10 @@ public async Task NoCancellationToken_DoesNotTrigger() using Xunit; class TestClass { - [Fact] - public void TestMethod() { - Thread.Sleep(1); - } + [Fact] + public void TestMethod() { + Thread.Sleep(1); + } } """; @@ -32,9 +32,9 @@ public async Task NonTestMethod_DoesNotTrigger() using Xunit; class TestClass { - public async Task NonTestMethod() { - await Task.Delay(1); - } + public async Task NonTestMethod() { + await Task.Delay(1); + } } """; @@ -52,14 +52,14 @@ public async Task WithAnyCancellationToken_DoesNotTrigger(string token) using Xunit; class TestClass {{ - [Fact] - public void TestMethod() {{ - FunctionWithDefaults(42, {0}); - FunctionWithDefaults(42, cancellationToken: {0}); - FunctionWithDefaults(cancellationToken: {0}); - }} - - void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default(CancellationToken)) {{ }} + [Fact] + public void TestMethod() {{ + FunctionWithDefaults(42, {0}); + FunctionWithDefaults(42, cancellationToken: {0}); + FunctionWithDefaults(cancellationToken: {0}); + }} + + void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default(CancellationToken)) {{ }} }} """, token); @@ -75,10 +75,10 @@ public async Task WithoutCancellationToken_V2_DoesNotTrigger() using Xunit; class TestClass { - [Fact] - public async Task TestMethod() { - await Task.Delay(1); - } + [Fact] + public async Task TestMethod() { + await Task.Delay(1); + } } """; @@ -94,13 +94,13 @@ public async Task WithoutCancellationToken_WithoutDirectUpgrade_DoesNotTrigger() using Xunit; class TestClass { - [Fact] - public void TestMethod() { - FunctionWithOverload(42); - } + [Fact] + public void TestMethod() { + FunctionWithOverload(42); + } - void FunctionWithOverload(int _) { } - void FunctionWithOverload(CancellationToken _) { } + void FunctionWithOverload(int _) { } + void FunctionWithOverload(CancellationToken _) { } } """; @@ -125,15 +125,15 @@ public async Task WithoutCancellationToken_V3_Triggers(string invocation) using Xunit; class TestClass {{ - [Fact] - public void TestMethod() {{ - [|{0}|]; - }} + [Fact] + public void TestMethod() {{ + [|{0}|]; + }} - void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default) {{ }} + void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default) {{ }} - void FunctionWithOverload(int _) {{ }} - void FunctionWithOverload(int _1, CancellationToken _2) {{ }} + void FunctionWithOverload(int _) {{ }} + void FunctionWithOverload(int _1, CancellationToken _2) {{ }} }} """, invocation); @@ -150,13 +150,13 @@ public async Task InsideLambda_Triggers() using Xunit; class TestClass { - [Fact] - public void TestMethod() { - async Task InnerMethod() { - await [|Task.Delay(1)|]; - } - Func _ = async () => await [|Task.Delay(1)|]; - } + [Fact] + public void TestMethod() { + async Task InnerMethod() { + await [|Task.Delay(1)|]; + } + Func _ = async () => await [|Task.Delay(1)|]; + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertCollectionContainsShouldNotUseBoolCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertCollectionContainsShouldNotUseBoolCheckTests.cs index b450dff6..473c0b68 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertCollectionContainsShouldNotUseBoolCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertCollectionContainsShouldNotUseBoolCheckTests.cs @@ -23,9 +23,9 @@ public async Task TrueCollectionContainsCheck_Triggers(string collection) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.True({0}.Contains(1))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.True({0}.Contains(1))|}}; + }} }} """, collection); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.Contains); @@ -39,9 +39,9 @@ public async Task FalseCollectionContainsCheck_Triggers(string collection) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.False({0}.Contains(1))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.False({0}.Contains(1))|}}; + }} }} """, collection); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.False()", Constants.Asserts.DoesNotContain); @@ -57,9 +57,9 @@ public async Task TrueLinqContainsCheck_Triggers(string enumerable) using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.True({0}.Contains(1))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.True({0}.Contains(1))|}}; + }} }} """, enumerable); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.Contains); @@ -75,9 +75,9 @@ public async Task TrueLinqContainsCheckWithEqualityComparer_Triggers(string enum using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.True({0}.Contains(1, System.Collections.Generic.EqualityComparer.Default))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.True({0}.Contains(1, System.Collections.Generic.EqualityComparer.Default))|}}; + }} }} """, enumerable); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.Contains); @@ -93,9 +93,9 @@ public async Task FalseLinqContainsCheck_Triggers(string enumerable) using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.False({0}.Contains(1))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.False({0}.Contains(1))|}}; + }} }} """, enumerable); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.False()", Constants.Asserts.DoesNotContain); @@ -111,9 +111,9 @@ public async Task FalseLinqContainsCheckWithEqualityComparer_Triggers(string enu using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.False({0}.Contains(1, System.Collections.Generic.EqualityComparer.Default))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.False({0}.Contains(1, System.Collections.Generic.EqualityComparer.Default))|}}; + }} }} """, enumerable); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.False()", Constants.Asserts.DoesNotContain); @@ -127,9 +127,9 @@ public async Task TrueCollectionContainsCheckWithAssertionMessage_DoesNotTrigger { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.True({0}.Contains(1), "Custom message"); - }} + void TestMethod() {{ + Xunit.Assert.True({0}.Contains(1), "Custom message"); + }} }} """, collection); @@ -142,9 +142,9 @@ public async Task FalseCollectionContainsCheckWithAssertionMessage_DoesNotTrigge { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.False({0}.Contains(1), "Custom message"); - }} + void TestMethod() {{ + Xunit.Assert.False({0}.Contains(1), "Custom message"); + }} }} """, collection); @@ -159,9 +159,9 @@ public async Task TrueLinqContainsCheckWithAssertionMessage_DoesNotTrigger(strin using System.Linq; class TestClass {{ - void TestMethod() {{ - Xunit.Assert.True({0}.Contains(1), "Custom message"); - }} + void TestMethod() {{ + Xunit.Assert.True({0}.Contains(1), "Custom message"); + }} }} """, enumerable); @@ -176,9 +176,9 @@ public async Task FalseLinqContainsCheckWithAssertionMessage_DoesNotTrigger(stri using System.Linq; class TestClass {{ - void TestMethod() {{ - Xunit.Assert.False({0}.Contains(1), "Custom message"); - }} + void TestMethod() {{ + Xunit.Assert.False({0}.Contains(1), "Custom message"); + }} }} """, enumerable); @@ -194,9 +194,9 @@ public async Task CollectionWithDifferentTypeParametersThanICollectionImplementa class IntList : List { } class TestClass { - void TestMethod() { - [|Xunit.Assert.False(new IntList().Contains(1))|]; - } + void TestMethod() { + [|Xunit.Assert.False(new IntList().Contains(1))|]; + } } """; @@ -210,9 +210,9 @@ public async Task CollectionWithDifferentTypeParametersThanICollectionImplementa using System.Collections.Generic; class TestClass { - void TestMethod() { - Xunit.Assert.False(new Dictionary().ContainsKey(1)); - } + void TestMethod() { + Xunit.Assert.False(new Dictionary().ContainsKey(1)); + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyCollectionCheckShouldNotBeUsedTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyCollectionCheckShouldNotBeUsedTests.cs index 7e45adec..ff802580 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyCollectionCheckShouldNotBeUsedTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyCollectionCheckShouldNotBeUsedTests.cs @@ -22,10 +22,10 @@ public async Task CollectionCheckWithoutAction_Triggers(string collection) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - [|Xunit.Assert.Collection({0})|]; - [|Xunit.Assert.CollectionAsync({0})|]; - }} + void TestMethod() {{ + [|Xunit.Assert.Collection({0})|]; + [|Xunit.Assert.CollectionAsync({0})|]; + }} }} """, collection); @@ -38,10 +38,10 @@ public async Task CollectionCheckWithAction_DoesNotTrigger(string collection) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Collection({0}, i => Xunit.Assert.True(true)); - Xunit.Assert.CollectionAsync({0}, async i => {{ await System.Threading.Tasks.Task.Yield(); Xunit.Assert.True(true); }}); - }} + void TestMethod() {{ + Xunit.Assert.Collection({0}, i => Xunit.Assert.True(true)); + Xunit.Assert.CollectionAsync({0}, async i => {{ await System.Threading.Tasks.Task.Yield(); Xunit.Assert.True(true); }}); + }} }} """, collection); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksTests.cs index 9f90e667..723aafcf 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksTests.cs @@ -25,10 +25,10 @@ public async Task Containers_WithoutWhereClause_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Empty({0}); + void TestMethod() {{ + Xunit.Assert.Empty({0}); Xunit.Assert.NotEmpty({0}); - }} + }} }} """, collection); @@ -46,10 +46,10 @@ public async Task Containers_WithWhereClauseWithIndex_DoesNotTrigger( using System.Linq; class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Empty({0}.Where((f, i) => {1} && i > 0)); + void TestMethod() {{ + Xunit.Assert.Empty({0}.Where((f, i) => {1} && i > 0)); Xunit.Assert.NotEmpty({0}.Where((f, i) => {1} && i > 0)); - }} + }} }} """, collection, comparison); @@ -67,10 +67,10 @@ public async Task EnumurableEmptyCheck_WithChainedLinq_DoesNotTrigger( using System.Linq; class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Empty({0}.Where(f => {1}).Select(f => f)); + void TestMethod() {{ + Xunit.Assert.Empty({0}.Where(f => {1}).Select(f => f)); Xunit.Assert.NotEmpty({0}.Where(f => {1}).Select(f => f)); - }} + }} }} """, collection, comparison); @@ -88,10 +88,10 @@ public async Task Containers_WithWhereClause_Triggers( using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|xUnit2029:Xunit.Assert.Empty({0}.Where(f => {1}))|}}; + void TestMethod() {{ + {{|xUnit2029:Xunit.Assert.Empty({0}.Where(f => {1}))|}}; {{|xUnit2030:Xunit.Assert.NotEmpty({0}.Where(f => {1}))|}}; - }} + }} }} """, collection, comparison); @@ -108,10 +108,10 @@ public async Task Strings_WithWhereClause_Triggers(string sampleString) using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|xUnit2029:Xunit.Assert.Empty("{0}".Where(f => f > 0))|}}; + void TestMethod() {{ + {{|xUnit2029:Xunit.Assert.Empty("{0}".Where(f => f > 0))|}}; {{|xUnit2030:Xunit.Assert.NotEmpty("{0}".Where(f => f > 0))|}}; - }} + }} }} """, sampleString); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckTests.cs index c500071c..5e9d0b95 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckTests.cs @@ -19,9 +19,9 @@ public async Task ForLinqAnyCheck_Triggers(string method) using System.Linq; class TestClass {{ - void TestMethod() {{ - [|Xunit.Assert.{0}(new [] {{ 1 }}.Any(i => true))|]; - }} + void TestMethod() {{ + [|Xunit.Assert.{0}(new [] {{ 1 }}.Any(i => true))|]; + }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualGenericShouldNotBeUsedForStringValueTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualGenericShouldNotBeUsedForStringValueTests.cs index 86ea238b..855cbda5 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualGenericShouldNotBeUsedForStringValueTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualGenericShouldNotBeUsedForStringValueTests.cs @@ -23,9 +23,9 @@ public async Task StringEqualityCheckWithoutGenericType_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Equal({0}, {1}); - }} + void TestMethod() {{ + Xunit.Assert.Equal({0}, {1}); + }} }} """, expected, value); @@ -40,9 +40,9 @@ public async Task StringEqualityCheckWithGenericType_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - [|Xunit.Assert.Equal({0}, {1})|]; - }} + void TestMethod() {{ + [|Xunit.Assert.Equal({0}, {1})|]; + }} }} """, expected, value); @@ -57,9 +57,9 @@ public async Task StrictStringEqualityCheck_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - [|Xunit.Assert.StrictEqual({0}, {1})|]; - }} + void TestMethod() {{ + [|Xunit.Assert.StrictEqual({0}, {1})|]; + }} }} """, expected, value); @@ -74,9 +74,9 @@ public async Task StrictStringEqualityCheckWithGenericType_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - [|Xunit.Assert.StrictEqual({0}, {1})|]; - }} + void TestMethod() {{ + [|Xunit.Assert.StrictEqual({0}, {1})|]; + }} }} """, expected, value); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualLiteralValueShouldBeFirstTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualLiteralValueShouldBeFirstTests.cs index af01461a..b181d522 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualLiteralValueShouldBeFirstTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualLiteralValueShouldBeFirstTests.cs @@ -9,9 +9,9 @@ public async Task WhenConstantOrLiteralUsedForBothArguments_DoesNotTrigger() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.Equal("TestMethod", nameof(TestMethod)); - } + void TestMethod() { + Xunit.Assert.Equal("TestMethod", nameof(TestMethod)); + } } """; @@ -39,10 +39,10 @@ public async Task ExpectedConstantOrLiteralValueAsFirstArgument_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - var v = default({0}); - Xunit.Assert.Equal({1}, v); - }} + void TestMethod() {{ + var v = default({0}); + Xunit.Assert.Equal({1}, v); + }} }} """, type, value); @@ -54,9 +54,9 @@ public async Task ConstantsUsedInStringConstructorAsFirstArgument_DoesNotTrigger { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.Equal(new string(' ', 4), " "); - } + void TestMethod() { + Xunit.Assert.Equal(new string(' ', 4), " "); + } } """; @@ -71,10 +71,10 @@ public async Task ExpectedConstantOrLiteralValueAsSecondArgument_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - var v = default({0}); - {{|#0:Xunit.Assert.Equal(v, {1})|}}; - }} + void TestMethod() {{ + var v = default({0}); + {{|#0:Xunit.Assert.Equal(v, {1})|}}; + }} }} """, type, value); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(value, "Assert.Equal(expected, actual)", "TestMethod", "TestClass"); @@ -89,10 +89,10 @@ public async Task ExpectedConstantOrLiteralValueAsNamedExpectedArgument_DoesNotT { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - var v = default(int); - Xunit.Assert.Equal({0}actual: v, {0}expected: 0); - }} + void TestMethod() {{ + var v = default(int); + Xunit.Assert.Equal({0}actual: v, {0}expected: 0); + }} }} """, useAlternateForm ? "@" : ""); @@ -107,10 +107,10 @@ public async Task ExpectedConstantOrLiteralValueAsNamedExpectedArgument_Triggers { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - var v = default({0}); - {{|#0:Xunit.Assert.Equal(actual: {1}, expected: v)|}}; - }} + void TestMethod() {{ + var v = default({0}); + {{|#0:Xunit.Assert.Equal(actual: {1}, expected: v)|}}; + }} }} """, type, value); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(value, "Assert.Equal(expected, actual)", "TestMethod", "TestClass"); @@ -130,10 +130,10 @@ public async Task DoesNotFindWarningWhenArgumentsAreNotNamedCorrectly( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - var v = default(int); - Xunit.Assert.{0}({1}: 1, {2}: v); - }} + void TestMethod() {{ + var v = default(int); + Xunit.Assert.{0}({1}: 1, {2}: v); + }} }} """, methodName, firstArgumentName, secondArgumentName); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualPrecisionShouldBeInRangeTest.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualPrecisionShouldBeInRangeTest.cs index 4dee1b9e..a8467bb6 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualPrecisionShouldBeInRangeTest.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualPrecisionShouldBeInRangeTest.cs @@ -6,9 +6,9 @@ public class AssertEqualPrecisionShouldBeInRangeTest { static readonly string Template = /* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {0} - }} + void TestMethod() {{ + {0} + }} }} """; diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckTests.cs index 73070478..4be35b3f 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckTests.cs @@ -24,10 +24,10 @@ public async Task ForFirstBoolLiteral_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - bool val = true; - {{|#0:Xunit.Assert.{0}(true, val)|}}; - }} + void TestMethod() {{ + bool val = true; + {{|#0:Xunit.Assert.{0}(true, val)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -44,10 +44,10 @@ public async Task ForFirstBoolLiteral_WithCustomComparer_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - bool val = false; - {{|#0:Xunit.Assert.{0}(false, val, System.Collections.Generic.EqualityComparer.Default)|}}; - }} + void TestMethod() {{ + bool val = false; + {{|#0:Xunit.Assert.{0}(false, val, System.Collections.Generic.EqualityComparer.Default)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -61,10 +61,10 @@ public async Task ForFirstBoolLiteral_ObjectOverload_DoesNotTrigger(string metho { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - object val = false; - Xunit.Assert.{0}(true, val); - }} + void TestMethod() {{ + object val = false; + Xunit.Assert.{0}(true, val); + }} }} """, method); @@ -77,10 +77,10 @@ public async Task ForOtherLiteral_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - int val = 1; - Xunit.Assert.{0}(1, val); - }} + void TestMethod() {{ + int val = 1; + Xunit.Assert.{0}(1, val); + }} }} """, method); @@ -93,10 +93,10 @@ public async Task ForSecondBoolLiteral_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - bool val = false; - Xunit.Assert.{0}(val, true); - }} + void TestMethod() {{ + bool val = false; + Xunit.Assert.{0}(val, true); + }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckTests.cs index cae84524..360de9b9 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckTests.cs @@ -36,11 +36,11 @@ public async Task AllowedCollection_DoesNotTrigger(string collection) using System.Linq; class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Equal(0, {0}); - Xunit.Assert.Equal(1, {0}); - Xunit.Assert.NotEqual(0, {0}); - }} + void TestMethod() {{ + Xunit.Assert.Equal(0, {0}); + Xunit.Assert.Equal(1, {0}); + Xunit.Assert.NotEqual(0, {0}); + }} }} """, collection); @@ -57,11 +57,11 @@ public async Task AllowedCheck_DoesNotTrigger(string collection) using System.Linq; class TestClass {{ - void TestMethod() {{ - Xunit.Assert.Equal(2, {0}); - Xunit.Assert.NotEqual(1, {0}); - Xunit.Assert.NotEqual(2, {0}); - }} + void TestMethod() {{ + Xunit.Assert.Equal(2, {0}); + Xunit.Assert.NotEqual(1, {0}); + Xunit.Assert.NotEqual(2, {0}); + }} }} """, collection); @@ -77,11 +77,11 @@ public async Task InvalidCheckWithConcreteType_Triggers(string collection) using System.Linq; class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.Equal(0, {0})|}}; - {{|#1:Xunit.Assert.Equal(1, {0})|}}; - {{|#2:Xunit.Assert.NotEqual(0, {0})|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.Equal(0, {0})|}}; + {{|#1:Xunit.Assert.Equal(1, {0})|}}; + {{|#2:Xunit.Assert.NotEqual(0, {0})|}}; + }} }} """, collection); var expected = new[] @@ -103,12 +103,12 @@ public async Task InvalidCheckWithInterfaceType_Triggers(string @interface) using System.Collections.Generic; class TestClass {{ - void TestMethod() {{ - {0} collection = null; - {{|#0:Xunit.Assert.Equal(0, collection.Count)|}}; - {{|#1:Xunit.Assert.Equal(1, collection.Count)|}}; - {{|#2:Xunit.Assert.NotEqual(0, collection.Count)|}}; - }} + void TestMethod() {{ + {0} collection = null; + {{|#0:Xunit.Assert.Equal(0, collection.Count)|}}; + {{|#1:Xunit.Assert.Equal(1, collection.Count)|}}; + {{|#2:Xunit.Assert.NotEqual(0, collection.Count)|}}; + }} }} """, @interface); var expected = new[] @@ -130,23 +130,23 @@ public async Task InvalidCheckWithCustomNonGenericCollection_Triggers() using Xunit; class IntCollection : ICollection { - public int Count { get { throw null; } } - public bool IsReadOnly { get { throw null; } } - public void Add(int item) { throw null; } - public void Clear() { throw null; } - public bool Contains(int item) { throw null; } - public void CopyTo(int[] array, int arrayIndex) { throw null; } - public IEnumerator GetEnumerator() { throw null; } - public bool Remove(int item) { throw null; } - IEnumerator IEnumerable.GetEnumerator() { throw null; } + public int Count { get { throw null; } } + public bool IsReadOnly { get { throw null; } } + public void Add(int item) { throw null; } + public void Clear() { throw null; } + public bool Contains(int item) { throw null; } + public void CopyTo(int[] array, int arrayIndex) { throw null; } + public IEnumerator GetEnumerator() { throw null; } + public bool Remove(int item) { throw null; } + IEnumerator IEnumerable.GetEnumerator() { throw null; } } class TestClass { - void TestMethod() { - {|#0:Assert.Equal(0, new IntCollection().Count)|}; - {|#1:Assert.Equal(1, new IntCollection().Count)|}; - {|#2:Assert.NotEqual(0, new IntCollection().Count)|}; - } + void TestMethod() { + {|#0:Assert.Equal(0, new IntCollection().Count)|}; + {|#1:Assert.Equal(1, new IntCollection().Count)|}; + {|#2:Assert.NotEqual(0, new IntCollection().Count)|}; + } } """; var expected = new[] @@ -166,23 +166,23 @@ public async Task OverridingCountMethod_DoesNotTrigger() using System.Collections.Generic; interface IIntCollection : ICollection { - new int Count { get; } + new int Count { get; } } interface ICustomCollection : ICollection { - new int Count { get; } + new int Count { get; } } interface ICustomDictionary : ICollection> { - new int Count { get; } + new int Count { get; } } class TestClass { - void TestMethod() { - Xunit.Assert.Equal(1, ((IIntCollection)null).Count); - Xunit.Assert.Equal(1, ((ICustomCollection)null).Count); - Xunit.Assert.Equal(1, ((ICustomDictionary)null).Count); - } + void TestMethod() { + Xunit.Assert.Equal(1, ((IIntCollection)null).Count); + Xunit.Assert.Equal(1, ((ICustomCollection)null).Count); + Xunit.Assert.Equal(1, ((ICustomDictionary)null).Count); + } } """; @@ -194,9 +194,9 @@ public async Task ForNonIntArguments_DoesNotCrash() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.Equal('b', new int[0].Length); - } + void TestMethod() { + Xunit.Assert.Equal('b', new int[0].Length); + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForNullCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForNullCheckTests.cs index 3d57fbfd..7512da7b 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForNullCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualShouldNotBeUsedForNullCheckTests.cs @@ -28,10 +28,10 @@ public async Task ForFirstNullLiteral_StringOverload_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - string val = null; - {{|#0:Xunit.Assert.{0}(null, val)|}}; - }} + void TestMethod() {{ + string val = null; + {{|#0:Xunit.Assert.{0}(null, val)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -47,10 +47,10 @@ public async Task ForFirstNullLiteral_StringOverload_WithCustomComparer_Triggers { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - string val = null; - {{|#0:Xunit.Assert.{0}(null, val, System.StringComparer.Ordinal)|}}; - }} + void TestMethod() {{ + string val = null; + {{|#0:Xunit.Assert.{0}(null, val, System.StringComparer.Ordinal)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -71,10 +71,10 @@ public async Task ForFirstNullLiteral_ObjectOverload_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - object val = null; - {{|#0:Xunit.Assert.{0}(null, val)|}}; - }} + void TestMethod() {{ + object val = null; + {{|#0:Xunit.Assert.{0}(null, val)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -90,10 +90,10 @@ public async Task ForFirstNullLiteral_ObjectOverload_WithCustomComparer_Triggers { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - object val = null; - {{|#0:Xunit.Assert.{0}(null, val, System.Collections.Generic.EqualityComparer.Default)|}}; - }} + void TestMethod() {{ + object val = null; + {{|#0:Xunit.Assert.{0}(null, val, System.Collections.Generic.EqualityComparer.Default)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -112,10 +112,10 @@ public async Task ForFirstNullLiteral_GenericOverload_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - TestClass val = null; - {{|#0:Xunit.Assert.{0}(null, val)|}}; - }} + void TestMethod() {{ + TestClass val = null; + {{|#0:Xunit.Assert.{0}(null, val)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -131,10 +131,10 @@ public async Task ForFirstNullLiteral_GenericOverload_WithCustomComparer_Trigger { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - TestClass val = null; - {{|#0:Xunit.Assert.{0}(null, val, System.Collections.Generic.EqualityComparer.Default)|}}; - }} + void TestMethod() {{ + TestClass val = null; + {{|#0:Xunit.Assert.{0}(null, val, System.Collections.Generic.EqualityComparer.Default)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -148,10 +148,10 @@ public async Task ForOtherLiteral_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - int val = 1; - Xunit.Assert.{0}(1, val); - }} + void TestMethod() {{ + int val = 1; + Xunit.Assert.{0}(1, val); + }} }} """, method); @@ -164,10 +164,10 @@ public async Task ForSecondNullLiteral_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - string val = null; - Xunit.Assert.{0}(val, null); - }} + void TestMethod() {{ + string val = null; + Xunit.Assert.{0}(val, null); + }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualsShouldNotBeUsedTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualsShouldNotBeUsedTests.cs index 63af1b09..134d5235 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualsShouldNotBeUsedTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertEqualsShouldNotBeUsedTests.cs @@ -14,9 +14,9 @@ public async Task WhenProhibitedMethodIsUsed_Triggers( { var source = $@" class TestClass {{ - void TestMethod() {{ - {{|#0:{{|CS0619:Xunit.Assert.{method}(null, null)|}}|}}; - }} + void TestMethod() {{ + {{|#0:{{|CS0619:Xunit.Assert.{method}(null, null)|}}|}}; + }} }}"; var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeTests.cs index 5681ffd0..c4672ad2 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeTests.cs @@ -30,9 +30,9 @@ public async Task Interface_Triggers( using Xunit; class TestClass {{ - void TestMethod() {{ - {{|#0:Assert.{0}(new object())|}}; - }} + void TestMethod() {{ + {{|#0:Assert.{0}(new object())|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("interface", "System.IDisposable", replacement); @@ -57,13 +57,13 @@ public async Task Interface_WithExactMatchFlag_TriggersForTrue(string method) using Xunit; class TestClass {{ - void TestMethod() {{ - var flag = true; + void TestMethod() {{ + var flag = true; - {{|#0:Assert.{0}(new object(), true)|}}; - {{|#1:Assert.{0}(new object(), exactMatch: true)|}}; - Assert.{0}(new object(), flag); - }} + {{|#0:Assert.{0}(new object(), true)|}}; + {{|#1:Assert.{0}(new object(), exactMatch: true)|}}; + Assert.{0}(new object(), flag); + }} }} """, method); var expected = new[] { @@ -86,9 +86,9 @@ public async Task AbstractClass_Triggers( using Xunit; class TestClass {{ - void TestMethod() {{ - {{|#0:Assert.{0}(new object())|}}; - }} + void TestMethod() {{ + {{|#0:Assert.{0}(new object())|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("abstract class", "System.IO.Stream", replacement); @@ -113,13 +113,13 @@ public async Task AbstractClass_WithExactMatchFlag_TriggersForTrue(string method using Xunit; class TestClass {{ - void TestMethod() {{ - var flag = true; + void TestMethod() {{ + var flag = true; - {{|#0:Assert.{0}(new object(), true)|}}; - {{|#1:Assert.{0}(new object(), exactMatch: true)|}}; - Assert.{0}(new object(), flag); - }} + {{|#0:Assert.{0}(new object(), true)|}}; + {{|#1:Assert.{0}(new object(), exactMatch: true)|}}; + Assert.{0}(new object(), flag); + }} }} """, method); var expected = new[] { @@ -142,9 +142,9 @@ public async Task UsingStatic_Triggers( using static Xunit.Assert; class TestClass {{ - void TestMethod() {{ - {{|#0:{0}(new object())|}}; - }} + void TestMethod() {{ + {{|#0:{0}(new object())|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("interface", "System.IDisposable", replacement); @@ -166,17 +166,17 @@ public async Task NonAbstractClass_DoesNotTrigger(string method) using Xunit; class TestClass {{ - void TestMethod() {{ - var flag = true; - - Assert.{0}(new object()); - Assert.{0}(new object(), flag); - Assert.{0}(new object(), exactMatch: flag); - Assert.{0}(new object(), true); - Assert.{0}(new object(), exactMatch: true); - Assert.{0}(new object(), false); - Assert.{0}(new object(), exactMatch: false); - }} + void TestMethod() {{ + var flag = true; + + Assert.{0}(new object()); + Assert.{0}(new object(), flag); + Assert.{0}(new object(), exactMatch: flag); + Assert.{0}(new object(), true); + Assert.{0}(new object(), exactMatch: true); + Assert.{0}(new object(), false); + Assert.{0}(new object(), exactMatch: false); + }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldUseGenericOverloadTypeTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldUseGenericOverloadTypeTests.cs index 49aed351..ee9aa125 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldUseGenericOverloadTypeTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertIsTypeShouldUseGenericOverloadTypeTests.cs @@ -21,9 +21,9 @@ public async Task ForNonGenericCall_Triggers(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(typeof(int), 1)|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(typeof(int), 1)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("int"); @@ -37,9 +37,9 @@ public async Task ForGenericCall_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}(1); - }} + void TestMethod() {{ + Xunit.Assert.{0}(1); + }} }} """, method); @@ -53,10 +53,10 @@ public async Task ForGenericCall_WithExactMatchFlag_DoesNotTrigger(string method { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}(1, false); - Xunit.Assert.{0}(typeof(int), true); - }} + void TestMethod() {{ + Xunit.Assert.{0}(1, false); + Xunit.Assert.{0}(typeof(int), true); + }} }} """, method); @@ -78,20 +78,20 @@ public interface IParentClass {{ }} public interface IClass : IParentClass {{ - {1} + {1} }} public class Class : IClass {{ - public static void Method() {{ }} + public static void Method() {{ }} }} public abstract class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = new Class(); + [Fact] + public void TestMethod() {{ + var data = new Class(); - Assert.IsAssignableFrom(typeof(IClass), data); - }} + Assert.IsAssignableFrom(typeof(IClass), data); + }} }} """; @@ -125,20 +125,20 @@ public async Task ForNotStaticAbstractInterfaceMembers_Triggers( using Xunit; public interface IClass {{ - {0} {1} void Method() {2} + {0} {1} void Method() {2} }} public class Class : IClass {{ - public {0} void Method() {{ }} + public {0} void Method() {{ }} }} public abstract class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = new Class(); + [Fact] + public void TestMethod() {{ + var data = new Class(); - {{|#0:Assert.IsAssignableFrom(typeof(IClass), data)|}}; - }} + {{|#0:Assert.IsAssignableFrom(typeof(IClass), data)|}}; + }} }} """, staticModifier, abstractModifier, methodBody); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("IClass"); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertNullShouldNotBeCalledOnValueTypesTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertNullShouldNotBeCalledOnValueTypesTests.cs index 859cd2e9..61d3edf9 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertNullShouldNotBeCalledOnValueTypesTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertNullShouldNotBeCalledOnValueTypesTests.cs @@ -16,10 +16,10 @@ public async Task ForValueType_Triggers(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - int val = 1; - {{|#0:Xunit.Assert.{0}(val)|}}; - }} + void TestMethod() {{ + int val = 1; + {{|#0:Xunit.Assert.{0}(val)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", "int"); @@ -33,10 +33,10 @@ public async Task ForNullableValueType_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - int? val = 1; - Xunit.Assert.{0}(val); - }} + void TestMethod() {{ + int? val = 1; + Xunit.Assert.{0}(val); + }} }} """, method); @@ -49,10 +49,10 @@ public async Task ForNullableReferenceType_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - string val = null; - Xunit.Assert.{0}(val); - }} + void TestMethod() {{ + string val = null; + Xunit.Assert.{0}(val); + }} }} """, method); @@ -65,9 +65,9 @@ public async Task ForClassConstrainedGenericTypes_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class Class where T : class {{ - public void Method(T arg) {{ - Xunit.Assert.{0}(arg); - }} + public void Method(T arg) {{ + Xunit.Assert.{0}(arg); + }} }} """, method); @@ -82,11 +82,11 @@ public async Task ForInterfaceConstrainedGenericTypes_DoesNotTrigger(string meth interface IDo {{ }} class Class where T : IDo {{ - public void Method(System.Collections.Generic.IEnumerable collection) {{ - foreach (T item in collection) {{ - Xunit.Assert.{0}(item); - }} - }} + public void Method(System.Collections.Generic.IEnumerable collection) {{ + foreach (T item in collection) {{ + Xunit.Assert.{0}(item); + }} + }} }} """, method); @@ -99,11 +99,11 @@ public async Task ForUnconstrainedGenericTypes_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ class Class {{ - public void Method(System.Collections.Generic.IEnumerable collection) {{ - foreach (T item in collection) {{ - Xunit.Assert.{0}(item); - }} - }} + public void Method(System.Collections.Generic.IEnumerable collection) {{ + foreach (T item in collection) {{ + Xunit.Assert.{0}(item); + }} + }} }} """, method); @@ -117,20 +117,20 @@ public async Task ForUserDefinedImplicitConversion_DoesNotTrigger(string method) { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public void TestMethod() {{ - Xunit.Assert.{0}((MyBuggyInt)42); - Xunit.Assert.{0}((MyBuggyInt)(int?)42); - Xunit.Assert.{0}((MyBuggyIntBase)42); - Xunit.Assert.{0}((MyBuggyIntBase)(int?)42); - }} + public void TestMethod() {{ + Xunit.Assert.{0}((MyBuggyInt)42); + Xunit.Assert.{0}((MyBuggyInt)(int?)42); + Xunit.Assert.{0}((MyBuggyIntBase)42); + Xunit.Assert.{0}((MyBuggyIntBase)(int?)42); + }} }} public abstract class MyBuggyIntBase {{ - public static implicit operator MyBuggyIntBase(int i) => new MyBuggyInt(); + public static implicit operator MyBuggyIntBase(int i) => new MyBuggyInt(); }} public class MyBuggyInt : MyBuggyIntBase {{ - public MyBuggyInt() {{ }} + public MyBuggyInt() {{ }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckTests.cs index 3f5982b4..d8f5c158 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckTests.cs @@ -19,9 +19,9 @@ public async Task ForStaticRegexIsMatch_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(System.Text.RegularExpressions.Regex.IsMatch("abc", "\\w*"))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(System.Text.RegularExpressions.Regex.IsMatch("abc", "\\w*"))|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -37,9 +37,9 @@ public async Task ForInstanceRegexIsMatchWithInlineConstructedRegex_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(new System.Text.RegularExpressions.Regex("abc").IsMatch("\\w*"))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(new System.Text.RegularExpressions.Regex("abc").IsMatch("\\w*"))|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -55,10 +55,10 @@ public async Task ForInstanceRegexIsMatchWithConstructedRegexVariable_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - var regex = new System.Text.RegularExpressions.Regex("abc"); - {{|#0:Xunit.Assert.{0}(regex.IsMatch("\\w*"))|}}; - }} + void TestMethod() {{ + var regex = new System.Text.RegularExpressions.Regex("abc"); + {{|#0:Xunit.Assert.{0}(regex.IsMatch("\\w*"))|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSameShouldNotBeCalledOnValueTypesTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSameShouldNotBeCalledOnValueTypesTests.cs index 9ecf363d..3e76b71d 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSameShouldNotBeCalledOnValueTypesTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSameShouldNotBeCalledOnValueTypesTests.cs @@ -19,10 +19,10 @@ public async Task TwoValueParameters_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - int a = 0; - {{|#0:Xunit.Assert.{0}(0, a)|}}; - }} + void TestMethod() {{ + int a = 0; + {{|#0:Xunit.Assert.{0}(0, a)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", "int", replacement); @@ -38,10 +38,10 @@ public async Task FirstValueParameters_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - object a = 0; - {{|#0:Xunit.Assert.{0}(0, a)|}}; - }} + void TestMethod() {{ + object a = 0; + {{|#0:Xunit.Assert.{0}(0, a)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", "int", replacement); @@ -57,10 +57,10 @@ public async Task SecondValueParameters_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - object a = 0; - {{|#0:Xunit.Assert.{0}(a, 0)|}}; - }} + void TestMethod() {{ + object a = 0; + {{|#0:Xunit.Assert.{0}(a, 0)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", "int", replacement); @@ -77,27 +77,27 @@ public async Task UserDefinedImplicitConversion_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ public class TestClass {{ - public void TestMethod() {{ - var o = new object(); - - Xunit.Assert.{0}((MyBuggyInt)42, o); - Xunit.Assert.{0}((MyBuggyInt)(int?)42, o); - Xunit.Assert.{0}((MyBuggyIntBase)42, o); - Xunit.Assert.{0}((MyBuggyIntBase)(int?)42, o); - - Xunit.Assert.{0}(o, (MyBuggyInt)42); - Xunit.Assert.{0}(o, (MyBuggyInt)(int?)42); - Xunit.Assert.{0}(o, (MyBuggyIntBase)42); - Xunit.Assert.{0}(o, (MyBuggyIntBase)(int?)42); - }} + public void TestMethod() {{ + var o = new object(); + + Xunit.Assert.{0}((MyBuggyInt)42, o); + Xunit.Assert.{0}((MyBuggyInt)(int?)42, o); + Xunit.Assert.{0}((MyBuggyIntBase)42, o); + Xunit.Assert.{0}((MyBuggyIntBase)(int?)42, o); + + Xunit.Assert.{0}(o, (MyBuggyInt)42); + Xunit.Assert.{0}(o, (MyBuggyInt)(int?)42); + Xunit.Assert.{0}(o, (MyBuggyIntBase)42); + Xunit.Assert.{0}(o, (MyBuggyIntBase)(int?)42); + }} }} public abstract class MyBuggyIntBase {{ - public static implicit operator MyBuggyIntBase(int i) => new MyBuggyInt(); + public static implicit operator MyBuggyIntBase(int i) => new MyBuggyInt(); }} public class MyBuggyInt : MyBuggyIntBase {{ - public MyBuggyInt() {{ }} + public MyBuggyInt() {{ }} }} """, method); @@ -112,9 +112,9 @@ public async Task FirstValueParametersIfSecondIsNull_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(0, null)|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(0, null)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", "int", replacement); @@ -130,9 +130,9 @@ public async Task SecondValueParametersIfFirstIsNull_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(null, 0)|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(null, 0)|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", "int", replacement); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldBeUsedForSingleParameterTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldBeUsedForSingleParameterTests.cs index cdba147f..446014b4 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldBeUsedForSingleParameterTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldBeUsedForSingleParameterTests.cs @@ -16,10 +16,10 @@ public async Task ForSingleItemCollectionCheck_Triggers(string collection) using System.Collections.Generic; public class TestClass {{ - [Fact] - public void TestMethod() {{ - {{|#0:Assert.Collection({0}, item => Assert.NotNull(item))|}}; - }} + [Fact] + public void TestMethod() {{ + {{|#0:Assert.Collection({0}, item => Assert.NotNull(item))|}}; + }} }} """, collection); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Collection"); @@ -39,10 +39,10 @@ public async Task ForMultipleItemCollectionCheck_DoesNotTrigger(string collectio using System.Collections.Generic; public class TestClass {{ - [Fact] - public void TestMethod() {{ - Assert.Collection({0}, item1 => Assert.NotNull(item1), item2 => Assert.NotNull(item2)); - }} + [Fact] + public void TestMethod() {{ + Assert.Collection({0}, item1 => Assert.NotNull(item1), item2 => Assert.NotNull(item2)); + }} }} """, collection); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldUseTwoArgumentCallTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldUseTwoArgumentCallTests.cs index 33b31503..c000d79c 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldUseTwoArgumentCallTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSingleShouldUseTwoArgumentCallTests.cs @@ -18,9 +18,9 @@ public async Task Containers_WithoutWhereClause_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ + void TestMethod() {{ Xunit.Assert.Single({0}); - }} + }} }} """, collection); @@ -38,9 +38,9 @@ public async Task Containers_WithWhereClauseWithIndex_DoesNotTrigger( using System.Linq; class TestClass {{ - void TestMethod() {{ + void TestMethod() {{ Xunit.Assert.Single({0}.Where((f, i) => {1} && i > 0)); - }} + }} }} """, collection, comparison); @@ -58,9 +58,9 @@ public async Task EnumurableEmptyCheck_WithChainedLinq_DoesNotTrigger( using System.Linq; class TestClass {{ - void TestMethod() {{ + void TestMethod() {{ Xunit.Assert.Single({0}.Where(f => {1}).Select(f => f)); - }} + }} }} """, collection, comparison); @@ -78,9 +78,9 @@ public async Task Containers_WithWhereClause_Triggers( using System.Linq; class TestClass {{ - void TestMethod() {{ + void TestMethod() {{ [|Xunit.Assert.Single({0}.Where(f => {1}))|]; - }} + }} }} """, collection, comparison); @@ -97,9 +97,9 @@ public async Task Strings_WithWhereClause_Triggers(string sampleString) using System.Linq; class TestClass {{ - void TestMethod() {{ + void TestMethod() {{ [|Xunit.Assert.Single("{0}".Where(f => f > 0))|]; - }} + }} }} """, sampleString); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckTest.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckTest.cs index 5e4967a7..295e814e 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckTest.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckTest.cs @@ -41,9 +41,9 @@ public async Task ForInstanceEqualsCheck_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}("abc".Equals("a"))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}("abc".Equals("a"))|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -57,9 +57,9 @@ public async Task ForTrueInstanceEqualsCheck_WithSupportedStringComparison_Trigg { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.True("abc".Equals("a", System.StringComparison.{0}))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.True("abc".Equals("a", System.StringComparison.{0}))|}}; + }} }} """, comparison); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.Equal); @@ -73,9 +73,9 @@ public async Task ForTrueInstanceEqualsCheck_WithUnsupportedStringComparison_Doe { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.True("abc".Equals("a", System.StringComparison.{0})); - }} + void TestMethod() {{ + Xunit.Assert.True("abc".Equals("a", System.StringComparison.{0})); + }} }} """, comparison); @@ -88,9 +88,9 @@ public async Task ForFalseInstanceEqualsCheck_WithStringComparison_DoesNotTrigge { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.False("abc".Equals("a", System.StringComparison.{0})); - }} + void TestMethod() {{ + Xunit.Assert.False("abc".Equals("a", System.StringComparison.{0})); + }} }} """, comparison); @@ -105,9 +105,9 @@ public async Task ForStaticEqualsCheck_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(System.String.Equals("abc", "a"))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(System.String.Equals("abc", "a"))|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -121,9 +121,9 @@ public async Task ForTrueStaticEqualsCheck_WithSupportedStringComparison_Trigger { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.True(System.String.Equals("abc", "a", System.StringComparison.{0}))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.True(System.String.Equals("abc", "a", System.StringComparison.{0}))|}}; + }} }} """, comparison); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.Equal); @@ -137,9 +137,9 @@ public async Task ForTrueStaticEqualsCheck_WithUnsupportedStringComparison_DoesN { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.True(System.String.Equals("abc", "a", System.StringComparison.{0})); - }} + void TestMethod() {{ + Xunit.Assert.True(System.String.Equals("abc", "a", System.StringComparison.{0})); + }} }} """, comparison); @@ -152,9 +152,9 @@ public async Task ForFalseStaticEqualsCheck_WithStringComparison_DoesNotTrigger( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.False(System.String.Equals("abc", "a", System.StringComparison.{0})); - }} + void TestMethod() {{ + Xunit.Assert.False(System.String.Equals("abc", "a", System.StringComparison.{0})); + }} }} """, comparison); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSubstringCheckShouldNotUseBoolCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSubstringCheckShouldNotUseBoolCheckTests.cs index b452cbe9..641ee42c 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertSubstringCheckShouldNotUseBoolCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertSubstringCheckShouldNotUseBoolCheckTests.cs @@ -20,9 +20,9 @@ public async Task ForBooleanContainsCheck_Triggers( { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}("abc".Contains("a"))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}("abc".Contains("a"))|}}; + }} }} """, method); var expected = Verify.Diagnostic().WithLocation(0).WithArguments($"Assert.{method}()", replacement); @@ -36,9 +36,9 @@ public async Task ForBooleanContainsCheck_WithUserMessage_DoesNotTrigger(string { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".Contains("a"), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".Contains("a"), "message"); + }} }} """, method); @@ -50,9 +50,9 @@ public async Task ForBooleanTrueStartsWithCheck_Triggers() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - {|#0:Xunit.Assert.True("abc".StartsWith("a"))|}; - } + void TestMethod() { + {|#0:Xunit.Assert.True("abc".StartsWith("a"))|}; + } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.StartsWith); @@ -65,9 +65,9 @@ public async Task ForBooleanTrueStartsWithCheck_WithStringComparison_Triggers() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - {|#0:Xunit.Assert.True("abc".StartsWith("a", System.StringComparison.CurrentCulture))|}; - } + void TestMethod() { + {|#0:Xunit.Assert.True("abc".StartsWith("a", System.StringComparison.CurrentCulture))|}; + } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.StartsWith); @@ -80,9 +80,9 @@ public async Task ForBooleanFalseStartsWithCheck_DoesNotTrigger() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.False("abc".StartsWith("a")); - } + void TestMethod() { + Xunit.Assert.False("abc".StartsWith("a")); + } } """; @@ -94,9 +94,9 @@ public async Task ForBooleanFalseStartsWithCheck_WithStringComparison_DoesNotTri { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.False("abc".StartsWith("a", System.StringComparison.CurrentCulture)); - } + void TestMethod() { + Xunit.Assert.False("abc".StartsWith("a", System.StringComparison.CurrentCulture)); + } } """; @@ -109,9 +109,9 @@ public async Task ForBooleanStartsWithCheck_WithUserMessage_DoesNotTrigger(strin { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".StartsWith("a"), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".StartsWith("a"), "message"); + }} }} """, method); @@ -124,9 +124,9 @@ public async Task ForBooleanStartsWithCheck_WithStringComparison_AndUserMessage_ { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".StartsWith("a", System.StringComparison.CurrentCulture), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".StartsWith("a", System.StringComparison.CurrentCulture), "message"); + }} }} """, method); @@ -139,9 +139,9 @@ public async Task ForBooleanStartsWithCheck_WithBoolAndCulture_DoesNotTrigger(st { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".StartsWith("a", true, System.Globalization.CultureInfo.CurrentCulture)); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".StartsWith("a", true, System.Globalization.CultureInfo.CurrentCulture)); + }} }} """, method); @@ -154,9 +154,9 @@ public async Task ForBooleanStartsWithCheck_WithBoolAndCulture_AndUserMessage_Do { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".StartsWith("a", true, System.Globalization.CultureInfo.CurrentCulture), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".StartsWith("a", true, System.Globalization.CultureInfo.CurrentCulture), "message"); + }} }} """, method); @@ -168,9 +168,9 @@ public async Task ForBooleanTrueEndsWithCheck_Triggers() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - {|#0:Xunit.Assert.True("abc".EndsWith("a"))|}; - } + void TestMethod() { + {|#0:Xunit.Assert.True("abc".EndsWith("a"))|}; + } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.EndsWith); @@ -183,9 +183,9 @@ public async Task ForBooleanTrueEndsWithCheck_WithStringComparison_Triggers() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - {|#0:Xunit.Assert.True("abc".EndsWith("a", System.StringComparison.CurrentCulture))|}; - } + void TestMethod() { + {|#0:Xunit.Assert.True("abc".EndsWith("a", System.StringComparison.CurrentCulture))|}; + } } """; var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.True()", Constants.Asserts.EndsWith); @@ -198,9 +198,9 @@ public async Task ForBooleanFalseEndsWithCheck_DoesNotTrigger() { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.False("abc".EndsWith("a")); - } + void TestMethod() { + Xunit.Assert.False("abc".EndsWith("a")); + } } """; @@ -212,9 +212,9 @@ public async Task ForBooleanFalseEndsWithCheck_WithStringComparison_DoesNotTrigg { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - Xunit.Assert.False("abc".EndsWith("a", System.StringComparison.CurrentCulture)); - } + void TestMethod() { + Xunit.Assert.False("abc".EndsWith("a", System.StringComparison.CurrentCulture)); + } } """; @@ -227,9 +227,9 @@ public async Task ForBooleanEndsWithCheck_WithUserMessage_DoesNotTrigger(string { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".EndsWith("a"), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".EndsWith("a"), "message"); + }} }} """, method); @@ -242,9 +242,9 @@ public async Task ForBooleanEndsWithCheck_WithStringComparison_AndUserMessage_Do { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".EndsWith("a", System.StringComparison.CurrentCulture), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".EndsWith("a", System.StringComparison.CurrentCulture), "message"); + }} }} """, method); @@ -257,9 +257,9 @@ public async Task ForBooleanEndsWithCheck_WithBoolAndCulture_DoesNotTrigger(stri { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".EndsWith("a", true, System.Globalization.CultureInfo.CurrentCulture)); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".EndsWith("a", true, System.Globalization.CultureInfo.CurrentCulture)); + }} }} """, method); @@ -272,9 +272,9 @@ public async Task ForBooleanEndsWithCheck_WithBoolAndCulture_AndUserMessage_Does { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - Xunit.Assert.{0}("abc".EndsWith("a", true, System.Globalization.CultureInfo.CurrentCulture), "message"); - }} + void TestMethod() {{ + Xunit.Assert.{0}("abc".EndsWith("a", true, System.Globalization.CultureInfo.CurrentCulture), "message"); + }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckTests.cs index ddbf2b5d..6e0712d0 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckTests.cs @@ -25,13 +25,13 @@ public async Task Throws_NonGeneric_WithNonAsyncLambda_DoesNotTrigger(string lam { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Action ThrowingMethod = () => {{ - throw new System.NotImplementedException(); - }}; + System.Action ThrowingMethod = () => {{ + throw new System.NotImplementedException(); + }}; - void TestMethod() {{ - Xunit.Assert.Throws(typeof(System.NotImplementedException), {0}); - }} + void TestMethod() {{ + Xunit.Assert.Throws(typeof(System.NotImplementedException), {0}); + }} }} """, lambda); @@ -44,13 +44,13 @@ public async Task Throws_Generic_WithNonAsyncLambda_DoesNotTrigger(string lambda { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Action ThrowingMethod = () => {{ - throw new System.NotImplementedException(); - }}; + System.Action ThrowingMethod = () => {{ + throw new System.NotImplementedException(); + }}; - void TestMethod() {{ - Xunit.Assert.Throws({0}); - }} + void TestMethod() {{ + Xunit.Assert.Throws({0}); + }} }} """, lambda); @@ -63,13 +63,13 @@ public async Task Throws_Generic_WithNamedArgumentException_WithNonAsyncLambda_D { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Action ThrowingMethod = () => {{ - throw new System.NotImplementedException(); - }}; + System.Action ThrowingMethod = () => {{ + throw new System.NotImplementedException(); + }}; - void TestMethod() {{ - Xunit.Assert.Throws("param1", {0}); - }} + void TestMethod() {{ + Xunit.Assert.Throws("param1", {0}); + }} }} """, lambda); @@ -82,13 +82,13 @@ public async Task Throws_NonGeneric_WithAsyncLambda_Triggers(string lambda) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ + System.Threading.Tasks.Task ThrowingMethod() {{ throw new System.NotImplementedException(); - }} + }} - void TestMethod() {{ - {{|#0:{{|CS0619:Xunit.Assert.Throws(typeof(System.NotImplementedException), {0})|}}|}}; - }} + void TestMethod() {{ + {{|#0:{{|CS0619:Xunit.Assert.Throws(typeof(System.NotImplementedException), {0})|}}|}}; + }} }} """, lambda); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.Throws()", Constants.Asserts.ThrowsAsync); @@ -102,13 +102,13 @@ public async Task Throws_Generic_WithAsyncLambda_Triggers(string lambda) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - void TestMethod() {{ - {{|#0:{{|CS0619:Xunit.Assert.Throws({0})|}}|}}; - }} + void TestMethod() {{ + {{|#0:{{|CS0619:Xunit.Assert.Throws({0})|}}|}}; + }} }} """, lambda); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.Throws()", Constants.Asserts.ThrowsAsync); @@ -122,13 +122,13 @@ public async Task Throws_Generic_WithNamedArgumentException_WithAsyncLambda_Trig { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - void TestMethod() {{ - {{|#0:{{|CS0619:Xunit.Assert.Throws("param1", {0})|}}|}}; - }} + void TestMethod() {{ + {{|#0:{{|CS0619:Xunit.Assert.Throws("param1", {0})|}}|}}; + }} }} """, lambda); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.Throws()", Constants.Asserts.ThrowsAsync); @@ -142,13 +142,13 @@ public async Task ThrowsAsync_NonGeneric_WithAsyncLambda_DoesNotTrigger(string l { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - async System.Threading.Tasks.Task TestMethod() {{ - await Xunit.Assert.ThrowsAsync(typeof(System.NotImplementedException), {0}); - }} + async System.Threading.Tasks.Task TestMethod() {{ + await Xunit.Assert.ThrowsAsync(typeof(System.NotImplementedException), {0}); + }} }} """, lambda); @@ -161,13 +161,13 @@ public async Task ThrowsAsync_Generic_WithAsyncLambda_DoesNotTrigger(string lamb { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - async void TestMethod() {{ - await Xunit.Assert.ThrowsAsync({0}); - }} + async void TestMethod() {{ + await Xunit.Assert.ThrowsAsync({0}); + }} }} """, lambda); @@ -180,13 +180,13 @@ public async Task ThrowsAny_WithNonAsyncLambda_DoesNotTrigger(string lambda) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Action ThrowingMethod = () => {{ - throw new System.NotImplementedException(); - }}; + System.Action ThrowingMethod = () => {{ + throw new System.NotImplementedException(); + }}; - void TestMethod() {{ - Xunit.Assert.ThrowsAny({0}); - }} + void TestMethod() {{ + Xunit.Assert.ThrowsAny({0}); + }} }} """, lambda); @@ -199,13 +199,13 @@ public async Task ThrowsAny_WithAsyncLambda_Triggers(string lambda) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - void TestMethod() {{ - {{|#0:{{|CS0619:Xunit.Assert.ThrowsAny({0})|}}|}}; - }} + void TestMethod() {{ + {{|#0:{{|CS0619:Xunit.Assert.ThrowsAny({0})|}}|}}; + }} }} """, lambda); var expected = Verify.Diagnostic().WithLocation(0).WithArguments("Assert.ThrowsAny()", Constants.Asserts.ThrowsAnyAsync); @@ -219,13 +219,13 @@ public async Task ThrowsAnyAsync_WithAsyncLambda_DoesNotTrigger(string lambda) { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - async void TestMethod() {{ - await Xunit.Assert.ThrowsAnyAsync({0}); - }} + async void TestMethod() {{ + await Xunit.Assert.ThrowsAnyAsync({0}); + }} }} """, lambda); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldUseGenericOverloadCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldUseGenericOverloadCheckTests.cs index 0872e42c..bcc98db9 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldUseGenericOverloadCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssertThrowsShouldUseGenericOverloadCheckTests.cs @@ -19,13 +19,13 @@ public async Task ForThrowsCheck_WithExceptionParameter_OnThrowingMethod_Trigger { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - System.Threading.Tasks.Task ThrowingMethod() {{ - throw new System.NotImplementedException(); - }} + System.Threading.Tasks.Task ThrowingMethod() {{ + throw new System.NotImplementedException(); + }} - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(typeof(System.NotImplementedException), (System.Func)ThrowingMethod)|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(typeof(System.NotImplementedException), (System.Func)ThrowingMethod)|}}; + }} }} """, method); var expected = new List { @@ -43,9 +43,9 @@ public async Task ForThrowsCheck_WithExceptionParameter_OnThrowingLambda_Trigger { var source = string.Format(/* lang=c#-test */ """ class TestClass {{ - void TestMethod() {{ - {{|#0:Xunit.Assert.{0}(typeof(System.NotImplementedException), () => System.Threading.Tasks.Task.Delay(0))|}}; - }} + void TestMethod() {{ + {{|#0:Xunit.Assert.{0}(typeof(System.NotImplementedException), () => System.Threading.Tasks.Task.Delay(0))|}}; + }} }} """, method); var expected = new List { @@ -62,13 +62,13 @@ public async Task ForThrowsCheck_WithExceptionTypeArgument_OnThrowingMethod_Trig { var source = /* lang=c#-test */ """ class TestClass { - System.Threading.Tasks.Task ThrowingMethod() { - throw new System.NotImplementedException(); - } + System.Threading.Tasks.Task ThrowingMethod() { + throw new System.NotImplementedException(); + } - void TestMethod() { - {|CS0619:Xunit.Assert.Throws((System.Func)ThrowingMethod)|}; - } + void TestMethod() { + {|CS0619:Xunit.Assert.Throws((System.Func)ThrowingMethod)|}; + } } """; @@ -80,13 +80,13 @@ public async Task ForThrowsAsyncCheck_WithExceptionTypeArgument_OnThrowingMethod { var source = /* lang=c#-test */ """ class TestClass { - System.Threading.Tasks.Task ThrowingMethod() { - throw new System.NotImplementedException(); - } + System.Threading.Tasks.Task ThrowingMethod() { + throw new System.NotImplementedException(); + } - async System.Threading.Tasks.Task TestMethod() { - await Xunit.Assert.ThrowsAsync((System.Func)ThrowingMethod); - } + async System.Threading.Tasks.Task TestMethod() { + await Xunit.Assert.ThrowsAsync((System.Func)ThrowingMethod); + } } """; @@ -98,9 +98,9 @@ public async Task ForThrowsCheck_WithExceptionTypeArgument_OnThrowingLambda_Trig { var source = /* lang=c#-test */ """ class TestClass { - void TestMethod() { - {|CS0619:Xunit.Assert.Throws(() => System.Threading.Tasks.Task.Delay(0))|}; - } + void TestMethod() { + {|CS0619:Xunit.Assert.Throws(() => System.Threading.Tasks.Task.Delay(0))|}; + } } """; @@ -112,9 +112,9 @@ public async Task ForThrowsAsyncCheck_WithExceptionTypeArgument_OnThrowingLambda { var source = /* lang=c#-test */ """ class TestClass { - async System.Threading.Tasks.Task TestMethod() { - await Xunit.Assert.ThrowsAsync(() => System.Threading.Tasks.Task.Delay(0)); - } + async System.Threading.Tasks.Task TestMethod() { + await Xunit.Assert.ThrowsAsync(() => System.Threading.Tasks.Task.Delay(0)); + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AssignableFromAssertionIsConfusinglyNamedTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AssignableFromAssertionIsConfusinglyNamedTests.cs index 0918eb87..55bd64c3 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AssignableFromAssertionIsConfusinglyNamedTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AssignableFromAssertionIsConfusinglyNamedTests.cs @@ -26,10 +26,10 @@ public async Task WhenReplacementAvailable_Triggers( using Xunit; class TestClass {{ - void TestMethod() {{ - {{|#0:Assert.{0}(new object())|}}; - {{|#1:Assert.{0}(typeof(object), new object())|}}; - }} + void TestMethod() {{ + {{|#0:Assert.{0}(new object())|}}; + {{|#1:Assert.{0}(typeof(object), new object())|}}; + }} }} """, method); var expected = new[] { @@ -51,10 +51,10 @@ public async Task WhenReplacementNotAvailable_DoesNotTriggers( using Xunit; class TestClass {{ - void TestMethod() {{ - Assert.{0}(new object()); - Assert.{0}(typeof(object), new object()); - }} + void TestMethod() {{ + Assert.{0}(new object()); + Assert.{0}(typeof(object), new object()); + }} }} """, method); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/AsyncAssertsShouldBeAwaitedTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/AsyncAssertsShouldBeAwaitedTests.cs index 45caaff0..b70327c2 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/AsyncAssertsShouldBeAwaitedTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/AsyncAssertsShouldBeAwaitedTests.cs @@ -14,10 +14,10 @@ public async Task UnawaitedNonAssertion_DoesNotTrigger() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Task.Delay(1); - } + [Fact] + public void TestMethod() { + Task.Delay(1); + } } """; @@ -32,20 +32,20 @@ public void TestMethod() { using Xunit; public class TestClass : INotifyPropertyChanged {{ - public int Property {{ get; set; }} + public int Property {{ get; set; }} - public event PropertyChangedEventHandler? PropertyChanged; - public event EventHandler? SimpleEvent; - public event EventHandler? SimpleIntEvent; + public event PropertyChangedEventHandler? PropertyChanged; + public event EventHandler? SimpleEvent; + public event EventHandler? SimpleIntEvent; - [Fact] - public async Task TestMethod() {{ - {0} - }} + [Fact] + public async Task TestMethod() {{ + {0} + }} }} public static class MyTaskExtensions {{ - public static void ConsumeTask(this Task t) {{ }} + public static void ConsumeTask(this Task t) {{ }} }} """; diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeNegatedTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeNegatedTests.cs index 7406b581..b20df05b 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeNegatedTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeNegatedTests.cs @@ -15,12 +15,12 @@ public async Task NegatedBooleanAssertion_Triggers( using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - bool condition = true; + [Fact] + public void TestMethod() {{ + bool condition = true; - {{|#0:Assert.{0}(!condition)|}}; - }} + {{|#0:Assert.{0}(!condition)|}}; + }} }} """, assertion); var expected = Verify.Diagnostic().WithLocation(0).WithArguments(assertion, replacement); diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckTests.cs index 2c498358..4c67ea9b 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckTests.cs @@ -24,14 +24,14 @@ public async Task ComparingAgainstNonLiteral_DoesNotTrigger( using Xunit; public class TestClass {{ - public void TestMethod() {{ - var value1 = 42; - var value2 = 2112; - var value3 = new {{ innerValue = 2600 }}; - - Assert.{0}(value1 {1} value2); - Assert.{0}(value1 {1} value3.innerValue); - }} + public void TestMethod() {{ + var value1 = 42; + var value2 = 2112; + var value3 = new {{ innerValue = 2600 }}; + + Assert.{0}(value1 {1} value2); + Assert.{0}(value1 {1} value3.innerValue); + }} }} """, method, @operator); @@ -58,12 +58,12 @@ public async Task ComparingAgainstLiteral_WithMessage_DoesNotTrigger( public enum MyEnum {{ None, Bacon, Veggie }} public class TestClass {{ - public void TestMethod() {{ - var value = {2}; + public void TestMethod() {{ + var value = {2}; - Assert.{0}(value {1} {2}, "message"); - Assert.{0}({2} {1} value, "message"); - }} + Assert.{0}(value {1} {2}, "message"); + Assert.{0}({2} {1} value, "message"); + }} }} """, method, @operator, value); @@ -83,12 +83,12 @@ public async Task ComparingAgainstLiteral_WithoutMessage_Triggers( public enum MyEnum {{ None, Bacon, Veggie }} public class TestClass {{ - public void TestMethod() {{ - var value = {2}; + public void TestMethod() {{ + var value = {2}; - {{|#0:Assert.{0}(value {1} {2})|}}; - {{|#1:Assert.{0}({2} {1} value)|}}; - }} + {{|#0:Assert.{0}(value {1} {2})|}}; + {{|#1:Assert.{0}({2} {1} value)|}}; + }} }} """, method, @operator, value); var suggestedAssert = @@ -126,12 +126,12 @@ public async Task ComparingAgainstNull_WithMessage_DoesNotTrigger( public enum MyEnum {{ None, Bacon, Veggie }} public class TestClass {{ - {2}? field = default; + {2}? field = default; - public void TestMethod() {{ - Assert.{0}(field {1} null, "Message"); - Assert.{0}(null {1} field, "Message"); - }} + public void TestMethod() {{ + Assert.{0}(field {1} null, "Message"); + Assert.{0}(null {1} field, "Message"); + }} }} """, method, @operator, type); @@ -151,12 +151,12 @@ public async Task ComparingAgainstNull_WithoutMessage_Triggers( public enum MyEnum {{ None, Bacon, Veggie }} public class TestClass {{ - {2}? field = default; + {2}? field = default; - public void TestMethod() {{ - {{|#0:Assert.{0}(field {1} null)|}}; - {{|#1:Assert.{0}(null {1} field)|}}; - }} + public void TestMethod() {{ + {{|#0:Assert.{0}(field {1} null)|}}; + {{|#1:Assert.{0}(null {1} field)|}}; + }} }} """, method, @operator, type); var suggestedAssert = @@ -195,14 +195,14 @@ public async Task ComparingAgainstBooleanLiteral_Triggers( using Xunit; public class TestClass {{ - bool field = {2}; - - void TestMethod() {{ - {{|#0:Assert.{0}(field {1} {2})|}}; - {{|#1:Assert.{0}(field {1} {2}, "Message")|}}; - {{|#2:Assert.{0}({2} {1} field)|}}; - {{|#3:Assert.{0}({2} {1} field, "Message")|}}; - }} + bool field = {2}; + + void TestMethod() {{ + {{|#0:Assert.{0}(field {1} {2})|}}; + {{|#1:Assert.{0}(field {1} {2}, "Message")|}}; + {{|#2:Assert.{0}({2} {1} field)|}}; + {{|#3:Assert.{0}({2} {1} field, "Message")|}}; + }} }} """, method, @operator, value); var expected = new[] diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/DoNotUseAssertEmptyWithProblematicTypesTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/DoNotUseAssertEmptyWithProblematicTypesTests.cs index c11fb2ce..286ff1d3 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/DoNotUseAssertEmptyWithProblematicTypesTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/DoNotUseAssertEmptyWithProblematicTypesTests.cs @@ -22,10 +22,10 @@ public async Task NonProblematicCollection_DoesNotTrigger(string invocation) using Xunit; public class TestClass {{ - public void TestMethod() {{ - Assert.Empty({0}); - Assert.NotEmpty({0}); - }} + public void TestMethod() {{ + Assert.Empty({0}); + Assert.NotEmpty({0}); + }} }} """, invocation); @@ -46,10 +46,10 @@ public async Task ConvertingToCollection_DoesNotTrigger( using Xunit; public class TestClass {{ - public void TestMethod() {{ - Assert.Empty({0}.ToArray()); - Assert.NotEmpty({0}.ToArray()); - }} + public void TestMethod() {{ + Assert.Empty({0}.ToArray()); + Assert.NotEmpty({0}.ToArray()); + }} }} """, invocation); @@ -69,10 +69,10 @@ public async Task UsingProblematicType_Triggers( using Xunit; public class TestClass {{ - public void TestMethod() {{ - {{|#0:Assert.Empty({0})|}}; - {{|#1:Assert.NotEmpty({0})|}}; - }} + public void TestMethod() {{ + {{|#0:Assert.Empty({0})|}}; + {{|#1:Assert.NotEmpty({0})|}}; + }} }} """, invocation); var expected = new[] diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/SetEqualityAnalyzerTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/SetEqualityAnalyzerTests.cs index 74d8f87c..5db3ee13 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/SetEqualityAnalyzerTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/SetEqualityAnalyzerTests.cs @@ -10,32 +10,32 @@ public class SetEqualityAnalyzerTests using System.Collections.Generic; public class MySet : ISet { - public int Count => throw new System.NotImplementedException(); - public bool IsReadOnly => throw new System.NotImplementedException(); - - public bool Add(int item) => throw new System.NotImplementedException(); - public void Clear() => throw new System.NotImplementedException(); - public bool Contains(int item) => throw new System.NotImplementedException(); - public void CopyTo(int[] array, int arrayIndex) => throw new System.NotImplementedException(); - public void ExceptWith(IEnumerable other) => throw new System.NotImplementedException(); - public IEnumerator GetEnumerator() => throw new System.NotImplementedException(); - public void IntersectWith(IEnumerable other) => throw new System.NotImplementedException(); - public bool IsProperSubsetOf(IEnumerable other) => throw new System.NotImplementedException(); - public bool IsProperSupersetOf(IEnumerable other) => throw new System.NotImplementedException(); - public bool IsSubsetOf(IEnumerable other) => throw new System.NotImplementedException(); - public bool IsSupersetOf(IEnumerable other) => throw new System.NotImplementedException(); - public bool Overlaps(IEnumerable other) => throw new System.NotImplementedException(); - public bool Remove(int item) => throw new System.NotImplementedException(); - public bool SetEquals(IEnumerable other) => throw new System.NotImplementedException(); - public void SymmetricExceptWith(IEnumerable other) => throw new System.NotImplementedException(); - public void UnionWith(IEnumerable other) => throw new System.NotImplementedException(); - void ICollection.Add(int item) => throw new System.NotImplementedException(); - IEnumerator IEnumerable.GetEnumerator() => throw new System.NotImplementedException(); + public int Count => throw new System.NotImplementedException(); + public bool IsReadOnly => throw new System.NotImplementedException(); + + public bool Add(int item) => throw new System.NotImplementedException(); + public void Clear() => throw new System.NotImplementedException(); + public bool Contains(int item) => throw new System.NotImplementedException(); + public void CopyTo(int[] array, int arrayIndex) => throw new System.NotImplementedException(); + public void ExceptWith(IEnumerable other) => throw new System.NotImplementedException(); + public IEnumerator GetEnumerator() => throw new System.NotImplementedException(); + public void IntersectWith(IEnumerable other) => throw new System.NotImplementedException(); + public bool IsProperSubsetOf(IEnumerable other) => throw new System.NotImplementedException(); + public bool IsProperSupersetOf(IEnumerable other) => throw new System.NotImplementedException(); + public bool IsSubsetOf(IEnumerable other) => throw new System.NotImplementedException(); + public bool IsSupersetOf(IEnumerable other) => throw new System.NotImplementedException(); + public bool Overlaps(IEnumerable other) => throw new System.NotImplementedException(); + public bool Remove(int item) => throw new System.NotImplementedException(); + public bool SetEquals(IEnumerable other) => throw new System.NotImplementedException(); + public void SymmetricExceptWith(IEnumerable other) => throw new System.NotImplementedException(); + public void UnionWith(IEnumerable other) => throw new System.NotImplementedException(); + void ICollection.Add(int item) => throw new System.NotImplementedException(); + IEnumerator IEnumerable.GetEnumerator() => throw new System.NotImplementedException(); } public class MyComparer : IEqualityComparer { - public bool Equals(int x, int y) => throw new System.NotImplementedException(); - public int GetHashCode(int obj) => throw new System.NotImplementedException(); + public bool Equals(int x, int y) => throw new System.NotImplementedException(); + public int GetHashCode(int obj) => throw new System.NotImplementedException(); } """; @@ -61,13 +61,13 @@ public async Task WithCollectionComparer_DoesNotTrigger( using System.Collections.Immutable; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var collection1 = {1}; - var collection2 = {2}; + [Fact] + public void TestMethod() {{ + var collection1 = {1}; + var collection2 = {2}; - Assert.{0}(collection1, collection2, (IEnumerable e1, IEnumerable e2) => true); - }} + Assert.{0}(collection1, collection2, (IEnumerable e1, IEnumerable e2) => true); + }} }} """, method, collection1, collection2); @@ -87,23 +87,23 @@ public async Task WithEqualityComparer_DoesNotTrigger( using System.Collections.Immutable; public class TestEqualityComparer : IEqualityComparer {{ - public bool Equals(int x, int y) {{ - return true; - }} + public bool Equals(int x, int y) {{ + return true; + }} - public int GetHashCode(int obj) {{ - return 0; - }} + public int GetHashCode(int obj) {{ + return 0; + }} }} public class TestClass {{ - [Fact] - public void TestMethod() {{ - var collection1 = {1}; - var collection2 = {2}; + [Fact] + public void TestMethod() {{ + var collection1 = {1}; + var collection2 = {2}; - Assert.{0}(collection1, collection2, new TestEqualityComparer()); - }} + Assert.{0}(collection1, collection2, new TestEqualityComparer()); + }} }} """, method, collection1, collection2); @@ -123,13 +123,13 @@ public async Task WithComparerLambda_Triggers( using System.Collections.Immutable; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var collection1 = {1}; - var collection2 = {2}; + [Fact] + public void TestMethod() {{ + var collection1 = {1}; + var collection2 = {2}; - {{|#0:Assert.{0}(collection1, collection2, (int e1, int e2) => true)|}}; - }} + {{|#0:Assert.{0}(collection1, collection2, (int e1, int e2) => true)|}}; + }} }} """, method, collection1, collection2); var expected = Verify.Diagnostic("xUnit2026").WithLocation(0).WithArguments(method); @@ -161,25 +161,25 @@ public async Task WithComparerFunction_Triggers( using System.Collections.Immutable; public class TestClass {{ - private bool FuncComparer(int obj1, int obj2) {{ - return true; - }} + private bool FuncComparer(int obj1, int obj2) {{ + return true; + }} - private delegate bool FuncDelegate(int obj1, int obj2); + private delegate bool FuncDelegate(int obj1, int obj2); - [Fact] - public void TestMethod() {{ - var collection1 = {2}; - var collection2 = {3}; + [Fact] + public void TestMethod() {{ + var collection1 = {2}; + var collection2 = {3}; - bool LocalFunc(int obj1, int obj2) {{ - return true; - }} + bool LocalFunc(int obj1, int obj2) {{ + return true; + }} - var funcDelegate = FuncComparer; + var funcDelegate = FuncComparer; - {{|#0:Assert.{0}(collection1, collection2, {1})|}}; - }} + {{|#0:Assert.{0}(collection1, collection2, {1})|}}; + }} }} """, method, comparerFuncSyntax, collection1, collection2); var expected = Verify.Diagnostic("xUnit2026").WithLocation(0).WithArguments(method); @@ -210,15 +210,15 @@ public async Task LinearContainers_DoesNotTrigger( using System.Linq; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var collection1 = new List(); - var collection2 = {1}; - - Assert.{0}(collection1, collection2); - Assert.{0}(collection1, collection2, (int e1, int e2) => true); - Assert.{0}(collection1, collection2, new MyComparer()); - }} + [Fact] + public void TestMethod() {{ + var collection1 = new List(); + var collection2 = {1}; + + Assert.{0}(collection1, collection2); + Assert.{0}(collection1, collection2, (int e1, int e2) => true); + Assert.{0}(collection1, collection2, new MyComparer()); + }} }} """, method, collection); @@ -233,16 +233,16 @@ public async Task CastedSet_DoesNotTrigger() using System.Collections.Generic; public class TestClass { - [Fact] - public void TestMethod() { - var expected = new HashSet { "bar", "foo" }; - var actual = new HashSet { "foo", "bar" }; - - Assert.Equal(expected, actual); - Assert.Equal(expected, (ISet)actual); - Assert.Equal((ISet)expected, actual); - Assert.Equal((ISet)expected, (ISet)actual); - } + [Fact] + public void TestMethod() { + var expected = new HashSet { "bar", "foo" }; + var actual = new HashSet { "foo", "bar" }; + + Assert.Equal(expected, actual); + Assert.Equal(expected, (ISet)actual); + Assert.Equal((ISet)expected, actual); + Assert.Equal((ISet)expected, (ISet)actual); + } } """; @@ -252,10 +252,11 @@ public void TestMethod() { public static MatrixTheoryData MethodAndTypeAndInitializer => new( /* lang=c#-test */ ["Equal", "NotEqual"], - /* lang=c#-test */ [ + /* lang=c#-test */ + [ ("System.Collections.Generic.HashSet", "new HashSet()"), - ("System.Collections.Immutable.ImmutableHashSet", "new HashSet().ToImmutableHashSet()"), - ("MySet", "new MySet()") + ("System.Collections.Immutable.ImmutableHashSet", "new HashSet().ToImmutableHashSet()"), + ("MySet", "new MySet()") ] ); @@ -272,19 +273,19 @@ public async Task SetWithLinearContainer_Triggers( using System.Linq; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var collection1 = new List(); - var collection2 = {1}; - - {{|#0:Assert.{0}(collection1, collection2)|}}; - {{|#1:Assert.{0}(collection1, collection2, (int e1, int e2) => true)|}}; - {{|#2:Assert.{0}(collection1, collection2, new MyComparer())|}}; - - {{|#3:Assert.{0}(collection2, collection1)|}}; - {{|#4:Assert.{0}(collection2, collection1, (int e1, int e2) => true)|}}; - {{|#5:Assert.{0}(collection2, collection1, new MyComparer())|}}; - }} + [Fact] + public void TestMethod() {{ + var collection1 = new List(); + var collection2 = {1}; + + {{|#0:Assert.{0}(collection1, collection2)|}}; + {{|#1:Assert.{0}(collection1, collection2, (int e1, int e2) => true)|}}; + {{|#2:Assert.{0}(collection1, collection2, new MyComparer())|}}; + + {{|#3:Assert.{0}(collection2, collection1)|}}; + {{|#4:Assert.{0}(collection2, collection1, (int e1, int e2) => true)|}}; + {{|#5:Assert.{0}(collection2, collection1, new MyComparer())|}}; + }} }} """, method, collection.initializer); var expected = new[] diff --git a/src/xunit.analyzers.tests/Analyzers/X2000/UseAssertFailInsteadOfBooleanAssertTests.cs b/src/xunit.analyzers.tests/Analyzers/X2000/UseAssertFailInsteadOfBooleanAssertTests.cs index 94d4f313..ae6a36cb 100644 --- a/src/xunit.analyzers.tests/Analyzers/X2000/UseAssertFailInsteadOfBooleanAssertTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X2000/UseAssertFailInsteadOfBooleanAssertTests.cs @@ -10,10 +10,10 @@ public class UseAssertFailInsteadOfBooleanAssertTests { const string codeTemplate = /* lang=c#-test */ """ public class TestClass {{ - [Xunit.Fact] - public void TestMethod() {{ - {{|#0:Xunit.Assert.{0}({1}, "failure message")|}}; - }} + [Xunit.Fact] + public void TestMethod() {{ + {{|#0:Xunit.Assert.{0}({1}, "failure message")|}}; + }} }} """; @@ -59,11 +59,11 @@ public async Task NonConstantInvocation_DoesNotTrigger() { var source = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { - var value = (1 != 2); - Xunit.Assert.False(value, "failure message"); - } + [Xunit.Fact] + public void TestMethod() { + var value = (1 != 2); + Xunit.Assert.False(value, "failure message"); + } } """; diff --git a/src/xunit.analyzers.tests/Analyzers/X3000/DoNotTestForConcreteTypeOfJsonSerializableTypesTests.cs b/src/xunit.analyzers.tests/Analyzers/X3000/DoNotTestForConcreteTypeOfJsonSerializableTypesTests.cs index 27e81ae8..348effd2 100644 --- a/src/xunit.analyzers.tests/Analyzers/X3000/DoNotTestForConcreteTypeOfJsonSerializableTypesTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X3000/DoNotTestForConcreteTypeOfJsonSerializableTypesTests.cs @@ -63,7 +63,7 @@ sealed partial class MyMessage : IMyMessage { } """; var messagePartial2 = /* lang=c#-test */ """ public partial class MyMessage { - public int PropertyValue { get; set; } + public int PropertyValue { get; set; } }; """; diff --git a/src/xunit.analyzers.tests/Analyzers/X3000/SerializableClassMustHaveParameterlessConstructorTests.cs b/src/xunit.analyzers.tests/Analyzers/X3000/SerializableClassMustHaveParameterlessConstructorTests.cs index 1b75bc42..886fd5e9 100644 --- a/src/xunit.analyzers.tests/Analyzers/X3000/SerializableClassMustHaveParameterlessConstructorTests.cs +++ b/src/xunit.analyzers.tests/Analyzers/X3000/SerializableClassMustHaveParameterlessConstructorTests.cs @@ -55,18 +55,18 @@ public class RunnerReporter public class {{|#0:MyRunnerReporter|}} : IRunnerReporter {{ - {0} - - public bool CanBeEnvironmentallyEnabled => false; - public string Description => string.Empty; - public bool ForceNoLogo => false; - public bool IsEnvironmentallyEnabled => false; - public string? RunnerSwitch => "unused"; - - public ValueTask CreateMessageHandler( - IRunnerLogger logger, - IMessageSink? diagnosticMessageSink) => - throw new NotImplementedException(); + {0} + + public bool CanBeEnvironmentallyEnabled => false; + public string Description => string.Empty; + public bool ForceNoLogo => false; + public bool IsEnvironmentallyEnabled => false; + public string? RunnerSwitch => "unused"; + + public ValueTask CreateMessageHandler( + IRunnerLogger logger, + IMessageSink? diagnosticMessageSink) => + throw new NotImplementedException(); }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/ClassDataAttributeMustPointAtValidClassFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/ClassDataAttributeMustPointAtValidClassFixerTests.cs index 0a9e3fe8..d9edf7d7 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/ClassDataAttributeMustPointAtValidClassFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/ClassDataAttributeMustPointAtValidClassFixerTests.cs @@ -16,9 +16,9 @@ public class TestData { } public class TestClass { - [Theory] - [{|xUnit1007:ClassData(typeof(TestData))|}] - public void TestMethod(int _) { } + [Theory] + [{|xUnit1007:ClassData(typeof(TestData))|}] + public void TestMethod(int _) { } } """; var afterV2 = /* lang=c#-test */ """ @@ -30,9 +30,9 @@ public class TestData : {|CS0535:{|CS0535:IEnumerable|}|} } public class TestClass { - [Theory] - [ClassData(typeof(TestData))] - public void TestMethod(int _) { } + [Theory] + [ClassData(typeof(TestData))] + public void TestMethod(int _) { } } """; var afterV3 = afterV2.Replace("ClassData(typeof(TestData))", "{|xUnit1050:ClassData(typeof(TestData))|}"); @@ -50,16 +50,16 @@ public async Task ConvertsParameterlessConstructorToPublic() using Xunit; public class TestData : IEnumerable { - TestData() { } + TestData() { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } public class TestClass { - [Theory] - [{|xUnit1007:ClassData(typeof(TestData))|}] - public void TestMethod(int _) { } + [Theory] + [{|xUnit1007:ClassData(typeof(TestData))|}] + public void TestMethod(int _) { } } """; var afterV2 = /* lang=c#-test */ """ @@ -68,16 +68,16 @@ public void TestMethod(int _) { } using Xunit; public class TestData : IEnumerable { - public TestData() { } + public TestData() { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } public class TestClass { - [Theory] - [ClassData(typeof(TestData))] - public void TestMethod(int _) { } + [Theory] + [ClassData(typeof(TestData))] + public void TestMethod(int _) { } } """; var afterV3 = afterV2.Replace("ClassData(typeof(TestData))", "{|xUnit1050:ClassData(typeof(TestData))|}"); @@ -95,16 +95,16 @@ public async Task AddsPublicParameterlessConstructor() using Xunit; public class TestData : IEnumerable { - TestData(int _) { } + TestData(int _) { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } public class TestClass { - [Theory] - [{|xUnit1007:ClassData(typeof(TestData))|}] - public void TestMethod(int _) { } + [Theory] + [{|xUnit1007:ClassData(typeof(TestData))|}] + public void TestMethod(int _) { } } """; var afterV2 = """ @@ -113,20 +113,20 @@ public void TestMethod(int _) { } using Xunit; public class TestData : IEnumerable { - TestData(int _) { } + TestData(int _) { } - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; - public TestData() - { - } + public TestData() + { + } } public class TestClass { - [Theory] - [ClassData(typeof(TestData))] - public void TestMethod(int _) { } + [Theory] + [ClassData(typeof(TestData))] + public void TestMethod(int _) { } } """; var afterV3 = afterV2.Replace("ClassData(typeof(TestData))", "{|xUnit1050:ClassData(typeof(TestData))|}"); @@ -144,14 +144,14 @@ public async Task RemovesAbstractModifierFromDataClass() using Xunit; public abstract class TestData : IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } public class TestClass { - [Theory] - [{|xUnit1007:ClassData(typeof(TestData))|}] - public void TestMethod(int _) { } + [Theory] + [{|xUnit1007:ClassData(typeof(TestData))|}] + public void TestMethod(int _) { } } """; var afterV2 = /* lang=c#-test */ """ @@ -160,14 +160,14 @@ public void TestMethod(int _) { } using Xunit; public class TestData : IEnumerable { - public IEnumerator GetEnumerator() => null; - IEnumerator IEnumerable.GetEnumerator() => null; + public IEnumerator GetEnumerator() => null; + IEnumerator IEnumerable.GetEnumerator() => null; } public class TestClass { - [Theory] - [ClassData(typeof(TestData))] - public void TestMethod(int _) { } + [Theory] + [ClassData(typeof(TestData))] + public void TestMethod(int _) { } } """; var afterV3 = afterV2.Replace("ClassData(typeof(TestData))", "{|xUnit1050:ClassData(typeof(TestData))|}"); diff --git a/src/xunit.analyzers.tests/Fixes/X1000/ConvertToFactFixTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/ConvertToFactFixTests.cs index 95d28f2a..6dececed 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/ConvertToFactFixTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/ConvertToFactFixTests.cs @@ -13,16 +13,16 @@ public async Task From_X1003() using Xunit; public class TestClass { - [Theory] - public void [|TestMethod|](int a) { } + [Theory] + public void [|TestMethod|](int a) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod(int a) { } + [Fact] + public void TestMethod(int a) { } } """; @@ -36,16 +36,16 @@ public async Task From_X1006() using Xunit; public class TestClass { - [Theory] - public void [|TestMethod|]() { } + [Theory] + public void [|TestMethod|]() { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/ConvertToTheoryFixTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/ConvertToTheoryFixTests.cs index 48182208..3ce69f38 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/ConvertToTheoryFixTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/ConvertToTheoryFixTests.cs @@ -13,16 +13,16 @@ public async Task From_X1001() using Xunit; public class TestClass { - [Fact] - public void [|TestMethod|](int a) { } + [Fact] + public void [|TestMethod|](int a) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - public void TestMethod(int a) { } + [Theory] + public void TestMethod(int a) { } } """; @@ -36,18 +36,18 @@ public async Task From_X1005() using Xunit; public class TestClass { - [Fact] - [InlineData(42)] - public void [|TestMethod|]() { } + [Fact] + [InlineData(42)] + public void [|TestMethod|]() { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(42)] - public void TestMethod() { } + [Theory] + [InlineData(42)] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/DataAttributeShouldBeUsedOnATheoryFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/DataAttributeShouldBeUsedOnATheoryFixerTests.cs index e20ee09c..d6c31ac4 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/DataAttributeShouldBeUsedOnATheoryFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/DataAttributeShouldBeUsedOnATheoryFixerTests.cs @@ -12,17 +12,17 @@ public async Task AddsMissingTheoryAttribute() using Xunit; public class TestClass { - [InlineData] - public void [|TestMethod|]() { } + [InlineData] + public void [|TestMethod|]() { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData] - public void TestMethod() { } + [Theory] + [InlineData] + public void TestMethod() { } } """; @@ -36,15 +36,15 @@ public async Task RemovesDataAttributes() using Xunit; public class TestClass { - [InlineData] - public void [|TestMethod|]() { } + [InlineData] + public void [|TestMethod|]() { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - public void TestMethod() { } + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseAsyncVoidForTestMethodsFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseAsyncVoidForTestMethodsFixerTests.cs index 607b67a9..7db1e52f 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseAsyncVoidForTestMethodsFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseAsyncVoidForTestMethodsFixerTests.cs @@ -13,10 +13,10 @@ public async Task WithoutNamespace_ConvertsToTask() using Xunit; public class TestClass { - [Fact] - public async void {|xUnit1048:TestMethod|}() { - await System.Threading.Tasks.Task.Yield(); - } + [Fact] + public async void {|xUnit1048:TestMethod|}() { + await System.Threading.Tasks.Task.Yield(); + } } """; var beforeV3 = beforeV2.Replace("xUnit1048", "xUnit1049"); @@ -24,10 +24,10 @@ public class TestClass { using Xunit; public class TestClass { - [Fact] - public async System.Threading.Tasks.Task TestMethod() { - await System.Threading.Tasks.Task.Yield(); - } + [Fact] + public async System.Threading.Tasks.Task TestMethod() { + await System.Threading.Tasks.Task.Yield(); + } } """; @@ -43,10 +43,10 @@ public async Task WithNamespace_ConvertsToTask() using Xunit; public class TestClass { - [Fact] - public async void {|xUnit1048:TestMethod|}() { - await Task.Yield(); - } + [Fact] + public async void {|xUnit1048:TestMethod|}() { + await Task.Yield(); + } } """; var beforeV3 = beforeV2.Replace("xUnit1048", "xUnit1049"); @@ -55,10 +55,10 @@ public class TestClass { using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - await Task.Yield(); - } + [Fact] + public async Task TestMethod() { + await Task.Yield(); + } } """; @@ -73,20 +73,20 @@ public async Task WithoutNamespace_ConvertsToValueTask() using Xunit; public class TestClass { - [Fact] - public async void {|xUnit1049:TestMethod|}() { - await System.Threading.Tasks.Task.Yield(); - } + [Fact] + public async void {|xUnit1049:TestMethod|}() { + await System.Threading.Tasks.Task.Yield(); + } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public async System.Threading.Tasks.ValueTask TestMethod() { - await System.Threading.Tasks.Task.Yield(); - } + [Fact] + public async System.Threading.Tasks.ValueTask TestMethod() { + await System.Threading.Tasks.Task.Yield(); + } } """; @@ -101,10 +101,10 @@ public async Task WithNamespace_ConvertsToValueTask() using Xunit; public class TestClass { - [Fact] - public async void {|xUnit1049:TestMethod|}() { - await Task.Yield(); - } + [Fact] + public async void {|xUnit1049:TestMethod|}() { + await Task.Yield(); + } } """; var after = /* lang=c#-test */ """ @@ -112,10 +112,10 @@ public class TestClass { using Xunit; public class TestClass { - [Fact] - public async ValueTask TestMethod() { - await Task.Yield(); - } + [Fact] + public async ValueTask TestMethod() { + await Task.Yield(); + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseConfigureAwaitFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseConfigureAwaitFixerTests.cs index 4de4addd..d8843052 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseConfigureAwaitFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/DoNotUseConfigureAwaitFixerTests.cs @@ -26,11 +26,11 @@ public async Task Task_Async(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - await Task.Delay(1).[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + await Task.Delay(1).[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -38,11 +38,11 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - await Task.Delay(1); - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + await Task.Delay(1); + } } """; @@ -58,11 +58,11 @@ public async Task Task_NonAsync(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var booleanVar = true; - Task.Delay(1).[|ConfigureAwait({0})|].GetAwaiter().GetResult(); - }} + [Fact] + public void TestMethod() {{ + var booleanVar = true; + Task.Delay(1).[|ConfigureAwait({0})|].GetAwaiter().GetResult(); + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -70,11 +70,11 @@ public void TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var booleanVar = true; - Task.Delay(1).GetAwaiter().GetResult(); - } + [Fact] + public void TestMethod() { + var booleanVar = true; + Task.Delay(1).GetAwaiter().GetResult(); + } } """; @@ -90,12 +90,12 @@ public async Task TaskOfT(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var task = Task.FromResult(42); - await task.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var task = Task.FromResult(42); + await task.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -103,12 +103,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - var task = Task.FromResult(42); - await task; - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + var task = Task.FromResult(42); + await task; + } } """; @@ -124,12 +124,12 @@ public async Task ValueTask(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -137,12 +137,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask; - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask; + } } """; @@ -158,12 +158,12 @@ public async Task ValueTaskOfT(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -171,12 +171,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask; - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask; + } } """; @@ -195,11 +195,11 @@ public async Task Task_Async(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - await Task.Delay(1).[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + await Task.Delay(1).[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -207,11 +207,11 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - await Task.Delay(1).ConfigureAwait(true); - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + await Task.Delay(1).ConfigureAwait(true); + } } """; @@ -227,11 +227,11 @@ public async Task Task_NonAsync(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var booleanVar = true; - Task.Delay(1).[|ConfigureAwait({0})|].GetAwaiter().GetResult(); - }} + [Fact] + public void TestMethod() {{ + var booleanVar = true; + Task.Delay(1).[|ConfigureAwait({0})|].GetAwaiter().GetResult(); + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -239,11 +239,11 @@ public void TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var booleanVar = true; - Task.Delay(1).ConfigureAwait(true).GetAwaiter().GetResult(); - } + [Fact] + public void TestMethod() { + var booleanVar = true; + Task.Delay(1).ConfigureAwait(true).GetAwaiter().GetResult(); + } } """; @@ -259,12 +259,12 @@ public async Task TaskOfT(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var task = Task.FromResult(42); - await task.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var task = Task.FromResult(42); + await task.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -272,12 +272,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - var task = Task.FromResult(42); - await task.ConfigureAwait(true); - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + var task = Task.FromResult(42); + await task.ConfigureAwait(true); + } } """; @@ -293,12 +293,12 @@ public async Task ValueTask(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -306,12 +306,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.ConfigureAwait(true); - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.ConfigureAwait(true); + } } """; @@ -327,12 +327,12 @@ public async Task ValueTaskOfT(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = /* lang=c#-test */ """ @@ -340,12 +340,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass { - [Fact] - public async Task TestMethod() { - var booleanVar = true; - var valueTask = default(ValueTask); - await valueTask.ConfigureAwait(true); - } + [Fact] + public async Task TestMethod() { + var booleanVar = true; + var valueTask = default(ValueTask); + await valueTask.ConfigureAwait(true); + } } """; @@ -378,11 +378,11 @@ public async Task Task_Async(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - await Task.Delay(1).[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + await Task.Delay(1).[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = string.Format(/* lang=c#-test */ """ @@ -390,11 +390,11 @@ public async Task TestMethod() {{ using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - await Task.Delay(1).ConfigureAwait({0} | ConfigureAwaitOptions.ContinueOnCapturedContext); - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + await Task.Delay(1).ConfigureAwait({0} | ConfigureAwaitOptions.ContinueOnCapturedContext); + }} }} """, argumentValue); @@ -410,11 +410,11 @@ public async Task Task_NonAsync(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - Task.Delay(1).[|ConfigureAwait({0})|].GetAwaiter().GetResult(); - }} + [Fact] + public void TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + Task.Delay(1).[|ConfigureAwait({0})|].GetAwaiter().GetResult(); + }} }} """, argumentValue); var after = string.Format(/* lang=c#-test */ """ @@ -422,11 +422,11 @@ public void TestMethod() {{ using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - Task.Delay(1).ConfigureAwait({0} | ConfigureAwaitOptions.ContinueOnCapturedContext).GetAwaiter().GetResult(); - }} + [Fact] + public void TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + Task.Delay(1).ConfigureAwait({0} | ConfigureAwaitOptions.ContinueOnCapturedContext).GetAwaiter().GetResult(); + }} }} """, argumentValue); @@ -442,12 +442,12 @@ public async Task TaskOfT(string argumentValue) using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - var task = Task.FromResult(42); - await task.[|ConfigureAwait({0})|]; - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + var task = Task.FromResult(42); + await task.[|ConfigureAwait({0})|]; + }} }} """, argumentValue); var after = string.Format(/* lang=c#-test */ """ @@ -455,12 +455,12 @@ public async Task TestMethod() {{ using Xunit; public class TestClass {{ - [Fact] - public async Task TestMethod() {{ - var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; - var task = Task.FromResult(42); - await task.ConfigureAwait({0} | ConfigureAwaitOptions.ContinueOnCapturedContext); - }} + [Fact] + public async Task TestMethod() {{ + var enumVar = ConfigureAwaitOptions.ContinueOnCapturedContext; + var task = Task.FromResult(42); + await task.ConfigureAwait({0} | ConfigureAwaitOptions.ContinueOnCapturedContext); + }} }} """, argumentValue); diff --git a/src/xunit.analyzers.tests/Fixes/X1000/FactMethodMustNotHaveParametersFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/FactMethodMustNotHaveParametersFixerTests.cs index 5a234f3c..72717daf 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/FactMethodMustNotHaveParametersFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/FactMethodMustNotHaveParametersFixerTests.cs @@ -12,16 +12,16 @@ public async Task RemovesParameter() using Xunit; public class TestClass { - [Fact] - public void [|TestMethod|](int x) { } + [Fact] + public void [|TestMethod|](int x) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/FactMethodShouldNotHaveTestDataFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/FactMethodShouldNotHaveTestDataFixerTests.cs index 3f81641d..4ecf4d22 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/FactMethodShouldNotHaveTestDataFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/FactMethodShouldNotHaveTestDataFixerTests.cs @@ -12,17 +12,17 @@ public async Task RemovesDataAttribute() using Xunit; public class TestClass { - [Fact] - [InlineData(1)] - public void [|TestMethod|](int x) { } + [Fact] + [InlineData(1)] + public void [|TestMethod|](int x) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod(int x) { } + [Fact] + public void TestMethod(int x) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_ExtraValueFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_ExtraValueFixerTests.cs index 2202e113..7628175d 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_ExtraValueFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_ExtraValueFixerTests.cs @@ -12,18 +12,18 @@ public async Task RemovesUnusedData() using Xunit; public class TestClass { - [Theory] - [InlineData(42, {|xUnit1011:21.12|})] - public void TestMethod(int a) { } + [Theory] + [InlineData(42, {|xUnit1011:21.12|})] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(42)] - public void TestMethod(int a) { } + [Theory] + [InlineData(42)] + public void TestMethod(int a) { } } """; @@ -41,18 +41,18 @@ public async Task AddsParameterWithCorrectType( using Xunit; public class TestClass {{ - [Theory] - [InlineData(42, {{|xUnit1011:{0}|}})] - public void TestMethod(int a) {{ }} + [Theory] + [InlineData(42, {{|xUnit1011:{0}|}})] + public void TestMethod(int a) {{ }} }} """, value); var after = string.Format(/* lang=c#-test */ """ using Xunit; public class TestClass {{ - [Theory] - [InlineData(42, {0})] - public void TestMethod(int a, {1} p) {{ }} + [Theory] + [InlineData(42, {0})] + public void TestMethod(int a, {1} p) {{ }} }} """, value, valueType); @@ -66,18 +66,18 @@ public async Task AddsParameterWithNonConflictingName() using Xunit; public class TestClass { - [Theory] - [InlineData(42, {|xUnit1011:21.12|})] - public void TestMethod(int p) { } + [Theory] + [InlineData(42, {|xUnit1011:21.12|})] + public void TestMethod(int p) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(42, 21.12)] - public void TestMethod(int p, double p_2) { } + [Theory] + [InlineData(42, 21.12)] + public void TestMethod(int p, double p_2) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs index 7b3620cf..3728215e 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs @@ -13,18 +13,18 @@ public async Task MakesParameterNullable() using Xunit; public class TestClass { - [Theory] - [InlineData(42, {|xUnit1012:null|})] - public void TestMethod(int a, int b) { } + [Theory] + [InlineData(42, {|xUnit1012:null|})] + public void TestMethod(int a, int b) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(42, null)] - public void TestMethod(int a, int? b) { } + [Theory] + [InlineData(42, null)] + public void TestMethod(int a, int? b) { } } """; @@ -40,9 +40,9 @@ public async Task MakesReferenceParameterNullable() using Xunit; public class TestClass { - [Theory] - [InlineData(42, {|xUnit1012:null|})] - public void TestMethod(int a, object b) { } + [Theory] + [InlineData(42, {|xUnit1012:null|})] + public void TestMethod(int a, object b) { } } """; var after = /* lang=c#-test */ """ @@ -51,9 +51,9 @@ public void TestMethod(int a, object b) { } using Xunit; public class TestClass { - [Theory] - [InlineData(42, null)] - public void TestMethod(int a, object? b) { } + [Theory] + [InlineData(42, null)] + public void TestMethod(int a, object? b) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_TooFewValuesFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_TooFewValuesFixerTests.cs index a4b731c7..9fb3c53e 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_TooFewValuesFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataMustMatchTheoryParameters_TooFewValuesFixerTests.cs @@ -24,9 +24,9 @@ public async Task MakesParameterNullable( public enum Color {{ Red, Green, Blue }} public class TestClass {{ - [Theory] - [{{|xUnit1009:InlineData|}}] - public void TestMethod({0} p) {{ }} + [Theory] + [{{|xUnit1009:InlineData|}}] + public void TestMethod({0} p) {{ }} }} """, valueType); var after = string.Format(/* lang=c#-test */ """ @@ -35,9 +35,9 @@ public void TestMethod({0} p) {{ }} public enum Color {{ Red, Green, Blue }} public class TestClass {{ - [Theory] - [InlineData({1})] - public void TestMethod({0} p) {{ }} + [Theory] + [InlineData({1})] + public void TestMethod({0} p) {{ }} }} """, valueType, defaultValue); diff --git a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataShouldBeUniqueWithinTheoryFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataShouldBeUniqueWithinTheoryFixerTests.cs index 66abda92..85816940 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/InlineDataShouldBeUniqueWithinTheoryFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/InlineDataShouldBeUniqueWithinTheoryFixerTests.cs @@ -12,19 +12,19 @@ public async Task RemovesDuplicateData() using Xunit; public class TestClass { - [Theory] - [InlineData(1)] - [[|InlineData(1)|]] - public void TestMethod(int x) { } + [Theory] + [InlineData(1)] + [[|InlineData(1)|]] + public void TestMethod(int x) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(1)] - public void TestMethod(int x) { } + [Theory] + [InlineData(1)] + public void TestMethod(int x) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/LocalFunctionsCannotBeTestFunctionsFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/LocalFunctionsCannotBeTestFunctionsFixerTests.cs index 9de0dd50..e5685210 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/LocalFunctionsCannotBeTestFunctionsFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/LocalFunctionsCannotBeTestFunctionsFixerTests.cs @@ -15,21 +15,21 @@ public async Task LocalFunctionsCannotHaveTestAttributes(string attribute) using Xunit; public class TestClass {{ - public void Method() {{ - [[|{0}|]] - void LocalFunction() {{ - }} - }} + public void Method() {{ + [[|{0}|]] + void LocalFunction() {{ + }} + }} }} """, attribute); var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - public void Method() { - void LocalFunction() { - } - } + public void Method() { + void LocalFunction() { + } + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ExtraValueFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ExtraValueFixerTests.cs index 617c1ceb..8bd9d724 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ExtraValueFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ExtraValueFixerTests.cs @@ -12,22 +12,22 @@ public async Task RemovesUnusedData() using Xunit; public class TestClass { - public static TheoryData TestData(int n) => new TheoryData(); + public static TheoryData TestData(int n) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, {|xUnit1036:21.12|})] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(TestData), 42, {|xUnit1036:21.12|})] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - public static TheoryData TestData(int n) => new TheoryData(); + public static TheoryData TestData(int n) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42)] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(TestData), 42)] + public void TestMethod(int a) { } } """; @@ -45,22 +45,22 @@ public async Task AddsParameterWithCorrectType( using Xunit; public class TestClass {{ - public static TheoryData TestData(int n) => new TheoryData(); + public static TheoryData TestData(int n) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, {{|xUnit1036:{0}|}})] - public void TestMethod(int a) {{ }} + [Theory] + [MemberData(nameof(TestData), 42, {{|xUnit1036:{0}|}})] + public void TestMethod(int a) {{ }} }} """, value); var after = string.Format(/* lang=c#-test */ """ using Xunit; public class TestClass {{ - public static TheoryData TestData(int n, {1} p) => new TheoryData(); + public static TheoryData TestData(int n, {1} p) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, {0})] - public void TestMethod(int a) {{ }} + [Theory] + [MemberData(nameof(TestData), 42, {0})] + public void TestMethod(int a) {{ }} }} """, value, valueType); @@ -74,22 +74,22 @@ public async Task AddsParameterWithNonConflictingName() using Xunit; public class TestClass { - public static TheoryData TestData(int p) => new TheoryData(); + public static TheoryData TestData(int p) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, {|xUnit1036:21.12|})] - public void TestMethod(int n) { } + [Theory] + [MemberData(nameof(TestData), 42, {|xUnit1036:21.12|})] + public void TestMethod(int n) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - public static TheoryData TestData(int p, double p_2) => new TheoryData(); + public static TheoryData TestData(int p, double p_2) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, 21.12)] - public void TestMethod(int n) { } + [Theory] + [MemberData(nameof(TestData), 42, 21.12)] + public void TestMethod(int n) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NameOfFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NameOfFixerTests.cs index 08bb389b..0ef17674 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NameOfFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NameOfFixerTests.cs @@ -14,11 +14,11 @@ public async Task ConvertStringToNameOf() using Xunit; public class TestClass { - public static TheoryData DataSource; + public static TheoryData DataSource; - [Theory] - [MemberData({|xUnit1014:"DataSource"|})] - public void TestMethod(int a) { } + [Theory] + [MemberData({|xUnit1014:"DataSource"|})] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ @@ -27,11 +27,11 @@ public void TestMethod(int a) { } using Xunit; public class TestClass { - public static TheoryData DataSource; + public static TheoryData DataSource; - [Theory] - [MemberData(nameof(DataSource))] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(DataSource))] + public void TestMethod(int a) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs index e66d5e68..4d25bd65 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_NullShouldNotBeUsedForIncompatibleParameterFixerTests.cs @@ -13,22 +13,22 @@ public async Task MakesParameterNullable() using Xunit; public class TestClass { - public static TheoryData TestData(int n, int k) => new TheoryData(); + public static TheoryData TestData(int n, int k) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, {|xUnit1034:null|})] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(TestData), 42, {|xUnit1034:null|})] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - public static TheoryData TestData(int n, int? k) => new TheoryData(); + public static TheoryData TestData(int n, int? k) => new TheoryData(); - [Theory] - [MemberData(nameof(TestData), 42, null)] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(TestData), 42, null)] + public void TestMethod(int a) { } } """; @@ -44,11 +44,11 @@ public async Task MakesReferenceParameterNullable() using Xunit; public class TestClass { - public static TheoryData TestData(int n, string k) => new TheoryData { n }; + public static TheoryData TestData(int n, string k) => new TheoryData { n }; - [Theory] - [MemberData(nameof(TestData), 42, {|xUnit1034:null|})] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(TestData), 42, {|xUnit1034:null|})] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ @@ -57,11 +57,11 @@ public void TestMethod(int a) { } using Xunit; public class TestClass { - public static TheoryData TestData(int n, string? k) => new TheoryData { n }; + public static TheoryData TestData(int n, string? k) => new TheoryData { n }; - [Theory] - [MemberData(nameof(TestData), 42, null)] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(TestData), 42, null)] + public void TestMethod(int a) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ParamsForNonMethodFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ParamsForNonMethodFixerTests.cs index 3f137ad8..ce6b25b1 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ParamsForNonMethodFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ParamsForNonMethodFixerTests.cs @@ -15,11 +15,11 @@ public async Task RemovesParametersFromNonMethodMemberData() public class TestClass { - public static TheoryData DataSource = new TheoryData(); + public static TheoryData DataSource = new TheoryData(); - [Theory] - [MemberData(nameof(DataSource), {|xUnit1021:"abc", 123|})] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(DataSource), {|xUnit1021:"abc", 123|})] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ @@ -29,11 +29,11 @@ public void TestMethod(int a) { } public class TestClass { - public static TheoryData DataSource = new TheoryData(); + public static TheoryData DataSource = new TheoryData(); - [Theory] - [MemberData(nameof(DataSource))] - public void TestMethod(int a) { } + [Theory] + [MemberData(nameof(DataSource))] + public void TestMethod(int a) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ReturnTypeFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ReturnTypeFixerTests.cs index 244e6ddd..12bac8ae 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ReturnTypeFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_ReturnTypeFixerTests.cs @@ -13,11 +13,11 @@ public async Task ChangesReturnType_ObjectArray() using Xunit; public class TestClass { - public static IEnumerable Data => null; + public static IEnumerable Data => null; - [Theory] - [{|xUnit1019:MemberData(nameof(Data))|}] - public void TestMethod(int a) { } + [Theory] + [{|xUnit1019:MemberData(nameof(Data))|}] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ @@ -25,11 +25,11 @@ public void TestMethod(int a) { } using Xunit; public class TestClass { - public static IEnumerable Data => null; + public static IEnumerable Data => null; - [Theory] - [{|xUnit1042:MemberData(nameof(Data))|}] - public void TestMethod(int a) { } + [Theory] + [{|xUnit1042:MemberData(nameof(Data))|}] + public void TestMethod(int a) { } } """; @@ -44,11 +44,11 @@ public async Task ChangesReturnType_TheoryDataRow() using Xunit; public class TestClass { - public static IEnumerable Data => null; + public static IEnumerable Data => null; - [Theory] - [{|xUnit1019:MemberData(nameof(Data))|}] - public void TestMethod(int a) { } + [Theory] + [{|xUnit1019:MemberData(nameof(Data))|}] + public void TestMethod(int a) { } } """; var after = /* lang=c#-test */ """ @@ -56,11 +56,11 @@ public void TestMethod(int a) { } using Xunit; public class TestClass { - public static IEnumerable Data => null; + public static IEnumerable Data => null; - [Theory] - [{|xUnit1042:MemberData(nameof(Data))|}] - public void TestMethod(int a) { } + [Theory] + [{|xUnit1042:MemberData(nameof(Data))|}] + public void TestMethod(int a) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_StaticFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_StaticFixerTests.cs index f85ab4d3..e249212b 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_StaticFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_StaticFixerTests.cs @@ -13,11 +13,11 @@ public async Task MarksDataMemberAsStatic() using Xunit; public class TestClass { - public TheoryData TestData => null; + public TheoryData TestData => null; - [Theory] - [{|xUnit1017:MemberData(nameof(TestData))|}] - public void TestMethod(int x) { } + [Theory] + [{|xUnit1017:MemberData(nameof(TestData))|}] + public void TestMethod(int x) { } } """; var after = /* lang=c#-test */ """ @@ -25,11 +25,11 @@ public void TestMethod(int x) { } using Xunit; public class TestClass { - public static TheoryData TestData => null; + public static TheoryData TestData => null; - [Theory] - [MemberData(nameof(TestData))] - public void TestMethod(int x) { } + [Theory] + [MemberData(nameof(TestData))] + public void TestMethod(int x) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_VisibilityFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_VisibilityFixerTests.cs index e183daff..60f7decb 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_VisibilityFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/MemberDataShouldReferenceValidMember_VisibilityFixerTests.cs @@ -16,11 +16,11 @@ public async Task SetsPublicModifier(string badModifier) using Xunit; public class TestClass {{ - {0}static TheoryData TestData => null; + {0}static TheoryData TestData => null; - [Theory] - [{{|xUnit1016:MemberData(nameof(TestData))|}}] - public void TestMethod(int x) {{ }} + [Theory] + [{{|xUnit1016:MemberData(nameof(TestData))|}}] + public void TestMethod(int x) {{ }} }} """, badModifier); var after = /* lang=c#-test */ """ @@ -28,11 +28,11 @@ public void TestMethod(int x) {{ }} using Xunit; public class TestClass { - public static TheoryData TestData => null; + public static TheoryData TestData => null; - [Theory] - [MemberData(nameof(TestData))] - public void TestMethod(int x) { } + [Theory] + [MemberData(nameof(TestData))] + public void TestMethod(int x) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/PublicMethodShouldBeMarkedAsTestFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/PublicMethodShouldBeMarkedAsTestFixerTests.cs index 97ba1c88..2a8426eb 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/PublicMethodShouldBeMarkedAsTestFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/PublicMethodShouldBeMarkedAsTestFixerTests.cs @@ -9,20 +9,20 @@ public class PublicMethodShouldBeMarkedAsTestFixerTests using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } - public void [|TestMethod2|]() { } + public void [|TestMethod2|]() { } } """; const string beforeWithParams = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } - public void [|TestMethod2|](int _) { } + public void [|TestMethod2|](int _) { } } """; @@ -33,11 +33,11 @@ public async Task AddsFactToPublicMethodWithoutParameters() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } - [Fact] - public void TestMethod2() { } + [Fact] + public void TestMethod2() { } } """; @@ -51,11 +51,11 @@ public async Task AddsFactToPublicMethodWithParameters() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } - [Theory] - public void TestMethod2(int _) { } + [Theory] + public void TestMethod2(int _) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/RemoveMethodParameterFixTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/RemoveMethodParameterFixTests.cs index a1326d35..a9b1f8f7 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/RemoveMethodParameterFixTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/RemoveMethodParameterFixTests.cs @@ -16,18 +16,18 @@ public async Task X1022_RemoveParamsArray() using Xunit; public class TestClass { - [Theory] - [InlineData(1, 2, 3)] - public void TestMethod([|params int[] values|]) { } + [Theory] + [InlineData(1, 2, 3)] + public void TestMethod([|params int[] values|]) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(1, 2, 3)] - public void TestMethod() { } + [Theory] + [InlineData(1, 2, 3)] + public void TestMethod() { } } """; @@ -41,18 +41,18 @@ public async Task X1026_RemovesUnusedParameter() using Xunit; public class TestClass { - [Theory] - [InlineData(1)] - public void TestMethod(int [|arg|]) { } + [Theory] + [InlineData(1)] + public void TestMethod(int [|arg|]) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(1)] - public void TestMethod() { } + [Theory] + [InlineData(1)] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/TestClassCannotBeNestedInGenericClassFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/TestClassCannotBeNestedInGenericClassFixerTests.cs index 6c317b45..59dcf498 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/TestClassCannotBeNestedInGenericClassFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/TestClassCannotBeNestedInGenericClassFixerTests.cs @@ -11,11 +11,11 @@ public async Task MovesTestClassOutOfGenericParent() const string before = /* lang=c#-test */ """ public abstract class OpenGenericType { - public class [|NestedTestClass|] - { - [Xunit.Fact] - public void TestMethod() { } - } + public class [|NestedTestClass|] + { + [Xunit.Fact] + public void TestMethod() { } + } } """; const string after = /* lang=c#-test */ """ @@ -25,8 +25,8 @@ public abstract class OpenGenericType public class NestedTestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/TestClassMustBePublicFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/TestClassMustBePublicFixerTests.cs index c553ad4a..72aaf4eb 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/TestClassMustBePublicFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/TestClassMustBePublicFixerTests.cs @@ -12,14 +12,14 @@ public async Task MakesClassPublic(string nonPublicAccessModifier) { var before = string.Format(/* lang=c#-test */ """ {0}class [|TestClass|] {{ - [Xunit.Fact] - public void TestMethod() {{ }} + [Xunit.Fact] + public void TestMethod() {{ }} }} """, nonPublicAccessModifier); var after = /* lang=c#-test */ """ public class TestClass { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -31,24 +31,24 @@ public async Task ForPartialClassDeclarations_MakesSingleDeclarationPublic() { var before = /* lang=c#-test */ """ partial class [|TestClass|] { - [Xunit.Fact] - public void TestMethod1() {} + [Xunit.Fact] + public void TestMethod1() {} } partial class TestClass { - [Xunit.Fact] - public void TestMethod2() {} + [Xunit.Fact] + public void TestMethod2() {} } """; var after = /* lang=c#-test */ """ public partial class TestClass { - [Xunit.Fact] - public void TestMethod1() {} + [Xunit.Fact] + public void TestMethod1() {} } partial class TestClass { - [Xunit.Fact] - public void TestMethod2() {} + [Xunit.Fact] + public void TestMethod2() {} } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/TestClassShouldHaveTFixtureArgumentFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/TestClassShouldHaveTFixtureArgumentFixerTests.cs index 3e8ee87a..083da9fb 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/TestClassShouldHaveTFixtureArgumentFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/TestClassShouldHaveTFixtureArgumentFixerTests.cs @@ -12,23 +12,23 @@ public async Task ForClassWithoutField_GenerateFieldAndConstructor() public class FixtureData { } public class [|TestClass|]: Xunit.IClassFixture { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; var after = /* lang=c#-test */ """ public class FixtureData { } public class TestClass: Xunit.IClassFixture { - private readonly FixtureData _fixtureData; + private readonly FixtureData _fixtureData; - public TestClass(FixtureData fixtureData) - { - _fixtureData = fixtureData; - } + public TestClass(FixtureData fixtureData) + { + _fixtureData = fixtureData; + } - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; @@ -42,23 +42,23 @@ public async Task ForGenericTFixture_GenerateFieldAndConstructor() public class FixtureData { } public class [|TestClass|]: Xunit.IClassFixture> { - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; var after = /* lang=c#-test */ """ public class FixtureData { } public class TestClass: Xunit.IClassFixture> { - private readonly FixtureData _fixtureData; + private readonly FixtureData _fixtureData; - public TestClass(FixtureData fixtureData) - { - _fixtureData = fixtureData; - } + public TestClass(FixtureData fixtureData) + { + _fixtureData = fixtureData; + } - [Xunit.Fact] - public void TestMethod() { } + [Xunit.Fact] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/TestMethodMustNotHaveMultipleFactAttributesFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/TestMethodMustNotHaveMultipleFactAttributesFixerTests.cs index f8c97373..c100deaf 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/TestMethodMustNotHaveMultipleFactAttributesFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/TestMethodMustNotHaveMultipleFactAttributesFixerTests.cs @@ -14,9 +14,9 @@ public async Task RemovesSecondAttribute() public class FactDerivedAttribute : FactAttribute { } public class TestClass { - [Fact] - [{|CS0579:Fact|}] - public void [|TestMethod|]() { } + [Fact] + [{|CS0579:Fact|}] + public void [|TestMethod|]() { } } """; var after = /* lang=c#-test */ """ @@ -25,8 +25,8 @@ public class TestClass { public class FactDerivedAttribute : FactAttribute { } public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/TestMethodShouldNotBeSkippedFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/TestMethodShouldNotBeSkippedFixerTests.cs index 5e52ed53..4ed7ebed 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/TestMethodShouldNotBeSkippedFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/TestMethodShouldNotBeSkippedFixerTests.cs @@ -12,16 +12,16 @@ public async Task RemovesSkipProperty() using Xunit; public class TestClass { - [Fact([|Skip = "Don't run this"|])] - public void TestMethod() { } + [Fact([|Skip = "Don't run this"|])] + public void TestMethod() { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { } + [Fact] + public void TestMethod() { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/TheoryMethodCannotHaveDefaultParameterFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/TheoryMethodCannotHaveDefaultParameterFixerTests.cs index a51e71af..363a576f 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/TheoryMethodCannotHaveDefaultParameterFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/TheoryMethodCannotHaveDefaultParameterFixerTests.cs @@ -15,18 +15,18 @@ public async Task RemovesDefaultParameterValue() using Xunit; public class TestClass { - [Theory] - [InlineData(1)] - public void TestMethod(int _ [|= 0|]) { } + [Theory] + [InlineData(1)] + public void TestMethod(int _ [|= 0|]) { } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Theory] - [InlineData(1)] - public void TestMethod(int _) { } + [Theory] + [InlineData(1)] + public void TestMethod(int _) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X1000/UseCancellationTokenFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X1000/UseCancellationTokenFixerTests.cs index c31a2913..7dd97054 100644 --- a/src/xunit.analyzers.tests/Fixes/X1000/UseCancellationTokenFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X1000/UseCancellationTokenFixerTests.cs @@ -14,22 +14,22 @@ public async Task UseCancellationTokenArgument() using Xunit; public class TestClass { - [Fact] - public void TestMethod() - { - [|FunctionWithOverload(42)|]; - [|FunctionWithOverload(42, default(CancellationToken))|]; + [Fact] + public void TestMethod() + { + [|FunctionWithOverload(42)|]; + [|FunctionWithOverload(42, default(CancellationToken))|]; - [|FunctionWithDefaults()|]; - [|FunctionWithDefaults(42)|]; - [|FunctionWithDefaults(cancellationToken: default(CancellationToken))|]; - [|FunctionWithDefaults(42, cancellationToken: default(CancellationToken))|]; - } + [|FunctionWithDefaults()|]; + [|FunctionWithDefaults(42)|]; + [|FunctionWithDefaults(cancellationToken: default(CancellationToken))|]; + [|FunctionWithDefaults(42, cancellationToken: default(CancellationToken))|]; + } - void FunctionWithOverload(int _) { } - void FunctionWithOverload(int _1, CancellationToken _2) { } + void FunctionWithOverload(int _) { } + void FunctionWithOverload(int _1, CancellationToken _2) { } - void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default(CancellationToken)) { } + void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default(CancellationToken)) { } } """; var after = /* lang=c#-test */ """ @@ -38,22 +38,22 @@ void FunctionWithOverload(int _1, CancellationToken _2) { } using Xunit; public class TestClass { - [Fact] - public void TestMethod() - { - FunctionWithOverload(42, TestContext.Current.CancellationToken); - FunctionWithOverload(42, TestContext.Current.CancellationToken); + [Fact] + public void TestMethod() + { + FunctionWithOverload(42, TestContext.Current.CancellationToken); + FunctionWithOverload(42, TestContext.Current.CancellationToken); - FunctionWithDefaults(cancellationToken: TestContext.Current.CancellationToken); - FunctionWithDefaults(42, TestContext.Current.CancellationToken); - FunctionWithDefaults(cancellationToken: TestContext.Current.CancellationToken); - FunctionWithDefaults(42, cancellationToken: TestContext.Current.CancellationToken); - } + FunctionWithDefaults(cancellationToken: TestContext.Current.CancellationToken); + FunctionWithDefaults(42, TestContext.Current.CancellationToken); + FunctionWithDefaults(cancellationToken: TestContext.Current.CancellationToken); + FunctionWithDefaults(42, cancellationToken: TestContext.Current.CancellationToken); + } - void FunctionWithOverload(int _) { } - void FunctionWithOverload(int _1, CancellationToken _2) { } + void FunctionWithOverload(int _) { } + void FunctionWithOverload(int _1, CancellationToken _2) { } - void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default(CancellationToken)) { } + void FunctionWithDefaults(int _1 = 2112, CancellationToken cancellationToken = default(CancellationToken)) { } } """; @@ -69,13 +69,13 @@ public async Task UseCancellationTokenArgument_AliasTestContext() using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - [|Function()|]; - } + [Xunit.Fact] + public void TestMethod() + { + [|Function()|]; + } - void Function(CancellationToken token = default(CancellationToken)) { } + void Function(CancellationToken token = default(CancellationToken)) { } } """; var after = /* lang=c#-test */ """ @@ -84,13 +84,13 @@ public void TestMethod() using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - Function(MyContext.Current.CancellationToken); - } + [Xunit.Fact] + public void TestMethod() + { + Function(MyContext.Current.CancellationToken); + } - void Function(CancellationToken token = default(CancellationToken)) { } + void Function(CancellationToken token = default(CancellationToken)) { } } """; @@ -106,15 +106,15 @@ public async Task UseCancellationTokenArgument_ParamsArgument() using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - [|Function(1, 2, 3)|]; - } + [Xunit.Fact] + public void TestMethod() + { + [|Function(1, 2, 3)|]; + } - void Function(params int[] integers) { } + void Function(params int[] integers) { } - void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } + void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } } """; var after = /* lang=c#-test */ """ @@ -123,15 +123,15 @@ void Function(params int[] integers) { } using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - Function(new int[] { 1, 2, 3 }, MyContext.Current.CancellationToken); - } + [Xunit.Fact] + public void TestMethod() + { + Function(new int[] { 1, 2, 3 }, MyContext.Current.CancellationToken); + } - void Function(params int[] integers) { } + void Function(params int[] integers) { } - void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } + void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } } """; @@ -147,15 +147,15 @@ public async Task UseCancellationTokenArgument_ParamsArgumentAfterRegularArgumen using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - [|Function("hello", System.Guid.NewGuid(), System.Guid.NewGuid())|]; - } + [Xunit.Fact] + public void TestMethod() + { + [|Function("hello", System.Guid.NewGuid(), System.Guid.NewGuid())|]; + } - void Function(string str, params System.Guid[] guids) { } + void Function(string str, params System.Guid[] guids) { } - void Function(string str, System.Guid[] guids, CancellationToken token = default(CancellationToken)) { } + void Function(string str, System.Guid[] guids, CancellationToken token = default(CancellationToken)) { } } """; var after = /* lang=c#-test */ """ @@ -164,15 +164,15 @@ void Function(string str, params System.Guid[] guids) { } using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - Function("hello", new System.Guid[] { System.Guid.NewGuid(), System.Guid.NewGuid() }, MyContext.Current.CancellationToken); - } + [Xunit.Fact] + public void TestMethod() + { + Function("hello", new System.Guid[] { System.Guid.NewGuid(), System.Guid.NewGuid() }, MyContext.Current.CancellationToken); + } - void Function(string str, params System.Guid[] guids) { } + void Function(string str, params System.Guid[] guids) { } - void Function(string str, System.Guid[] guids, CancellationToken token = default(CancellationToken)) { } + void Function(string str, System.Guid[] guids, CancellationToken token = default(CancellationToken)) { } } """; @@ -188,15 +188,15 @@ public async Task UseCancellationTokenArgument_ParamsArgumentWithNoValues() using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - [|Function()|]; - } + [Xunit.Fact] + public void TestMethod() + { + [|Function()|]; + } - void Function(params int[] integers) { } + void Function(params int[] integers) { } - void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } + void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } } """; var after = /* lang=c#-test */ """ @@ -205,15 +205,15 @@ void Function(params int[] integers) { } using MyContext = Xunit.TestContext; public class TestClass { - [Xunit.Fact] - public void TestMethod() - { - Function(new int[] { }, MyContext.Current.CancellationToken); - } + [Xunit.Fact] + public void TestMethod() + { + Function(new int[] { }, MyContext.Current.CancellationToken); + } - void Function(params int[] integers) { } + void Function(params int[] integers) { } - void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } + void Function(int[] integers, CancellationToken token = default(CancellationToken)) { } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertCollectionContainsShouldNotUseBoolCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertCollectionContainsShouldNotUseBoolCheckFixerTests.cs index 8983b1d0..38e54c8c 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertCollectionContainsShouldNotUseBoolCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertCollectionContainsShouldNotUseBoolCheckFixerTests.cs @@ -11,12 +11,12 @@ public class AssertCollectionContainsShouldNotUseBoolCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var items = new[] {{ "a", "b", "c" }}; + [Fact] + public void TestMethod() {{ + var items = new[] {{ "a", "b", "c" }}; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyCollectionCheckShouldNotBeUsedFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyCollectionCheckShouldNotBeUsedFixerTests.cs index 8cc9e076..959024c8 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyCollectionCheckShouldNotBeUsedFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyCollectionCheckShouldNotBeUsedFixerTests.cs @@ -9,12 +9,12 @@ public class AssertEmptyCollectionCheckShouldNotBeUsedFixerTests using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var collection = new[] { 1, 2, 3 }; + [Fact] + public void TestMethod() { + var collection = new[] { 1, 2, 3 }; - [|Assert.Collection(collection)|]; - } + [|Assert.Collection(collection)|]; + } } """; @@ -25,12 +25,12 @@ public async Task UseEmptyCheck() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var collection = new[] { 1, 2, 3 }; + [Fact] + public void TestMethod() { + var collection = new[] { 1, 2, 3 }; - Assert.Empty(collection); - } + Assert.Empty(collection); + } } """; @@ -44,12 +44,12 @@ public async Task AddElementInspector() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var collection = new[] { 1, 2, 3 }; + [Fact] + public void TestMethod() { + var collection = new[] { 1, 2, 3 }; - Assert.Collection(collection, x => { }); - } + Assert.Collection(collection, x => { }); + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests.cs index 5a283645..689104db 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests.cs @@ -10,12 +10,12 @@ public class AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var list = new[] {{ -1, 0, 1, 2 }}; + [Fact] + public void TestMethod() {{ + var list = new[] {{ -1, 0, 1, 2 }}; - {0}; - }} + {0}; + }} public bool IsEven(int num) => num % 2 == 0; }} diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckFixerTests.cs index b69ff610..4997d2f8 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckFixerTests.cs @@ -10,12 +10,12 @@ public class AssertEnumerableAnyCheckShouldNotBeUsedForCollectionContainsCheckFi using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var collection = new[] {{ 1, 2, 3 }}; + [Fact] + public void TestMethod() {{ + var collection = new[] {{ 1, 2, 3 }}; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualGenericShouldNotBeUsedForStringValueFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualGenericShouldNotBeUsedForStringValueFixerTests.cs index 826ed162..594c2ee5 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualGenericShouldNotBeUsedForStringValueFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualGenericShouldNotBeUsedForStringValueFixerTests.cs @@ -10,12 +10,12 @@ public class AssertEqualGenericShouldNotBeUsedForStringValueFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - string result = "foo"; + [Fact] + public void TestMethod() {{ + string result = "foo"; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualLiteralValueShouldBeFirstFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualLiteralValueShouldBeFirstFixerTests.cs index 4c676191..e147d7c5 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualLiteralValueShouldBeFirstFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualLiteralValueShouldBeFirstFixerTests.cs @@ -10,11 +10,11 @@ public class AssertEqualLiteralValueShouldBeFirstFixerTests using System.Collections.Generic; public class TestClass {{ - [Xunit.Fact] - public void TestMethod() {{ - var i = 0; - [|Xunit.{0}|]; - }} + [Xunit.Fact] + public void TestMethod() {{ + var i = 0; + [|Xunit.{0}|]; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualPrecisionShouldBeInRangeFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualPrecisionShouldBeInRangeFixerTests.cs index be8df4a8..3c1ce028 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualPrecisionShouldBeInRangeFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualPrecisionShouldBeInRangeFixerTests.cs @@ -9,10 +9,10 @@ public class AssertEqualPrecisionShouldBeInRangeFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - {0}; - }} + [Fact] + public void TestMethod() {{ + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckFixerTests.cs index 746b1b39..f2e3d8ff 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForBoolLiteralCheckFixerTests.cs @@ -9,12 +9,12 @@ public class AssertEqualShouldNotBeUsedForBoolLiteralCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var actual = true; + [Fact] + public void TestMethod() {{ + var actual = true; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckFixerTests.cs index f3efd68f..8d20142b 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForCollectionSizeCheckFixerTests.cs @@ -10,12 +10,12 @@ public class AssertEqualShouldNotBeUsedForCollectionSizeCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = new[] {{ 1, 2, 3 }}; + [Fact] + public void TestMethod() {{ + var data = new[] {{ 1, 2, 3 }}; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForNullCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForNullCheckFixerTests.cs index 8621a9a5..07b0b326 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForNullCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualShouldNotBeUsedForNullCheckFixerTests.cs @@ -9,12 +9,12 @@ public class AssertEqualShouldNotBeUsedForNullCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - int? data = 1; + [Fact] + public void TestMethod() {{ + int? data = 1; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualsShouldNotBeUsedFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualsShouldNotBeUsedFixerTests.cs index 054dc878..4a0e5663 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualsShouldNotBeUsedFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertEqualsShouldNotBeUsedFixerTests.cs @@ -9,12 +9,12 @@ public class AssertEqualsShouldNotBeUsedFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = 1; + [Fact] + public void TestMethod() {{ + var data = 1; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeFixerTests.cs index 6bf3a3fb..09a593c9 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertIsTypeShouldNotBeUsedForAbstractTypeFixerTests.cs @@ -18,15 +18,15 @@ public async Task Conversions_WithoutExactMatch() using Xunit; public abstract class TestClass { - [Fact] - public void TestMethod() { - var data = new object(); + [Fact] + public void TestMethod() { + var data = new object(); - [|Assert.IsType(data)|]; - [|Assert.IsType(data)|]; - [|Assert.IsNotType(data)|]; - [|Assert.IsNotType(data)|]; - } + [|Assert.IsType(data)|]; + [|Assert.IsType(data)|]; + [|Assert.IsNotType(data)|]; + [|Assert.IsNotType(data)|]; + } } """; var after = /* lang=c#-test */ """ @@ -34,15 +34,15 @@ public void TestMethod() { using Xunit; public abstract class TestClass { - [Fact] - public void TestMethod() { - var data = new object(); + [Fact] + public void TestMethod() { + var data = new object(); - Assert.IsAssignableFrom(data); - Assert.IsAssignableFrom(data); - Assert.IsNotAssignableFrom(data); - Assert.IsNotAssignableFrom(data); - } + Assert.IsAssignableFrom(data); + Assert.IsAssignableFrom(data); + Assert.IsNotAssignableFrom(data); + Assert.IsNotAssignableFrom(data); + } } """; @@ -58,23 +58,23 @@ public async Task Conversions_WithExactMatch() using Xunit; public abstract class TestClass { - [Fact] - public void TestMethod() { - var data = new object(); + [Fact] + public void TestMethod() { + var data = new object(); - [|Assert.IsType(data)|]; - [|Assert.IsType(data, true)|]; - [|Assert.IsType(data, exactMatch: true)|]; - [|Assert.IsType(data)|]; - [|Assert.IsType(data, true)|]; - [|Assert.IsType(data, exactMatch: true)|]; - [|Assert.IsNotType(data)|]; - [|Assert.IsNotType(data, true)|]; - [|Assert.IsNotType(data, exactMatch: true)|]; - [|Assert.IsNotType(data)|]; - [|Assert.IsNotType(data, true)|]; - [|Assert.IsNotType(data, exactMatch: true)|]; - } + [|Assert.IsType(data)|]; + [|Assert.IsType(data, true)|]; + [|Assert.IsType(data, exactMatch: true)|]; + [|Assert.IsType(data)|]; + [|Assert.IsType(data, true)|]; + [|Assert.IsType(data, exactMatch: true)|]; + [|Assert.IsNotType(data)|]; + [|Assert.IsNotType(data, true)|]; + [|Assert.IsNotType(data, exactMatch: true)|]; + [|Assert.IsNotType(data)|]; + [|Assert.IsNotType(data, true)|]; + [|Assert.IsNotType(data, exactMatch: true)|]; + } } """; var after = /* lang=c#-test */ """ @@ -82,23 +82,23 @@ public void TestMethod() { using Xunit; public abstract class TestClass { - [Fact] - public void TestMethod() { - var data = new object(); + [Fact] + public void TestMethod() { + var data = new object(); - Assert.IsType(data, exactMatch: false); - Assert.IsType(data, exactMatch: false); - Assert.IsType(data, exactMatch: false); - Assert.IsType(data, exactMatch: false); - Assert.IsType(data, exactMatch: false); - Assert.IsType(data, exactMatch: false); - Assert.IsNotType(data, exactMatch: false); - Assert.IsNotType(data, exactMatch: false); - Assert.IsNotType(data, exactMatch: false); - Assert.IsNotType(data, exactMatch: false); - Assert.IsNotType(data, exactMatch: false); - Assert.IsNotType(data, exactMatch: false); - } + Assert.IsType(data, exactMatch: false); + Assert.IsType(data, exactMatch: false); + Assert.IsType(data, exactMatch: false); + Assert.IsType(data, exactMatch: false); + Assert.IsType(data, exactMatch: false); + Assert.IsType(data, exactMatch: false); + Assert.IsNotType(data, exactMatch: false); + Assert.IsNotType(data, exactMatch: false); + Assert.IsNotType(data, exactMatch: false); + Assert.IsNotType(data, exactMatch: false); + Assert.IsNotType(data, exactMatch: false); + Assert.IsNotType(data, exactMatch: false); + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertNullShouldNotBeCalledOnValueTypesFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertNullShouldNotBeCalledOnValueTypesFixerTests.cs index 7324379b..a4878d49 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertNullShouldNotBeCalledOnValueTypesFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertNullShouldNotBeCalledOnValueTypesFixerTests.cs @@ -12,22 +12,22 @@ public async Task ForValueTypeNullAssert_RemovesAssertion() using Xunit; public class Tests { - [Fact] - public void TestMethod() { - int i = 1; + [Fact] + public void TestMethod() { + int i = 1; - [|Assert.NotNull(i)|]; - } + [|Assert.NotNull(i)|]; + } } """; const string after = /* lang=c#-test */ """ using Xunit; public class Tests { - [Fact] - public void TestMethod() { - int i = 1; - } + [Fact] + public void TestMethod() { + int i = 1; + } } """; @@ -43,17 +43,17 @@ public async Task ForAssertionWithTrivia_RemovesAssertionAndLeavesLeadingTriviaI using Xunit; namespace XUnitTestProject1 { - public class UnitTest1 { - [Fact] - public void Test1() { - int i = 1; + public class UnitTest1 { + [Fact] + public void Test1() { + int i = 1; - // I am a comment which gets deleted by the quick fix - // Assert - [|Assert.NotNull(i)|]; - Assert.Null(null); - } - } + // I am a comment which gets deleted by the quick fix + // Assert + [|Assert.NotNull(i)|]; + Assert.Null(null); + } + } } """; const string after = /* lang=c#-test */ """ @@ -61,16 +61,16 @@ public void Test1() { using Xunit; namespace XUnitTestProject1 { - public class UnitTest1 { - [Fact] - public void Test1() { - int i = 1; + public class UnitTest1 { + [Fact] + public void Test1() { + int i = 1; - // I am a comment which gets deleted by the quick fix - // Assert - Assert.Null(null); - } - } + // I am a comment which gets deleted by the quick fix + // Assert + Assert.Null(null); + } + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckFixerTests.cs index cb658e88..0ad9f38c 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertRegexMatchShouldNotUseBoolLiteralCheckFixerTests.cs @@ -10,12 +10,12 @@ public class AssertRegexMatchShouldNotUseBoolLiteralCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var result = "foo bar baz"; + [Fact] + public void TestMethod() {{ + var result = "foo bar baz"; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertSameShouldNotBeCalledOnValueTypesFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertSameShouldNotBeCalledOnValueTypesFixerTests.cs index b779fe2d..fc198de4 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertSameShouldNotBeCalledOnValueTypesFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertSameShouldNotBeCalledOnValueTypesFixerTests.cs @@ -9,12 +9,12 @@ public class AssertSameShouldNotBeCalledOnValueTypesFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = 1; + [Fact] + public void TestMethod() {{ + var data = 1; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldBeUsedForSingleParameterFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldBeUsedForSingleParameterFixerTests.cs index 442de3b0..00691af3 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldBeUsedForSingleParameterFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldBeUsedForSingleParameterFixerTests.cs @@ -10,122 +10,122 @@ public class AssertSingleShouldBeUsedForSingleParameterFixerTests { { /* lang=c#-test */ """ - [|Assert.Collection(collection, item => Assert.NotNull(item))|] + [|Assert.Collection(collection, item => Assert.NotNull(item))|] """, /* lang=c#-test */ """ - var item = Assert.Single(collection); - Assert.NotNull(item); + var item = Assert.Single(collection); + Assert.NotNull(item); """ }, { /* lang=c#-test */ """ - var item = 42; - [|Assert.Collection(collection, item => Assert.NotNull(item))|] + var item = 42; + [|Assert.Collection(collection, item => Assert.NotNull(item))|] """, /* lang=c#-test */ """ - var item = 42; - var item_2 = Assert.Single(collection); - Assert.NotNull(item_2); + var item = 42; + var item_2 = Assert.Single(collection); + Assert.NotNull(item_2); """ }, { /* lang=c#-test */ """ - [|Assert.Collection(collection, item => { Assert.NotNull(item); })|] + [|Assert.Collection(collection, item => { Assert.NotNull(item); })|] """, /* lang=c#-test */ """ - var item = Assert.Single(collection); - Assert.NotNull(item); + var item = Assert.Single(collection); + Assert.NotNull(item); """ }, { /* lang=c#-test */ """ - var item = 42; - [|Assert.Collection(collection, item => { Assert.NotNull(item); })|] + var item = 42; + [|Assert.Collection(collection, item => { Assert.NotNull(item); })|] """, /* lang=c#-test */ """ - var item = 42; - var item_2 = Assert.Single(collection); - Assert.NotNull(item_2); + var item = 42; + var item_2 = Assert.Single(collection); + Assert.NotNull(item_2); """ }, { /* lang=c#-test */ """ - [|Assert.Collection(collection, item => { Assert.NotNull(item); Assert.NotNull(item); })|] + [|Assert.Collection(collection, item => { Assert.NotNull(item); Assert.NotNull(item); })|] """, /* lang=c#-test */ """ - var item = Assert.Single(collection); - Assert.NotNull(item); Assert.NotNull(item); + var item = Assert.Single(collection); + Assert.NotNull(item); Assert.NotNull(item); """ }, { /* lang=c#-test */ """ - var item = 42; - [|Assert.Collection(collection, item => { Assert.NotNull(item); Assert.NotNull(item); })|] + var item = 42; + [|Assert.Collection(collection, item => { Assert.NotNull(item); Assert.NotNull(item); })|] """, /* lang=c#-test */ """ - var item = 42; - var item_2 = Assert.Single(collection); - Assert.NotNull(item_2); Assert.NotNull(item_2); + var item = 42; + var item_2 = Assert.Single(collection); + Assert.NotNull(item_2); Assert.NotNull(item_2); """ }, { /* lang=c#-test */ """ - [|Assert.Collection(collection, item => { - if (item != null) { - Assert.NotNull(item); - Assert.NotNull(item); - } - })|] + [|Assert.Collection(collection, item => { + if (item != null) { + Assert.NotNull(item); + Assert.NotNull(item); + } + })|] """, /* lang=c#-test */ """ - var item = Assert.Single(collection); - if (item != null) - { - Assert.NotNull(item); - Assert.NotNull(item); - } + var item = Assert.Single(collection); + if (item != null) + { + Assert.NotNull(item); + Assert.NotNull(item); + } """ }, { /* lang=c#-test */ """ - var item = 42; - [|Assert.Collection(collection, item => { - if (item != null) { - Assert.NotNull(item); - Assert.NotNull(item); - } - })|] + var item = 42; + [|Assert.Collection(collection, item => { + if (item != null) { + Assert.NotNull(item); + Assert.NotNull(item); + } + })|] """, /* lang=c#-test */ """ - var item = 42; - var item_2 = Assert.Single(collection); - if (item_2 != null) - { - Assert.NotNull(item_2); - Assert.NotNull(item_2); - } + var item = 42; + var item_2 = Assert.Single(collection); + if (item_2 != null) + { + Assert.NotNull(item_2); + Assert.NotNull(item_2); + } """ }, { /* lang=c#-test */ """ - [|Assert.Collection(collection, ElementInspector)|] + [|Assert.Collection(collection, ElementInspector)|] """, /* lang=c#-test */ """ - var item = Assert.Single(collection); - ElementInspector(item); + var item = Assert.Single(collection); + ElementInspector(item); """ }, { /* lang=c#-test */ """ - var item = 42; - var item_2 = 21.12; - [|Assert.Collection(collection, ElementInspector)|] + var item = 42; + var item_2 = 21.12; + [|Assert.Collection(collection, ElementInspector)|] """, /* lang=c#-test */ """ - var item = 42; - var item_2 = 21.12; - var item_3 = Assert.Single(collection); - ElementInspector(item_3); + var item = 42; + var item_2 = 21.12; + var item_3 = Assert.Single(collection); + ElementInspector(item_3); """ }, }; @@ -135,15 +135,15 @@ public class AssertSingleShouldBeUsedForSingleParameterFixerTests using System.Collections.Generic; public class TestClass {{ - [Fact] - public void TestMethod() {{ - IEnumerable collection = new List() {{ new object() }}; + [Fact] + public void TestMethod() {{ + IEnumerable collection = new List() {{ new object() }}; {0}; - }} + }} - private void ElementInspector(object obj) - {{ }} + private void ElementInspector(object obj) + {{ }} }} """; @@ -152,15 +152,15 @@ private void ElementInspector(object obj) using System.Collections.Generic; public class TestClass {{ - [Fact] - public void TestMethod() {{ - IEnumerable collection = new List() {{ new object() }}; + [Fact] + public void TestMethod() {{ + IEnumerable collection = new List() {{ new object() }}; {0} - }} + }} - private void ElementInspector(object obj) - {{ }} + private void ElementInspector(object obj) + {{ }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldUseTwoArgumentCallFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldUseTwoArgumentCallFixerTests.cs index fdaefba5..375e16dc 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldUseTwoArgumentCallFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertSingleShouldUseTwoArgumentCallFixerTests.cs @@ -10,12 +10,12 @@ public class AssertSingleShouldUseTwoArgumentCallFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var list = new[] {{ -1, 0, 1, 2 }}; + [Fact] + public void TestMethod() {{ + var list = new[] {{ -1, 0, 1, 2 }}; - {0}; - }} + {0}; + }} public bool IsEven(int num) => num % 2 == 0; }} diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckFixerTests.cs index e9f9a839..6f03b74d 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertStringEqualityCheckShouldNotUseBoolCheckFixerTests.cs @@ -10,12 +10,12 @@ public class AssertStringEqualityCheckShouldNotUseBoolCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = "foo bar baz"; + [Fact] + public void TestMethod() {{ + var data = "foo bar baz"; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertSubstringCheckShouldNotUseBoolCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertSubstringCheckShouldNotUseBoolCheckFixerTests.cs index cda371ae..d1fb1f9a 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertSubstringCheckShouldNotUseBoolCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertSubstringCheckShouldNotUseBoolCheckFixerTests.cs @@ -10,12 +10,12 @@ public class AssertSubstringCheckShouldNotUseBoolCheckFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var data = "foo bar baz"; + [Fact] + public void TestMethod() {{ + var data = "foo bar baz"; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckFixerTests.cs index 83118aba..d97454b5 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssertThrowsShouldNotBeUsedForAsyncThrowsCheckFixerTests.cs @@ -14,11 +14,11 @@ public class AssertThrowsShouldNotBeUsedForAsyncThrowsCheckFixerTests using Xunit; public class TestClass {{ - Task ThrowingMethod() {{ - throw new NotImplementedException(); - }} + Task ThrowingMethod() {{ + throw new NotImplementedException(); + }} - [Fact]{0} + [Fact]{0} }} """; @@ -72,14 +72,14 @@ public async Task GivenAssertionInMethod_ReplacesWithAsyncAssertion( string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - {{|CS0619:[|{0}|]|}}; - }} + public void TestMethod() {{ + {{|CS0619:[|{0}|]|}}; + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - await {0}; - }} + public async Task TestMethod() {{ + await {0}; + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -92,26 +92,26 @@ public async Task GivenAssertionInInvokedAnonymousFunction_ReplacesWithAsyncAsse string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Func function = () => {{ - {{|CS0619:[|{0}|]|}}; - return 0; - }}; - - int number = function(); - function(); - }} + public void TestMethod() {{ + Func function = () => {{ + {{|CS0619:[|{0}|]|}}; + return 0; + }}; + + int number = function(); + function(); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - Func> function = async () => {{ - await {0}; - return 0; - }}; - - int number = {{|CS0029:function()|}}; - function(); - }} + public async Task TestMethod() {{ + Func> function = async () => {{ + await {0}; + return 0; + }}; + + int number = {{|CS0029:function()|}}; + function(); + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -124,28 +124,28 @@ public async Task GivenAssertionInInvokedAnonymousFunctionWithAssignment_Replace string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Func function = () => 0; - function = () => {{ - {{|CS0619:[|{0}|]|}}; - return 0; - }}; - - int number = function(); - function(); - }} + public void TestMethod() {{ + Func function = () => 0; + function = () => {{ + {{|CS0619:[|{0}|]|}}; + return 0; + }}; + + int number = function(); + function(); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - Func> function = () => {{|CS0029:{{|CS1662:0|}}|}}; - function = async () => {{ - await {0}; - return 0; - }}; - - int number = {{|CS0029:function()|}}; - function(); - }} + public async Task TestMethod() {{ + Func> function = () => {{|CS0029:{{|CS1662:0|}}|}}; + function = async () => {{ + await {0}; + return 0; + }}; + + int number = {{|CS0029:function()|}}; + function(); + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -160,26 +160,26 @@ public async Task GivenAssertionInInvokedAnonymousFunctionWithVar_ReplacesWithAs string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - var function = () => {{ - {{|CS0619:[|{0}|]|}}; - return 0; - }}; - - int number = function(); - function(); - }} + public void TestMethod() {{ + var function = () => {{ + {{|CS0619:[|{0}|]|}}; + return 0; + }}; + + int number = function(); + function(); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - var function = async () => {{ - await {0}; - return 0; - }}; - - int number = {{|CS0029:function()|}}; - function(); - }} + public async Task TestMethod() {{ + var function = async () => {{ + await {0}; + return 0; + }}; + + int number = {{|CS0029:function()|}}; + function(); + }} """, replacement); await VerifyCodeFix(LanguageVersion.CSharp10, beforeMethod, afterMethod); @@ -194,20 +194,20 @@ public async Task GivenAssertionInUninvokedAnonymousFunction_ReplacesWithAsyncAs string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Func function = () => {{ - {{|CS0619:[|{0}|]|}}; - return 0; - }}; - }} + public void TestMethod() {{ + Func function = () => {{ + {{|CS0619:[|{0}|]|}}; + return 0; + }}; + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Func> function = async () => {{ - await {0}; - return 0; - }}; - }} + public void TestMethod() {{ + Func> function = async () => {{ + await {0}; + return 0; + }}; + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -220,34 +220,34 @@ public async Task GivenAssertionInInvokedNestedAnonymousFunction_ReplacesWithAsy string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Action outerFunction = (number) => {{ - Func innerFunction = delegate () {{ - {{|CS0619:[|{0}|]|}}; - return string.Empty; - }}; - - var message = innerFunction().ToLower(); - innerFunction(); - }}; - - outerFunction(0); - }} + public void TestMethod() {{ + Action outerFunction = (number) => {{ + Func innerFunction = delegate () {{ + {{|CS0619:[|{0}|]|}}; + return string.Empty; + }}; + + var message = innerFunction().ToLower(); + innerFunction(); + }}; + + outerFunction(0); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - Func outerFunction = async (number) => {{ - Func> innerFunction = async delegate () {{ - await {0}; - return string.Empty; - }}; - - var message = innerFunction().{{|CS7036:ToLower|}}(); - innerFunction(); - }}; - - outerFunction(0); - }} + public async Task TestMethod() {{ + Func outerFunction = async (number) => {{ + Func> innerFunction = async delegate () {{ + await {0}; + return string.Empty; + }}; + + var message = innerFunction().{{|CS7036:ToLower|}}(); + innerFunction(); + }}; + + outerFunction(0); + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -260,32 +260,32 @@ public async Task GivenAssertionInExplicitlyInvokedNestedAnonymousFunction_Repla string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Action outerFunction = (number) => {{ - Func innerFunction = delegate () {{ - {{|CS0619:[|{0}|]|}}; - return string.Empty; - }}; - - var message = innerFunction.Invoke().ToLower(); - }}; - - outerFunction.Invoke(0); - }} + public void TestMethod() {{ + Action outerFunction = (number) => {{ + Func innerFunction = delegate () {{ + {{|CS0619:[|{0}|]|}}; + return string.Empty; + }}; + + var message = innerFunction.Invoke().ToLower(); + }}; + + outerFunction.Invoke(0); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - Func outerFunction = async (number) => {{ - Func> innerFunction = async delegate () {{ - await {0}; - return string.Empty; - }}; - - var message = innerFunction.Invoke().{{|CS7036:ToLower|}}(); - }}; - - outerFunction.Invoke(0); - }} + public async Task TestMethod() {{ + Func outerFunction = async (number) => {{ + Func> innerFunction = async delegate () {{ + await {0}; + return string.Empty; + }}; + + var message = innerFunction.Invoke().{{|CS7036:ToLower|}}(); + }}; + + outerFunction.Invoke(0); + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -298,32 +298,32 @@ public async Task GivenAssertionInConditionallyInvokedNestedAnonymousFunction_Re string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Action outerFunction = (number) => {{ - Func innerFunction = delegate () {{ - {{|CS0619:[|{0}|]|}}; - return string.Empty; - }}; - - var message = innerFunction?.Invoke().ToLower(); - }}; - - outerFunction?.Invoke(0); - }} + public void TestMethod() {{ + Action outerFunction = (number) => {{ + Func innerFunction = delegate () {{ + {{|CS0619:[|{0}|]|}}; + return string.Empty; + }}; + + var message = innerFunction?.Invoke().ToLower(); + }}; + + outerFunction?.Invoke(0); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - Func outerFunction = async (number) => {{ - Func> innerFunction = async delegate () {{ - await {0}; - return string.Empty; - }}; - - var message = innerFunction?.Invoke().{{|CS7036:ToLower|}}(); - }}; - - outerFunction?.Invoke(0); - }} + public async Task TestMethod() {{ + Func outerFunction = async (number) => {{ + Func> innerFunction = async delegate () {{ + await {0}; + return string.Empty; + }}; + + var message = innerFunction?.Invoke().{{|CS7036:ToLower|}}(); + }}; + + outerFunction?.Invoke(0); + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -336,24 +336,24 @@ public async Task GivenAssertionInUninvokedNestedAnonymousFunction_ReplacesWithA string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Action outerFunction = (number) => {{ - Func innerFunction = () => {{ - {{|CS0619:[|{0}|]|}}; - return string.Empty; - }}; - }}; - }} + public void TestMethod() {{ + Action outerFunction = (number) => {{ + Func innerFunction = () => {{ + {{|CS0619:[|{0}|]|}}; + return string.Empty; + }}; + }}; + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - Action outerFunction = (number) => {{ - Func> innerFunction = async () => {{ - await {0}; - return string.Empty; - }}; - }}; - }} + public void TestMethod() {{ + Action outerFunction = (number) => {{ + Func> innerFunction = async () => {{ + await {0}; + return string.Empty; + }}; + }}; + }} """, replacement); await VerifyCodeFix(beforeMethod, afterMethod); @@ -366,26 +366,26 @@ public async Task GivenAssertionInInvokedLocalFunction_ReplacesWithAsyncAssertio string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - int number = Function(); - Function(); - - int Function() {{ - {{|CS0619:[|{0}|]|}}; - return 0; - }} - }} + public void TestMethod() {{ + int number = Function(); + Function(); + + int Function() {{ + {{|CS0619:[|{0}|]|}}; + return 0; + }} + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - int number = {{|CS0029:Function()|}}; - Function(); - - async Task Function() {{ - await {0}; - return 0; - }} - }} + public async Task TestMethod() {{ + int number = {{|CS0029:Function()|}}; + Function(); + + async Task Function() {{ + await {0}; + return 0; + }} + }} """, replacement); await VerifyCodeFix(LanguageVersion.CSharp7, beforeMethod, afterMethod); @@ -398,20 +398,20 @@ public async Task GivenAssertionInUninvokedLocalFunction_ReplacesWithAsyncAssert string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - int Function() {{ - {{|CS0619:[|{0}|]|}}; - return 0; - }} - }} + public void TestMethod() {{ + int Function() {{ + {{|CS0619:[|{0}|]|}}; + return 0; + }} + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - async Task Function() {{ - await {0}; - return 0; - }} - }} + public void TestMethod() {{ + async Task Function() {{ + await {0}; + return 0; + }} + }} """, replacement); await VerifyCodeFix(LanguageVersion.CSharp7, beforeMethod, afterMethod); @@ -424,38 +424,38 @@ public async Task GivenAssertionInInvokedNestedLocalFunction_ReplacesWithAsyncAs string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - int number = OuterFunction(); - OuterFunction(); - - int OuterFunction() {{ - var message = InnerFunction().ToLower(); - InnerFunction(); - return 0; - - string InnerFunction() {{ - {{|CS0619:[|{0}|]|}}; - return string.Empty; - }} - }} - }} + public void TestMethod() {{ + int number = OuterFunction(); + OuterFunction(); + + int OuterFunction() {{ + var message = InnerFunction().ToLower(); + InnerFunction(); + return 0; + + string InnerFunction() {{ + {{|CS0619:[|{0}|]|}}; + return string.Empty; + }} + }} + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - int number = {{|CS0029:OuterFunction()|}}; - OuterFunction(); - - async Task OuterFunction() {{ - var message = InnerFunction().{{|CS7036:ToLower|}}(); - InnerFunction(); - return 0; - - async Task InnerFunction() {{ - await {0}; - return string.Empty; - }} - }} - }} + public async Task TestMethod() {{ + int number = {{|CS0029:OuterFunction()|}}; + OuterFunction(); + + async Task OuterFunction() {{ + var message = InnerFunction().{{|CS7036:ToLower|}}(); + InnerFunction(); + return 0; + + async Task InnerFunction() {{ + await {0}; + return string.Empty; + }} + }} + }} """, replacement); await VerifyCodeFix(LanguageVersion.CSharp7, beforeMethod, afterMethod); @@ -468,28 +468,28 @@ public async Task GivenAssertionInUninvokedNestedLocalFunction_ReplacesWithAsync string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - int OuterFunction() {{ - return 0; - - string InnerFunction() {{ - {{|CS0619:[|{0}|]|}}; - return string.Empty; - }} - }} - }} + public void TestMethod() {{ + int OuterFunction() {{ + return 0; + + string InnerFunction() {{ + {{|CS0619:[|{0}|]|}}; + return string.Empty; + }} + }} + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - int OuterFunction() {{ - return 0; - - async Task InnerFunction() {{ - await {0}; - return string.Empty; - }} - }} - }} + public void TestMethod() {{ + int OuterFunction() {{ + return 0; + + async Task InnerFunction() {{ + await {0}; + return string.Empty; + }} + }} + }} """, replacement); await VerifyCodeFix(LanguageVersion.CSharp7, beforeMethod, afterMethod); @@ -502,58 +502,58 @@ public async Task GivenAssertionInMixedNestedFunctions_ReplacesWithAsyncAssertio string replacement) { var beforeMethod = string.Format(/* lang=c#-test */ """ - public void TestMethod() {{ - int OuterLocalFunction() {{ - Func outerAnonymousFunction = () => {{ - string InnerLocalFunction() {{ - Action innerAnonymousFunction = () => {{ - {{|CS0619:[|{0}|]|}}; - }}; - - innerAnonymousFunction(); - return string.Empty; - }} - - string message = InnerLocalFunction(); - InnerLocalFunction(); - return false; - }}; - - bool condition = outerAnonymousFunction(); - outerAnonymousFunction(); - return 0; - }} - - int number = OuterLocalFunction(); - OuterLocalFunction(); - }} + public void TestMethod() {{ + int OuterLocalFunction() {{ + Func outerAnonymousFunction = () => {{ + string InnerLocalFunction() {{ + Action innerAnonymousFunction = () => {{ + {{|CS0619:[|{0}|]|}}; + }}; + + innerAnonymousFunction(); + return string.Empty; + }} + + string message = InnerLocalFunction(); + InnerLocalFunction(); + return false; + }}; + + bool condition = outerAnonymousFunction(); + outerAnonymousFunction(); + return 0; + }} + + int number = OuterLocalFunction(); + OuterLocalFunction(); + }} """, assertion); var afterMethod = string.Format(/* lang=c#-test */ """ - public async Task TestMethod() {{ - async Task OuterLocalFunction() {{ - Func> outerAnonymousFunction = async () => {{ - async Task InnerLocalFunction() {{ - Func innerAnonymousFunction = async () => {{ - await {0}; - }}; - - innerAnonymousFunction(); - return string.Empty; - }} - - string message = {{|CS0029:InnerLocalFunction()|}}; - InnerLocalFunction(); - return false; - }}; - - bool condition = {{|CS0029:outerAnonymousFunction()|}}; - outerAnonymousFunction(); - return 0; - }} - - int number = {{|CS0029:OuterLocalFunction()|}}; - OuterLocalFunction(); - }} + public async Task TestMethod() {{ + async Task OuterLocalFunction() {{ + Func> outerAnonymousFunction = async () => {{ + async Task InnerLocalFunction() {{ + Func innerAnonymousFunction = async () => {{ + await {0}; + }}; + + innerAnonymousFunction(); + return string.Empty; + }} + + string message = {{|CS0029:InnerLocalFunction()|}}; + InnerLocalFunction(); + return false; + }}; + + bool condition = {{|CS0029:outerAnonymousFunction()|}}; + outerAnonymousFunction(); + return 0; + }} + + int number = {{|CS0029:OuterLocalFunction()|}}; + OuterLocalFunction(); + }} """, replacement); await VerifyCodeFix(LanguageVersion.CSharp7, beforeMethod, afterMethod); diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AssignableFromAssertionIsConfusinglyNamedFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AssignableFromAssertionIsConfusinglyNamedFixerTests.cs index 019ab985..44e32688 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AssignableFromAssertionIsConfusinglyNamedFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AssignableFromAssertionIsConfusinglyNamedFixerTests.cs @@ -13,13 +13,13 @@ public async Task Conversions() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var data = "Hello world"; + [Fact] + public void TestMethod() { + var data = "Hello world"; - [|Assert.IsAssignableFrom(typeof(object), data)|]; - [|Assert.IsAssignableFrom(data)|]; - } + [|Assert.IsAssignableFrom(typeof(object), data)|]; + [|Assert.IsAssignableFrom(data)|]; + } } """; var after = /* lang=c#-test */ """ @@ -27,13 +27,13 @@ public void TestMethod() { using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var data = "Hello world"; + [Fact] + public void TestMethod() { + var data = "Hello world"; - Assert.IsType(typeof(object), data, exactMatch: false); - Assert.IsType(data, exactMatch: false); - } + Assert.IsType(typeof(object), data, exactMatch: false); + Assert.IsType(data, exactMatch: false); + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/AsyncAssertsShouldBeAwaitedFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/AsyncAssertsShouldBeAwaitedFixerTests.cs index 9d3543c6..f9daa2ef 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/AsyncAssertsShouldBeAwaitedFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/AsyncAssertsShouldBeAwaitedFixerTests.cs @@ -13,20 +13,20 @@ public class AsyncAssertsShouldBeAwaitedFixerTests using Xunit; public class TestClass : INotifyPropertyChanged {{ - public int Property {{ get; set; }} + public int Property {{ get; set; }} - public event PropertyChangedEventHandler? PropertyChanged; - public event EventHandler? SimpleEvent; - public event EventHandler? SimpleIntEvent; + public event PropertyChangedEventHandler? PropertyChanged; + public event EventHandler? SimpleEvent; + public event EventHandler? SimpleIntEvent; - [Fact] - public void TestMethod() {{ - {0} - }} + [Fact] + public void TestMethod() {{ + {0} + }} }} public static class MyTaskExtensions {{ - public static void ConsumeTask(this Task t) {{ }} + public static void ConsumeTask(this Task t) {{ }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeNegatedFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeNegatedFixerTests.cs index 0c14f905..cdc8c9db 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeNegatedFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeNegatedFixerTests.cs @@ -9,12 +9,12 @@ public class BooleanAssertsShouldNotBeNegatedFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - bool condition = true; + [Fact] + public void TestMethod() {{ + bool condition = true; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckBooleanFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckBooleanFixerTests.cs index f82a26ad..b1914707 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckBooleanFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckBooleanFixerTests.cs @@ -9,12 +9,12 @@ public class BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckBooleanFixerTest using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - bool condition = true; + [Fact] + public void TestMethod() {{ + bool condition = true; - {0}; - }} + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckNonBooleanFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckNonBooleanFixerTests.cs index 37410f78..6ff8a7ca 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckNonBooleanFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckNonBooleanFixerTests.cs @@ -13,12 +13,12 @@ public class BooleanAssertsShouldNotBeUsedForSimpleEqualityCheckNonBooleanFixerT public enum MyEnum {{ None, Bacon, Veggie }} public class TestClass {{ - [Fact] - public void TestMethod() {{ - {0} value = {1}; + [Fact] + public void TestMethod() {{ + {0} value = {1}; - {2}; - }} + {2}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/UseAssertFailInsteadOfBooleanAssertFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/UseAssertFailInsteadOfBooleanAssertFixerTests.cs index 3c4b1507..958534fe 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/UseAssertFailInsteadOfBooleanAssertFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/UseAssertFailInsteadOfBooleanAssertFixerTests.cs @@ -10,10 +10,10 @@ public class UseAssertFailInsteadOfBooleanAssertFixerTests using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - {0}; - }} + [Fact] + public void TestMethod() {{ + {0}; + }} }} """; diff --git a/src/xunit.analyzers.tests/Fixes/X2000/UseGenericOverloadFixTests.cs b/src/xunit.analyzers.tests/Fixes/X2000/UseGenericOverloadFixTests.cs index 82d92f9a..57a3a522 100644 --- a/src/xunit.analyzers.tests/Fixes/X2000/UseGenericOverloadFixTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X2000/UseGenericOverloadFixTests.cs @@ -13,24 +13,24 @@ public async Task X2007_SwitchesToGenericIsAssignableFrom() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var result = 123; + [Fact] + public void TestMethod() { + var result = 123; - [|Assert.IsAssignableFrom(typeof(int), result)|]; - } + [|Assert.IsAssignableFrom(typeof(int), result)|]; + } } """; var after = /* lang=c#-test */ """ using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - var result = 123; + [Fact] + public void TestMethod() { + var result = 123; - Assert.IsAssignableFrom(result); - } + Assert.IsAssignableFrom(result); + } } """; @@ -47,24 +47,24 @@ public async Task X2007_SwitchesToGenericIsType(string arguments) using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var result = 123; + [Fact] + public void TestMethod() {{ + var result = 123; - [|Assert.IsType(typeof(int), {0})|]; - }} + [|Assert.IsType(typeof(int), {0})|]; + }} }} """, arguments); var after = string.Format(/* lang=c#-test */ """ using Xunit; public class TestClass {{ - [Fact] - public void TestMethod() {{ - var result = 123; + [Fact] + public void TestMethod() {{ + var result = 123; - Assert.IsType({0}); - }} + Assert.IsType({0}); + }} }} """, arguments); @@ -79,12 +79,12 @@ public async Task X2015_SwitchesToGenericThrows() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Action func = () => { }; + [Fact] + public void TestMethod() { + Action func = () => { }; - [|Assert.Throws(typeof(DivideByZeroException), func)|]; - } + [|Assert.Throws(typeof(DivideByZeroException), func)|]; + } } """; var after = /* lang=c#-test */ """ @@ -92,12 +92,12 @@ public void TestMethod() { using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - Action func = () => { }; + [Fact] + public void TestMethod() { + Action func = () => { }; - Assert.Throws(func); - } + Assert.Throws(func); + } } """; diff --git a/src/xunit.analyzers.tests/Fixes/X3000/SerializableClassMustHaveParameterlessConstructorFixerTests.cs b/src/xunit.analyzers.tests/Fixes/X3000/SerializableClassMustHaveParameterlessConstructorFixerTests.cs index 3a6de0c9..eddb9f9c 100644 --- a/src/xunit.analyzers.tests/Fixes/X3000/SerializableClassMustHaveParameterlessConstructorFixerTests.cs +++ b/src/xunit.analyzers.tests/Fixes/X3000/SerializableClassMustHaveParameterlessConstructorFixerTests.cs @@ -16,7 +16,7 @@ public async Task WithPublicParameteredConstructor_AddsNewConstructor() [JsonTypeID("1")] public class [|MyJsonObject|] { - public MyJsonObject(int _) { } + public MyJsonObject(int _) { } } """; var after = /* lang=c#-test */ """ @@ -24,12 +24,12 @@ public MyJsonObject(int _) { } [JsonTypeID("1")] public class MyJsonObject { - [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public MyJsonObject() - { - } + [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] + public MyJsonObject() + { + } - public MyJsonObject(int _) { } + public MyJsonObject(int _) { } } """; @@ -44,7 +44,7 @@ public async Task WithNonPublicParameterlessConstructor_ChangesVisibility() [JsonTypeID("1")] public class [|MyJsonObject|] { - protected MyJsonObject() { } + protected MyJsonObject() { } } """; var after = /* lang=c#-test */ """ @@ -52,8 +52,8 @@ protected MyJsonObject() { } [JsonTypeID("1")] public class MyJsonObject { - [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public MyJsonObject() { } + [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] + public MyJsonObject() { } } """; @@ -74,18 +74,18 @@ public async Task WithPublicParameteredConstructor_AddsNewConstructor() public class [|MyRunnerReporter|] : IRunnerReporter { - public MyRunnerReporter(int _) { } + public MyRunnerReporter(int _) { } - public bool CanBeEnvironmentallyEnabled => false; - public string Description => string.Empty; - public bool ForceNoLogo => false; - public bool IsEnvironmentallyEnabled => false; - public string? RunnerSwitch => "unused"; + public bool CanBeEnvironmentallyEnabled => false; + public string Description => string.Empty; + public bool ForceNoLogo => false; + public bool IsEnvironmentallyEnabled => false; + public string? RunnerSwitch => "unused"; - public ValueTask CreateMessageHandler( - IRunnerLogger logger, - IMessageSink? diagnosticMessageSink) => - throw new NotImplementedException(); + public ValueTask CreateMessageHandler( + IRunnerLogger logger, + IMessageSink? diagnosticMessageSink) => + throw new NotImplementedException(); } """; var after = /* lang=c#-test */ """ @@ -96,22 +96,22 @@ public ValueTask CreateMessageHandler( public class MyRunnerReporter : IRunnerReporter { - public MyRunnerReporter() - { - } + public MyRunnerReporter() + { + } - public MyRunnerReporter(int _) { } + public MyRunnerReporter(int _) { } - public bool CanBeEnvironmentallyEnabled => false; - public string Description => string.Empty; - public bool ForceNoLogo => false; - public bool IsEnvironmentallyEnabled => false; - public string? RunnerSwitch => "unused"; + public bool CanBeEnvironmentallyEnabled => false; + public string Description => string.Empty; + public bool ForceNoLogo => false; + public bool IsEnvironmentallyEnabled => false; + public string? RunnerSwitch => "unused"; - public ValueTask CreateMessageHandler( - IRunnerLogger logger, - IMessageSink? diagnosticMessageSink) => - throw new NotImplementedException(); + public ValueTask CreateMessageHandler( + IRunnerLogger logger, + IMessageSink? diagnosticMessageSink) => + throw new NotImplementedException(); } """; @@ -129,18 +129,18 @@ public async Task WithNonPublicParameterlessConstructor_ChangesVisibility() public class [|MyRunnerReporter|] : IRunnerReporter { - protected MyRunnerReporter() { } + protected MyRunnerReporter() { } - public bool CanBeEnvironmentallyEnabled => false; - public string Description => string.Empty; - public bool ForceNoLogo => false; - public bool IsEnvironmentallyEnabled => false; - public string? RunnerSwitch => "unused"; + public bool CanBeEnvironmentallyEnabled => false; + public string Description => string.Empty; + public bool ForceNoLogo => false; + public bool IsEnvironmentallyEnabled => false; + public string? RunnerSwitch => "unused"; - public ValueTask CreateMessageHandler( - IRunnerLogger logger, - IMessageSink? diagnosticMessageSink) => - throw new NotImplementedException(); + public ValueTask CreateMessageHandler( + IRunnerLogger logger, + IMessageSink? diagnosticMessageSink) => + throw new NotImplementedException(); } """; var after = /* lang=c#-test */ """ @@ -151,18 +151,18 @@ public ValueTask CreateMessageHandler( public class MyRunnerReporter : IRunnerReporter { - public MyRunnerReporter() { } + public MyRunnerReporter() { } - public bool CanBeEnvironmentallyEnabled => false; - public string Description => string.Empty; - public bool ForceNoLogo => false; - public bool IsEnvironmentallyEnabled => false; - public string? RunnerSwitch => "unused"; + public bool CanBeEnvironmentallyEnabled => false; + public string Description => string.Empty; + public bool ForceNoLogo => false; + public bool IsEnvironmentallyEnabled => false; + public string? RunnerSwitch => "unused"; - public ValueTask CreateMessageHandler( - IRunnerLogger logger, - IMessageSink? diagnosticMessageSink) => - throw new NotImplementedException(); + public ValueTask CreateMessageHandler( + IRunnerLogger logger, + IMessageSink? diagnosticMessageSink) => + throw new NotImplementedException(); } """; @@ -177,23 +177,23 @@ public async Task WithPublicParameteredConstructor_AddsNewConstructor() { var beforeTemplate = /* lang=c#-test */ """ public class [|MyTestCase|]: {0}.IXunitSerializable {{ - public MyTestCase(int x) {{ }} + public MyTestCase(int x) {{ }} - void {0}.IXunitSerializable.Deserialize({0}.IXunitSerializationInfo _) {{ }} - void {0}.IXunitSerializable.Serialize({0}.IXunitSerializationInfo _) {{ }} + void {0}.IXunitSerializable.Deserialize({0}.IXunitSerializationInfo _) {{ }} + void {0}.IXunitSerializable.Serialize({0}.IXunitSerializationInfo _) {{ }} }} """; var afterTemplate = /* lang=c#-test */ """ public class MyTestCase: {0}.IXunitSerializable {{ - [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public MyTestCase() - {{ - }} + [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] + public MyTestCase() + {{ + }} - public MyTestCase(int x) {{ }} + public MyTestCase(int x) {{ }} - void {0}.IXunitSerializable.Deserialize({0}.IXunitSerializationInfo _) {{ }} - void {0}.IXunitSerializable.Serialize({0}.IXunitSerializationInfo _) {{ }} + void {0}.IXunitSerializable.Deserialize({0}.IXunitSerializationInfo _) {{ }} + void {0}.IXunitSerializable.Serialize({0}.IXunitSerializationInfo _) {{ }} }} """; @@ -215,21 +215,21 @@ public async Task WithNonPublicParameterlessConstructor_ChangesVisibility_Withou using {0}; public class [|MyTestCase|]: IXunitSerializable {{ - protected MyTestCase() {{ throw new System.DivideByZeroException(); }} + protected MyTestCase() {{ throw new System.DivideByZeroException(); }} - void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} - void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} }} """; var afterTemplate = /* lang=c#-test */ """ using {0}; public class MyTestCase: IXunitSerializable {{ - [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public MyTestCase() {{ throw new System.DivideByZeroException(); }} + [System.Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] + public MyTestCase() {{ throw new System.DivideByZeroException(); }} - void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} - void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} }} """; @@ -252,10 +252,10 @@ public async Task WithNonPublicParameterlessConstructor_ChangesVisibility_WithUs using {0}; public class [|MyTestCase|]: IXunitSerializable {{ - protected MyTestCase() {{ throw new DivideByZeroException(); }} + protected MyTestCase() {{ throw new DivideByZeroException(); }} - void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} - void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} }} """; var afterTemplate = /* lang=c#-test */ """ @@ -263,11 +263,11 @@ void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} using {0}; public class MyTestCase: IXunitSerializable {{ - [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] - public MyTestCase() {{ throw new DivideByZeroException(); }} + [Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")] + public MyTestCase() {{ throw new DivideByZeroException(); }} - void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} - void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} }} """; @@ -290,11 +290,11 @@ public async Task PreservesExistingObsoleteAttribute() using obo = System.ObsoleteAttribute; public class [|MyTestCase|]: IXunitSerializable {{ - [obo("This is my custom obsolete message")] - protected MyTestCase() {{ throw new System.DivideByZeroException(); }} + [obo("This is my custom obsolete message")] + protected MyTestCase() {{ throw new System.DivideByZeroException(); }} - void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} - void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} }} """; var afterTemplate = /* lang=c#-test */ """ @@ -302,11 +302,11 @@ void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} using obo = System.ObsoleteAttribute; public class MyTestCase: IXunitSerializable {{ - [obo("This is my custom obsolete message")] - public MyTestCase() {{ throw new System.DivideByZeroException(); }} + [obo("This is my custom obsolete message")] + public MyTestCase() {{ throw new System.DivideByZeroException(); }} - void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} - void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Deserialize(IXunitSerializationInfo _) {{ }} + void IXunitSerializable.Serialize(IXunitSerializationInfo _) {{ }} }} """; @@ -333,11 +333,11 @@ public async Task WithPublicParameteredConstructor_AddsNewConstructor() public class [|MySerializer|] : IXunitSerializer { - public MySerializer(int _) { } + public MySerializer(int _) { } - public object Deserialize(Type type, string serializedValue) => null!; - public bool IsSerializable(Type type, object? value) => true; - public string Serialize(object value) => string.Empty; + public object Deserialize(Type type, string serializedValue) => null!; + public bool IsSerializable(Type type, object? value) => true; + public string Serialize(object value) => string.Empty; } """; var after = /* lang=c#-test */ """ @@ -346,15 +346,15 @@ public MySerializer(int _) { } public class MySerializer : IXunitSerializer { - public MySerializer() - { - } + public MySerializer() + { + } - public MySerializer(int _) { } + public MySerializer(int _) { } - public object Deserialize(Type type, string serializedValue) => null!; - public bool IsSerializable(Type type, object? value) => true; - public string Serialize(object value) => string.Empty; + public object Deserialize(Type type, string serializedValue) => null!; + public bool IsSerializable(Type type, object? value) => true; + public string Serialize(object value) => string.Empty; } """; @@ -370,11 +370,11 @@ public async Task WithNonPublicParameterlessConstructor_ChangesVisibility() public class [|MySerializer|] : IXunitSerializer { - protected MySerializer() { } + protected MySerializer() { } - public object Deserialize(Type type, string serializedValue) => null!; - public bool IsSerializable(Type type, object? value) => true; - public string Serialize(object value) => string.Empty; + public object Deserialize(Type type, string serializedValue) => null!; + public bool IsSerializable(Type type, object? value) => true; + public string Serialize(object value) => string.Empty; } """; var after = /* lang=c#-test */ """ @@ -383,11 +383,11 @@ protected MySerializer() { } public class MySerializer : IXunitSerializer { - public MySerializer() { } + public MySerializer() { } - public object Deserialize(Type type, string serializedValue) => null!; - public bool IsSerializable(Type type, object? value) => true; - public string Serialize(object value) => string.Empty; + public object Deserialize(Type type, string serializedValue) => null!; + public bool IsSerializable(Type type, object? value) => true; + public string Serialize(object value) => string.Empty; } """; diff --git a/src/xunit.analyzers.tests/Suppressors/ConsiderCallingConfigureAwaitSuppressorTests.cs b/src/xunit.analyzers.tests/Suppressors/ConsiderCallingConfigureAwaitSuppressorTests.cs index fb43e143..2391f27b 100644 --- a/src/xunit.analyzers.tests/Suppressors/ConsiderCallingConfigureAwaitSuppressorTests.cs +++ b/src/xunit.analyzers.tests/Suppressors/ConsiderCallingConfigureAwaitSuppressorTests.cs @@ -18,9 +18,9 @@ public async Task NonTestMethod_DoesNotSuppress() using System.Threading.Tasks; public class NonTestClass { - public async Task NonTestMethod() { - await {|CA2007:Task.Delay(1)|}; - } + public async Task NonTestMethod() { + await {|CA2007:Task.Delay(1)|}; + } } """; @@ -39,10 +39,10 @@ public async Task StandardTestMethod_Suppresses(string attribute) using Xunit; public class TestClass {{ - [{0}] - public async Task TestMethod() {{ - await {{|#0:Task.Delay(1)|}}; - }} + [{0}] + public async Task TestMethod() {{ + await {{|#0:Task.Delay(1)|}}; + }} }} """, attribute); #if ROSLYN_LATEST @@ -64,10 +64,10 @@ public async Task CustomFactTestMethod_DoesNotSuppress() internal class CustomFactAttribute : FactAttribute { } public class TestClass { - [CustomFact] - public async Task TestMethod() { - await {|CA2007:Task.Delay(1)|}; - } + [CustomFact] + public async Task TestMethod() { + await {|CA2007:Task.Delay(1)|}; + } } """; @@ -83,12 +83,12 @@ public async Task CodeInsideFunctions_DoesNotSuppress() using Xunit; public class TestClass { - [Fact] - public void TestMethod() { - async Task InnerMethod1() { await {|CA2007:Task.Delay(1)|}; } - async Task InnerMethod2() => await {|CA2007:Task.Delay(1)|}; - Func Lambda = async () => await {|CA2007:Task.Delay(1)|}; - } + [Fact] + public void TestMethod() { + async Task InnerMethod1() { await {|CA2007:Task.Delay(1)|}; } + async Task InnerMethod2() => await {|CA2007:Task.Delay(1)|}; + Func Lambda = async () => await {|CA2007:Task.Delay(1)|}; + } } """; diff --git a/src/xunit.analyzers.tests/Suppressors/MakeTypesInternalSuppressorTests.cs b/src/xunit.analyzers.tests/Suppressors/MakeTypesInternalSuppressorTests.cs index 5ddf9e98..72f5d8fa 100644 --- a/src/xunit.analyzers.tests/Suppressors/MakeTypesInternalSuppressorTests.cs +++ b/src/xunit.analyzers.tests/Suppressors/MakeTypesInternalSuppressorTests.cs @@ -17,7 +17,7 @@ public async Task NonTestClass_DoesNotSuppress() { var code = /* lang=c#-test */ """ public class {|CA1515:NonTestClass|} { - public void NonTestMethod() { } + public void NonTestMethod() { } } """; @@ -39,8 +39,8 @@ public async Task TestClass_Suppresses(string attribute) internal class CustomFactAttribute : FactAttribute {{ }} public class {{|#0:TestClass|}} {{ - [{0}] - public void TestMethod() {{ }} + [{0}] + public void TestMethod() {{ }} }} """, attribute); #if ROSLYN_LATEST diff --git a/src/xunit.analyzers.tests/Suppressors/UseAsyncSuffixForAsyncMethodsSuppressorTests.cs b/src/xunit.analyzers.tests/Suppressors/UseAsyncSuffixForAsyncMethodsSuppressorTests.cs index a6f7e8b6..eed998b1 100644 --- a/src/xunit.analyzers.tests/Suppressors/UseAsyncSuffixForAsyncMethodsSuppressorTests.cs +++ b/src/xunit.analyzers.tests/Suppressors/UseAsyncSuffixForAsyncMethodsSuppressorTests.cs @@ -17,12 +17,12 @@ public async Task AcceptanceTest() using Xunit; public class NonTestClass { - public async Task {|#0:NonTestMethod|}() { } + public async Task {|#0:NonTestMethod|}() { } } public class TestClass { - [Fact] - public async Task {|#1:TestMethod|]() { } + [Fact] + public async Task {|#1:TestMethod|]() { } } """; var expected = new[] diff --git a/src/xunit.analyzers.tests/Utility/CSharpVerifier.cs b/src/xunit.analyzers.tests/Utility/CSharpVerifier.cs index 77e20881..1db7ef68 100644 --- a/src/xunit.analyzers.tests/Utility/CSharpVerifier.cs +++ b/src/xunit.analyzers.tests/Utility/CSharpVerifier.cs @@ -8,6 +8,7 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; using Microsoft.CodeAnalysis.Testing.Verifiers; +using Microsoft.CodeAnalysis.Text; public partial class CSharpVerifier where TAnalyzer : DiagnosticAnalyzer, new() @@ -44,6 +45,17 @@ protected TestBase( LanguageVersion = languageVersion; ReferenceAssemblies = referenceAssemblies; + // Ensure all fixed source matches the inline source (tabs, not spaces) + TestState.AnalyzerConfigFiles.Add( + ( + "/.editorconfig", + SourceText.From(""" + [*] + indent_style = tab + """) + ) + ); + // Diagnostics are reported in both normal and generated code TestBehaviors |= TestBehaviors.SkipGeneratedCodeCheck;