chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi

I have tried to run the typemock example which is there with the setup.But
the test case is failing for the following code .Can u help me out?

public void MockTheFactoryStaticProperties()
{

Mock factoryMock = MockManager.Mock(typeof(ProductFactory));

factoryMock.ExpectSet("References");



ProductFactory.References = 10;

Assert.AreEqual(0,ProductFactory.References);

factoryMock.ExpectGet("References",5);


Assert.AreEqual(5,ProductFactory.References);
}

Here ProductFactory.References returning 0 instead of 5.
asked by sunny0102 (680 points)

1 Answer

0 votes
I'm gathering you're working with static properties, not instance properties (as noted in the test name). I tried your code in Typemock Isolator 4.2.3 and it passed, but I believe it's technically incorrect because you're setting up instance expectations on static properties.

Try using the "CallStatic" property on the factoryMock instance, like:

factoryMock.CallStatic.ExpectSet("References");


Note the "CallStatic" in there before setting the expectation. This tells Isolator to refer to the static property or method rather than the instance version.

I tested this with a very simple "ProductFactory":

public class ProductFactory
{
  public static int References { get; set; }
}


And when I changed the expectations to use CallStatic, it passed.
answered by tillig (6.7k points)
...