Skip to content

Issue with .Net static methods like File.Exists #70

@sberthu

Description

@sberthu

Hello,
In .Net5 Framework, I have a Xunit Test class like this:

using Pose;
using System.IO;
using Xunit;
public class MyTest {
	public bool test(string path)
	{
		bool ret = File.Exists(path);
		if (!ret)
		{
			throw new FileNotFoundException("Not Found");
		}
		return ret;
    }
	[Fact]
	public void test_shouldSuccess()
	{
		string path = "anyKindOfPath must success";
		Shim shim = Shim.Replace(() => File.Exists(Is.A<string>())).With((string path) => true);

		var result = false;
		
		PoseContext.Isolate(() =>
		{
			result = test(path);
		}, shim);
		// assert
		Assert.True(result);
	}
}

We are ok that the File.Exists in test method is never call and be replace by the lambda wich is always true.
When I run this simple code, I get the Exception "Not Found". The shim seems to be never called like expected.
I run the 2.1 version of Pose downloaded from Github. The 2.1 version in Nuget crash with a "System.InvalidProgramException".
I think this is the .Net Framework Version wich is incompatible with .net 5.0
Thank for your reply

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions