Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 12-add-async-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Miista committed May 2, 2024
2 parents da34def + d4ed536 commit 44e57ef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[![Build status](https://dev.azure.com/palmund/Pose/_apis/build/status/Pose-CI?branchName=master)](https://dev.azure.com/palmund/Pose/_build/latest?definitionId=12)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![NuGet version](https://badge.fury.io/nu/Poser.svg)](https://www.nuget.org/packages/Poser)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Build status](https://dev.azure.com/palmund/Pose/_apis/build/status/Pose-CI?branchName=master&Label=build)](https://dev.azure.com/palmund/Pose/_build/latest?definitionId=12)
[![NuGet version](https://img.shields.io/nuget/v/Poser?logo=nuget)](https://www.nuget.org/packages/Poser)
[![NuGet preview version](https://img.shields.io/nuget/vpre/Poser?logo=nuget)](https://www.nuget.org/packages/Poser)

# Poser

Poser allows you to replace any .NET method (including static and non-virtual) with a delegate. It is similar to [Microsoft Fakes](https://msdn.microsoft.com/en-us/library/hh549175.aspx) but unlike it Poser is implemented _entirely_ in managed code (Reflection Emit API). Everything occurs at runtime and in-memory, no unmanaged Profiling APIs and no file system pollution with re-written assemblies.
Expand Down
5 changes: 3 additions & 2 deletions nuget/Poser.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Poser</id>
<version>2.1.0-alpha0001</version>
<version>2.0.1</version>
<title>Pose</title>
<authors>Søren Guldmund</authors>
<owners>Søren Guldmund</owners>
<projectUrl>https://github.com/Miista/Pose</projectUrl>
<repository type="git" url="https://github.com/Miista/Pose.git" />
<license type="expression">MIT</license>
<!-- <licenseUrl>https://github.com/Miista/pose/blob/master/LICENSE</licenseUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>pose;mocking;testing;unit-test;isolation-framework;test-framework</tags>
<description>Replace any .NET method (including static and non-virtual) with a delegate</description>
<copyright>Copyright 2024</copyright>
<readme>docs\README.md</readme>
<releaseNotes>
Add support for async methods.
Fix bug where `Enum.IsDefined` could not be called from within `PoseContext.Isolate`.
</releaseNotes>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions src/Pose/IL/Stubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static DynamicMethod GenerateStubForDirectCall(MethodBase method)

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

return stub;
}

Expand Down Expand Up @@ -455,7 +455,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 44e57ef

Please sign in to comment.