I am using winForms, VS2015 and typemock isolator 8.6.0.0. I was trying to mock out a call to a property setter but I only see the getter being mocked. Is there a way to intercept the call to the setter? (a way to control calls to the setter, not just the example here where trying to throw the exception)
Here is a simple class:
public class PhotonTorpedo
{
public int EnergyLevel
{
get { return 5; }
set
{
Debug.WriteLine("Set");
}
}
public PhotonTorpedo(){}
}
I would like to fake this class, and when the setter is called, throw an exception. But I don't see how to do this. Sample test:
[TestMethod]
public void SetterTest()
{
var fakeTorpedo = Isolate.Fake.AllInstances<PhotonTorpedo>();
Isolate.WhenCalled(() => fakeTorpedo.EnergyLevel).WillThrow(new Exception(""));
string msg = "";
var testTorpeo = new PhotonTorpedo();
try
{
testTorpeo.EnergyLevel = 100;
}
catch (Exception ex)
{
msg = ex.Message;
}
Assert.AreNotEqual(msg, "");
}