I have some legacy code I am trying to migrate to Just Mock. There are some static objects that many of our older tests reference. I am slowly starting to re-write these tests with Static Mocking.
How can I have some of my tests use the mocked static while others continue using the old un-mocked static? Ideally, I would like some code I can put either at the end of my test, in a using statement, or in my test/fixture teardown that would revert the static object to its original state and cause the next call to it to execute the static constructor/initialization.
Something like this:
How can I have some of my tests use the mocked static while others continue using the old un-mocked static? Ideally, I would like some code I can put either at the end of my test, in a using statement, or in my test/fixture teardown that would revert the static object to its original state and cause the next call to it to execute the static constructor/initialization.
Something like this:
class MyClass { public static int SomeStatic { get; private set;} static MyClass() { SomeStatic = 15; } } [Test] public void foo() { using (Mock.SetupStatic(typeof(MyClass), Behavior.Strict, StaticConstructor.Mocked)); { Mock.Arrange(() => MyClass.SomeStatic).Returns(5); Assert.AreEqual(5, MyClass.SomeStatic); } Assert.AreEqual(15, MyClass.SomeStatic); }