예제 #1
0
 public void ShimedAllInstanceMethod()
 {
     var instance = new MyInstanceClass();
     Assert.AreEqual(HHGTTG, MyInstanceClassCaller.MyInstanceMethod(instance));
     using (ShimsContext.Create())
     {
         ShimMyInstanceClass.AllInstances.MyInstanceMethod = @class => FUTURAMA;
         Assert.AreEqual(FUTURAMA, MyInstanceClassCaller.MyInstanceMethod(instance));
     }
 }
예제 #2
0
        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");
            }
        }
예제 #3
0
 public static int MyInstanceMethod(MyInstanceClass instance)
 {
     return instance.MyInstanceMethod();
 }