Skip to content

Commit

Permalink
Merge pull request #40 from Miista/26-enumisdefined-cannot-be-called-…
Browse files Browse the repository at this point in the history
…from-within-posecontextisolate

#26: Enum.IsDefined cannot be called from within PoseContext.Isolate
  • Loading branch information
Miista committed May 2, 2024
2 parents 91ac854 + 438f662 commit 6c16d52
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Pose/IL/Stubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static DynamicMethod GenerateStubForDirectCall(MethodBase method)

ilGenerator.MarkLabel(returnLabel);
ilGenerator.Emit(OpCodes.Ret);

return stub;
}

Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions test/Pose.Tests/RegressionTests.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}

0 comments on commit 6c16d52

Please sign in to comment.