diff --git a/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.HasAttributeOnDerivedClassAndPropertyManuallyDefinedInBase.verified.txt b/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.HasAttributeOnDerivedClassAndPropertyManuallyDefinedInBase.verified.txt index b95d48ce31..f788bf747d 100644 --- a/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.HasAttributeOnDerivedClassAndPropertyManuallyDefinedInBase.verified.txt +++ b/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.HasAttributeOnDerivedClassAndPropertyManuallyDefinedInBase.verified.txt @@ -12,7 +12,7 @@ partial class Derived { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Verify.MSTest.SourceGenerator", "1.0.0.0")] - public sealed override global::Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext + public new global::Microsoft.VisualStudio.TestTools.UnitTesting.TestContext TestContext { get => base.TestContext; set diff --git a/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.cs b/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.cs index 1b357b5484..c525e042ec 100644 --- a/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.cs +++ b/src/Verify.MSTest.SourceGenerator.Tests/InheritanceTests.cs @@ -76,7 +76,7 @@ public partial class Derived : Base } """; - return VerifyGenerator(TestDriver.Run(source), ["CS0506"]); + return VerifyGenerator(TestDriver.Run(source)); } [Fact] diff --git a/src/Verify.MSTest.SourceGenerator/ClassToGenerate.cs b/src/Verify.MSTest.SourceGenerator/ClassToGenerate.cs index 3271ef3c7c..5638b6c9e6 100644 --- a/src/Verify.MSTest.SourceGenerator/ClassToGenerate.cs +++ b/src/Verify.MSTest.SourceGenerator/ClassToGenerate.cs @@ -20,6 +20,7 @@ public enum PropertyFlags None = 0b00, Override = 0b01, CallBase = 0b10, + New = 0b100, } public string? Namespace { get; } = Namespace; diff --git a/src/Verify.MSTest.SourceGenerator/Emitter.cs b/src/Verify.MSTest.SourceGenerator/Emitter.cs index 671221c4ca..6b262f121a 100644 --- a/src/Verify.MSTest.SourceGenerator/Emitter.cs +++ b/src/Verify.MSTest.SourceGenerator/Emitter.cs @@ -131,5 +131,5 @@ static string GetterBody(PropertyFlags flags) => static string GetModifiers(PropertyFlags flags) => flags.HasFlag(PropertyFlags.Override) ? "sealed override " - : string.Empty; + : (flags.HasFlag(PropertyFlags.New) ? "new " : string.Empty); } \ No newline at end of file diff --git a/src/Verify.MSTest.SourceGenerator/Parser.cs b/src/Verify.MSTest.SourceGenerator/Parser.cs index 6a824c82f0..0a6866b402 100644 --- a/src/Verify.MSTest.SourceGenerator/Parser.cs +++ b/src/Verify.MSTest.SourceGenerator/Parser.cs @@ -23,9 +23,8 @@ static PropertyFlags GetDerivedPropertyFlagsGiven(IPropertySymbol? baseClassProp baseClassProperty?.IsAbstract switch { true => PropertyFlags.Override, - false => PropertyFlags.Override | - PropertyFlags.CallBase, - null => PropertyFlags.None + false => baseClassProperty.IsVirtual ? PropertyFlags.Override | PropertyFlags.CallBase : PropertyFlags.New | PropertyFlags.CallBase, + null => PropertyFlags.None, }; static IEnumerable BaseTestContextProperties(INamedTypeSymbol typeSymbol) => diff --git a/src/Verify.Xunit/Verifier_Object.cs b/src/Verify.Xunit/Verifier_Object.cs index 59b6353f8b..0e1d8e6d7b 100644 --- a/src/Verify.Xunit/Verifier_Object.cs +++ b/src/Verify.Xunit/Verifier_Object.cs @@ -1,4 +1,4 @@ -namespace VerifyXunit; +namespace VerifyXunit; public static partial class Verifier {