public void ShimedSingleInstanceMethod() { using (ShimsContext.Create()) { var instance = new ShimMyInstanceClass() { MyInstanceMethod = () => HHGTTG }; Assert.AreEqual(HHGTTG, MyInstanceClassCaller.MyInstanceMethod(instance)); instance = new ShimMyInstanceClass() { MyInstanceMethod = () => FUTURAMA }; Assert.AreEqual(FUTURAMA, MyInstanceClassCaller.MyInstanceMethod(instance)); } }
public void ShimedConstructor() { var instance = new MyInstanceClass(8); Assert.AreEqual(8, MyInstanceClassCaller.MyInstanceMethod(instance)); using (ShimsContext.Create()) { ShimMyInstanceClass.ConstructorInt32 = (@class, i) => { var shim = new ShimMyInstanceClass(@class) { ValueGet = () => -5 }; }; Assert.AreEqual(8, instance.Value, "Instance was created before the shim and so should have original value"); instance = new MyInstanceClass(8); Assert.AreEqual(-5, instance.Value, "Instance was created after the shim was put in place and so will have the original value"); } }
public void ShimedConstructor() { var instance = new MyInstanceClass(8); Assert.AreEqual(8, MyInstanceClassCaller.MyInstanceMethod(instance)); using (ShimsContext.Create()) { ShimMyInstanceClass.ConstructorInt32 = (@class, i) => { var shim = new ShimMyInstanceClass(@class) { ValueGet = () => - 5 }; }; Assert.AreEqual(8, instance.Value, "Instance was created before the shim and so should have original value"); instance = new MyInstanceClass(8); Assert.AreEqual(-5, instance.Value, "Instance was created after the shim was put in place and so will have the original value"); } }