pose icon indicating copy to clipboard operation
pose copied to clipboard

Allow to isolate a parent property on a child instance

Open alexanderabramov opened this issue 7 years ago • 1 comments

Version: Nuget Pose 1.2.0.

Trying to shim an instance property of a parent class on an instance of a derived class silently fails. Shimming the same property on an instance of the parent class works great.

Repro test:

class Sut
{
	private string _text;
	public string text { get => _text; set => _text = "unshimmed " + value; }
}
class ChildSut : Sut { }

[Fact]
public void PropertySetterShimWorksOnParent()
{
	var sut = new ChildSut();
	string capturedText = null;
	var shimText = Shim.Replace(() => sut.text, true).With((ChildSut @this, string value) => { capturedText = value; });
	PoseContext.Isolate(() =>
	{
		sut.text = "test";
	}, shimText);

	Assert.Null(sut.text);
	Assert.Equal("test", capturedText);
}

Assert fails with Actual: unshimmed test

alexanderabramov avatar Jun 22 '18 22:06 alexanderabramov

Try changing the ChildSut to Sut, I think I had the same issue with my own isolation attempt

Tarig0 avatar Jun 30 '18 00:06 Tarig0