From e0818ce05625ae9989c2a686c7a14412402490a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Guldmund?= Date: Fri, 2 Feb 2024 20:12:40 +0100 Subject: [PATCH 1/2] #26 Change `thisType.IsValueType` to `constructor.IsValueType` --- src/Pose/IL/Stubs.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); From 8737040ae3fb951839795227c660c4019345d829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Guldmund?= Date: Fri, 2 Feb 2024 20:12:51 +0100 Subject: [PATCH 2/2] #26 Add regression test for Miista/pose#26 --- test/Pose.Tests/RegressionTests.cs | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/Pose.Tests/RegressionTests.cs 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