"Swapping" instead of "Injecting" calls between classes

Eli Lopian, Typemock CEO and awesome Coder, just created a nice little API wrapper around Typemock Isolator that would allow a very simple and readable "Swapping" effect between classes. It would allow you to write code like this:

    [Test]

       public void SwapStatic_CallsFake()

       {

           Swap.StaticCalls<TypeA, TypeB>();

           Assert.AreEqual(2, TypeA.StaticReturnOne());

           Swap.Rollback();

       }

 

       [TestMethod]

       public void SwapInstance_CallsFake()

       {

           Swap.NextNew<OriginalClass, FakeClass>();

           OriginalClass swappedInstance = new OriginalClass();

           Assert.AreEqual(2, swappedInstance.ReturnOne());

       }

 

The first test uses the "Swap" class to replace static calls and redirect them to your own class with static methods. The second one is more advanced and will mock all instance calls made on the next instance that will be created of that type. so the last line on the second test will actually call a method against the FakeClass type.

pretty cool and very readable. download the code and binaries from his post.

Published Saturday, May 17, 2008 9:01 PM by RoyOsherove

Comments

Saturday, May 17, 2008 10:03 PM by whmoca

# re: "Swapping" instead of "Injecting" calls between classes

Could someone shed some light for me.  I was a developer back in the 80's.  I'm now getting ready to contract with a web development company to develop a very dynamic website that involves a significant "match process" and of course want the ability to blog etc.  The Company I'm thinking of going with tells me I can not "own the source code" because it's developed in ASP and Dreamweaver.  Is it true that they can not provide me the source code and therefore I can not own what I'm paying for?  The best they'll do for me is allow me to copywrite the pages.  And I'm sorry if I picked the wrong blog to ask this question in.  This is the 1st blog I've ever written in.

Sunday, May 18, 2008 9:29 AM by JAGregory

# re: "Swapping" instead of "Injecting" calls between classes

This looks very interesting!

Leave a Comment

(required) 
(required) 
(optional)
(required)