Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26: Enum.IsDefined cannot be called from within PoseContext.Isolate #40

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
}