This is very easy to do using expectations that can be verified with Typemock Isolator. Here is a sample:
public interface ISomeInterface
{
bool BooleanProperty { set; }
}
public class InterfaceConsumer
{
private ISomeInterface _ctorParam;
public InterfaceConsumer(ISomeInterface ctorParam)
{
this._ctorParam = ctorParam;
}
public void MethodWithParam(ISomeInterface methodParam)
{
methodParam.BooleanProperty = true;
}
public void MethodAllInternal()
{
this._ctorParam.BooleanProperty = true;
}
}
[TestFixture]
[VerifyMocks]
public class MyTestFixture
{
[Test]
public void TestMethodWithParam()
{
ISomeInterface methodParam = RecorderManager.CreateMockedObject<ISomeInterface>();
using(RecordExpectations r = RecorderManager.StartRecording())
{
methodParam.BooleanProperty = true;
r.CheckArguments();
}
InterfaceConsumer consumer = new InterfaceConsumer(null);
consumer.MethodWithParam(methodParam);
}
[Test]
public void TestMethodAllInternal()
{
ISomeInterface ctorParam = RecorderManager.CreateMockedObject<ISomeInterface>();
using(RecordExpectations r = RecorderManager.StartRecording())
{
ctorParam.BooleanProperty = true;
r.CheckArguments();
}
InterfaceConsumer consumer = new InterfaceConsumer(ctorParam);
consumer.MethodAllInternal();
}
}
In the above examples, you can see how I have an interface with just a setter, and a couple of different ways to get the dependency in there - in one case, a method that takes a parameter; in another case, a constructor that gets it passed in.
In either case, the way you test it is by setting expectations in the recorder block - you'll see that I'm calling "CheckArguments" to verify the value that the property is being set to as soon as the mocks get verified (via the VerifyMocks attribute).
If you have a factory or some other mechanism that's inserting the dependency (maybe you're calling a static method to generate the instance of the interface you're using, etc.) then it just means a couple of additional mocks to set up - you can mock the return value of the static factory method to return your mock interface implementation, for example.
In any case, it's the "CheckArguments" that does the magic.