You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class Blah
{
public string Thing { get; set; }
}
public class BlahWrapper
{
public virtual Blah Blah { get; set; }
public string Thing { get => Blah.Thing; set => Blah.Thing = value; }
}
public class TestService
{
public void Test(BlahWrapper blahWrapper)
{
blahWrapper.Thing = "";
}
}
[Test]
public void ActualTest()
{
var mock = new Mock<BlahWrapper>();
mock
.SetupSet(x => x.Thing = It.IsAny<string>())
.Verifiable();
new TestService().Test(mock.Object);
}
BlahWrapper.Thing is not virtual so this fails to setup but throws an unhelpful error, Could not determine the correct positions for all argument matchers (1 in total) used in a call to this method: ServiceRequestServiceTests.BlahWrapper.get_Blah.
Making BlahWrapper.Thing virtual allows the test to pass. In BlahWrapper, changing public string Thing { get => Blah.Thing; set => Blah.Thing = value; } to public string Thing { get; set; } correctly throws an error about it being non-virtual instead of the above, unhelpful error message.
The text was updated successfully, but these errors were encountered:
Feel free to submit a PR. You'd quickly discover why this is absolutely non-trivial, as everything non-virtual or sealed is basically invisible to Moq 4. Nothing to be done here, the only options as far as I can tell is switching to Moq 5, or otherwise replace the internal matcher guessing machinery behind SetupSet with one that decompiles the passed lambda's IL bytecode.
Simple setup here, using Moq 4.16.1:
BlahWrapper.Thing is not virtual so this fails to setup but throws an unhelpful error,
Could not determine the correct positions for all argument matchers (1 in total) used in a call to this method: ServiceRequestServiceTests.BlahWrapper.get_Blah.
Making BlahWrapper.Thing virtual allows the test to pass. In BlahWrapper, changing
public string Thing { get => Blah.Thing; set => Blah.Thing = value; }
topublic string Thing { get; set; }
correctly throws an error about it being non-virtual instead of the above, unhelpful error message.The text was updated successfully, but these errors were encountered: