pose icon indicating copy to clipboard operation
pose copied to clipboard

Issue with .Net static methods like File.Exists

Open sberthu opened this issue 3 years ago • 0 comments

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

sberthu avatar Jan 17 '22 15:01 sberthu