How did we do that?!!

If you have read my previous post about the TypeMock Test Attributes you probably have noticed that the attributes are test framework agnostic!

So how did we do that?

We tried to add our attributes using implementing the hooks of each framework. But we found this way to be unstable:

  • mbUnit is the easiest framework to extend, it is build with extensions in mind, but the extensions are version specific
  • nUnit has just started supporting extensions and the system is fragile, the extension system requires deploying to each nunit installation (and TestDriven.NET too) and needs to be redistributed for each nunit version as the extensions are version specific.
  • msTest (the Visual Studio Team System) currently has no means to extend and add attributes.

Then we remembered that TypeMock has an AOP framework. We can inject the Attributes! This is what we did.

We spiked and wrote the following code

[TestFixture] public class Spike { [SetUp] public void InjectVerifyMocks() { foreach (MethodInfo info in this.GetType().GetMethods()) { if (info.GetCustomAttributes(typeof(VerifyMeAttribute), false).Length > 0) { Mock m = MockManager.MockAll(this.GetType()); MethodInfo keepInfo = info; m.AlwaysReturn(info.Name, new DynamicReturnValue( delegate(object[] p, object c) { keepInfo.Invoke(c, p); MockManager.Verify(); return null; // void method })); } } } [Test] [VerifyMe] public void SpikeTest() { Mock m = MockManager.Mock<MockedClass>(); m.ExpectAndReturn("Method",10); } }

Ok, so what are we doing here?

In the setup we are scanning all the methods for a custom attribute. When we find such a method we mock ourselves!!! and change the behavior of our methods to return a dynamic return.

The dynamic return will call ourselves again!!! (via reflection) and then verify the mocks.

When we run the test (in all frameworks) it fails with VerifyException.

TestCase 'Spike.SpikeTest' failed: TypeMock.VerifyException : TypeMock Verification: Method MockedClass.Method() has 1 more expected calls

This works because while we are in the DynamicReturnValue Delegate, TypeMock is turned off and no methods are mocked. So we don’t recursively call ourselves, but on the other hand this means that our mocks are all turned off. 

This was just a spike to prove that it was possible, it took more time to implemented the extension system that will work for all testing frameworks.

I will publish how to extend and create your own attributes when we release the beta version.

  1. With the development of fashional world, Jimmy Choo Shoes UK Online Store with exquisite and excellent design is familiar to more and more people. Being a bride means another chapter of a woman’s life. Women dream to have a perfect, one of a kind wedding and walk down the isle with her lovely wedding gown, accessories, make up and of course her wedding shoes. The Jimmy Choo Wedding Shoes based on style and elegance, these Jimmy Choo sneakers are extremely in fashion is your best choice.
    jimmy choo outlet uk

  2. THREE RIVERS, MI— When the Powerball lottery drawing got really big, Julie Leach was known to buy more tickets. It is easy to say things, to suggest that we would be brave where others weren’t, that we have some kind of inner resource to be tapped when we really need it. z michael kors outlet store
    I lookforward to watching Mesa’s continued growth and success. Rick Kleiner, with Picor, represented both parties.
    Richard S. Stamm, representative, Carol A. Plumb and Catherine E. Stamm, estate, to Julie Ann Russell, 1 Manor Road, $190,000. My comments about deception is that the initiative is certainly at war with oil corporations, but tries to hide it behind claims that are distorted and senseless insults to the workers and even innocent owners. w michael kors outlet
    Crozon s 3-point attempt with two seconds left was no good coach outlet It is a rich and milky dish that gets its name from the stewed wild boar that dead Vikings – according to Norse mythology – ate in Valhalla.
    m The faster Red Wings have outskated and outplayed the Bruins through two periods and hold a 24-13 edge in shots. cheap michael kors bags “You can get more bang for your buck because your light is being directed where you want it,” Ledbetter said. louis vuitton handbags
    David Cobb, TEN, vs. coach outlet It was a frightening situation, so similar to court-rushes when Arizona lost at Cal’s Haas Pavilion and USC’s Galen Center already this year, not to mention past skirmishes at ASU’s Wells Fargo Arena and some ugly scenes at Oregon State’s Gill Coliseum.
    If you’re The Country Cat’s Adam and Jackie Sappington, you sign on as the latest tenants at Pine Street Market, the opening in Old Town. coach bags Tickets: $15$20 plus fees. s coach outlet online
    sd-embed class sd-embedded-media” data-embed-file 696850347751563264 ” data-embed-type twitter” id ui-id-31″sd-embed coach outlet store The Chandler Police Department is accepting applications for motorist assist volunteers to respond to reports of stranded motorists, crash scenes and other non-criminal calls for service.
    To say it’s something different wouldn’t do it justice. How much? $21.
    In addition, the holiday season also seems to give us permission to eat without pause. cheap air jordans General admission is $50 and chamber admission is $35, and additional information is available by visiting .
    Tibshraeny also thanked members of volunteer organizations in Chandler from Our Volunteer Income Tax Assistance program, which saved residents $400,000 in tax preparation fees and earned $1. michael kors outlet The Food and Drug Administration wants to know if these memorable images skew perceptions of risks associated with medications.
    g js%22%3E%3Cscript%3E%0A%3Cdiv%20data-cnnvansinglewidget%20data-affiliate=%22ktvo%22%20data-videoid=%22entertainment20160207beyonce-drops-new-single-formation-orig-vstop-bb. coach outlet online Follow reporter and blogger?Becky Pallack onTwitter.
    He was hit by a car and suffered a broken jaw, but will make a full recovery. coach bags All riders are required to bring their own helmet as well as plenty of water and an extra tube. n coach outlet online
    “Am I the only one who thinks these booking displays are less than honest? I mean, how many people actually click on the “Rules & Restrictions” link at the very bottom of the page to find out whether their room is refundable?video-ad-asset-container, video-ad-asset-container-played max-height: 0px; overflow: hidden; -webkit-transition: max-height 1s; -moz-transition: max-height 1s; transition: max-height 1s;video-ad-asset-container. cheap jordans Officers will be looking for signs of alcohol and/or drug impairment with officers checking drivers for proper licensing delaying motorists only momentarily.
    x “C-HR” stands for Compact size and High Ride. With four side doors and a hatch, Scion says it’s the perfect vehicle for what it calls “yuccies,” or young urban creatives. coach outlet online The mayor understands the smallbusiness community and cares about economic growth, Donaldson said. l
    To my surprise I didn’t receive a polite formal acknowledgement but a long, handwritten personal letter that was entirely in character with her growing involvement with the Alzheimer’s community coach outlet He also will honor Bert Campaneris’ fete of playing nine positions in a game five decades ago.
    After its cancellation, the failed “Star Trek” series launched a billion dollar film and TV franchise. coach outlet online Madeline Marks, Bentonville, 1:55. t
    sd-embed class sd-embedded-media” data-embed-file 707534398409850880 ” data-embed-type twitter” id ui-id-28″sd-embed Statewide, more than 3,700 cases of flu have been reported, with 51 percent of those in Maricopa County, according to the Arizona Department of Health Services.
    “The department has addressed the errors that originally occurred and we are ready to get the tax amnesty program underway,” said Secretary of Revenue Tim Barfield in a news release. “We mailed corrected letters to the taxpayers last week, and we sincerely apologize to them for this mistake and for any inconvenience that we have may have caused.” coach factory outlet He is applying a lot of pressure, including threats to cut off financial help toward schooling. f
    But I’m not sure if that would have prevented it. louis vuitton outlet ” No kidding!

Add Comment

Required fields are marked *. Your email address will not be published.