diff --git a/src/Pose/IL/Stubs.cs b/src/Pose/IL/Stubs.cs index 48b2483..118620f 100644 --- a/src/Pose/IL/Stubs.cs +++ b/src/Pose/IL/Stubs.cs @@ -173,7 +173,7 @@ public static DynamicMethod GenerateStubForDirectCall(MethodBase method) ilGenerator.MarkLabel(returnLabel); ilGenerator.Emit(OpCodes.Ret); - + return stub; } @@ -451,7 +451,7 @@ public static DynamicMethod GenerateStubForObjectInitialization(ConstructorInfo ilGenerator.MarkLabel(rewriteLabel); // ++ - if (thisType.IsValueType) + if (constructor.DeclaringType.IsValueType) { ilGenerator.Emit(OpCodes.Ldloca_S, (byte)1); // ilGenerator.Emit(OpCodes.Dup); diff --git a/test/Pose.Tests/RegressionTests.cs b/test/Pose.Tests/RegressionTests.cs new file mode 100644 index 0000000..7718ccd --- /dev/null +++ b/test/Pose.Tests/RegressionTests.cs @@ -0,0 +1,32 @@ +using System; +using FluentAssertions; +using Xunit; +using DateTime = System.DateTime; + +namespace Pose.Tests +{ + public class RegressionTests + { + private enum TestEnum { A } + + [Fact(DisplayName = "Enum.IsDefined cannot be called from within PoseContext.Isolate #26")] + public void Can_call_EnumIsDefined_from_Isolate() + { + // Arrange + var shim = Shim + .Replace(() => new DateTime(2024, 2, 2)) + .With((int year, int month, int day) => new DateTime(2004, 1, 1)); + var isDefined = false; + + // Act + PoseContext.Isolate( + () => + { + isDefined = Enum.IsDefined(typeof(TestEnum), nameof(TestEnum.A)); + }, shim); + + // Assert + isDefined.Should().BeTrue(because: "Enum.IsDefined can be called from Isolate"); + } + } +} \ No newline at end of file