From 442ba7dd0c9d5f8a7ac0d96e14ed22dbccdd9b5f Mon Sep 17 00:00:00 2001 From: nth-commit Date: Sat, 11 Dec 2021 12:44:39 +1300 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=8D=20#314=20Code=20refactoring=20sugg?= =?UTF-8?q?estions=20now=20also=20apply=20to=20SampleAttribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfigureGenWithMemberTests.cs | 35 +++++++++++++++++++ .../ConfigureGenWithMember.cs | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/GalaxyCheck.Xunit.CodeAnalysis.Tests/CodeRefactoringProviders/ConfigureGenWithMemberTests.cs b/src/GalaxyCheck.Xunit.CodeAnalysis.Tests/CodeRefactoringProviders/ConfigureGenWithMemberTests.cs index 3dbf993e..487e3dd8 100644 --- a/src/GalaxyCheck.Xunit.CodeAnalysis.Tests/CodeRefactoringProviders/ConfigureGenWithMemberTests.cs +++ b/src/GalaxyCheck.Xunit.CodeAnalysis.Tests/CodeRefactoringProviders/ConfigureGenWithMemberTests.cs @@ -96,6 +96,41 @@ public void TestMethod([MemberGen(nameof(TestMethod_x))] int x) await Verifier.Verify(code, codeProvidingRefactorPosition, expectedRefactoredCode, expectedRefactoringTitle); } + [Fact] + public async Task ItRefactorsMethodsDecoratedWithTheSampleAttribute() + { + var code = @" +using GalaxyCheck; + +public class TestClass +{ + [Sample] + public void TestMethod(int x) + { + } +} +"; + var codeProvidingRefactorPosition = new LinePosition(7, 28); + + var expectedRefactoredCode = @" +using GalaxyCheck; + +public class TestClass +{ + private static IGen TestMethod_x => Gen.Int32(); + + [Sample] + public void TestMethod([MemberGen(nameof(TestMethod_x))] int x) + { + } +} +"; + + var expectedRefactoringTitle = $"Configure generation of parameter with MemberGenAttribute"; + + await Verifier.Verify(code, codeProvidingRefactorPosition, expectedRefactoredCode, expectedRefactoringTitle); + } + [Theory] [InlineData(7, 27)] [InlineData(7, 33)] diff --git a/src/GalaxyCheck.Xunit.CodeAnalysis/CodeRefactoringProviders/ConfigureGenWithMember.cs b/src/GalaxyCheck.Xunit.CodeAnalysis/CodeRefactoringProviders/ConfigureGenWithMember.cs index 16987479..a8cfaea5 100644 --- a/src/GalaxyCheck.Xunit.CodeAnalysis/CodeRefactoringProviders/ConfigureGenWithMember.cs +++ b/src/GalaxyCheck.Xunit.CodeAnalysis/CodeRefactoringProviders/ConfigureGenWithMember.cs @@ -37,7 +37,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte .FirstOrDefault(a => { var attributeSymbol = semanticModel.GetSymbolInfo(a); - return SymbolEqualityComparer.Default.Equals(attributeSymbol.Symbol?.ContainingType, propertyAttributeType); + return attributeSymbol.Symbol != null && propertyAttributeType.IsAssignableFrom(attributeSymbol.Symbol.ContainingType); }); if (propertyAttribute is null) return;