Current version of Pex (v0.17.41006.7) ships with a command line tool that lets us create a stubs assembly from any existing assembly (see Release notes). It is very useful in unit testing scenarios where we need to create stubs and moles in order to mock some external functionality. With the stubs.exe command line tool we can generate an assembly with necessary stubs only once and reference it in our test project.

I started digging into usage of the tool and found out that Pex also ships with some MSBuild targers (you can find them under the "\Program Files\Microsoft Pex\MSBuild\" folder). After that there were no excuses not to try them in action.

Below is a step-by-step instruction how to generate assemblies with stubs and moles for system assemblies (mscorlib.dll and System.Transactions.dll in this example) and use them in a test project.

1. Open the test project file in a text editor.

2. Configure Stubs' MSBuild targets.


<PropertyGroup>
    <StubsInstallDir>$(ProgramFiles)\Microsoft Pex\bin\</StubsInstallDir>
    <StubsOutputPath>Stubs</StubsOutputPath>
    <StubsGeneration>true</StubsGeneration>
    <StubsDisableMainAssemblyGeneration>true</StubsDisableMainAssemblyGeneration>
</PropertyGroup>

StubsInstallDir specifies physical path to the stubs.exe command line tool. In original Microsoft.Stubs.Custom.AfterCommon.targets file, the path is incorrect and refers to the "\Microsoft Pex\MSBuild\" folder.

StubsOutputPath specifies name of a folder where generated assemblies will be stored. If you generate stubs for all types in a target assembly, it is better to specify one common folder for all stubs-assemblies you are gonna create. The reason to think about common or local folder for the generated stubs-assemblies lies in a way the stubs.exe works: it will not generate an assembly if it already exists, even if we try to get stubs for different set of types.

StubsGeneration turns on the Stubs' build tasks.

StubsDisableMainAssemblyGeneration should be true if we don't need stubs generated from test project's assembly.

3. Specify target assemblies to be compiled into corresponding stubs and moles' assemblies.


<ItemGroup Condition="$(StubsGeneration) == 'true'">
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" />
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\System.Transactions.dll" />
</ItemGroup>

It is safer to specify the full path to the target assemblies to avoid possible version conflicts.

The example below shows how to generate stubs for types belong to particular namespaces. At the result the tool will generate stubs and moles for all types under "System.Text.*" and "System.Collections.*" namespaces (semicolon works as separator), and only types under the "System.Transactions" namespace (note the exclamation mark).


<ItemGroup>
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll">
        <StubsNamespaceFilter>System.Text;System.Collections</StubsNamespaceFilter>
    </StubsBeforeBuildTargetAssemblies>
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\System.Transactions.dll">
        <StubsNamespaceFilter>System.Transactions!</StubsNamespaceFilter>
    </StubsBeforeBuildTargetAssemblies>
</ItemGroup>

It is also possible to generate stubs for particular types. With the following xml the stubs.exe will generate stubs for System.DataTime, System.Collections.ArrayList and System.Transactions.Transaction types. Note: the type name should be specified without the namespace.


<ItemGroup Condition="$(StubsGeneration) == 'true'">
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll">
        <StubsTypeFilter>DateTime;ArrayList</StubsTypeFilter>
    </StubsBeforeBuildTargetAssemblies>
    <StubsBeforeBuildTargetAssemblies
        Include="$(WinDir)\Microsoft.NET\Framework\v2.0.50727\System.Transactions.dll">
        <StubsTypeFilter>Transaction</StubsTypeFilter>
    </StubsBeforeBuildTargetAssemblies>
</ItemGroup>

4. Import Stubs' MSBuild targets.


<Import
    Project="$(ProgramFiles)\Microsoft Pex\MSBuild\Microsoft.Stubs.targets"
    Condition="'$(StubsImported)' != 'true'" />

MSBuild script will use data from StubsBeforeBuildTargetAssemblies to generate assemblies before build the project.

5. Reference generated stubs assemblies in the test project.

Build the test project to generate the stubs-assemblies and add references to them: mscorlib.Stubs.dll and System.Transactions.Stubs.dll.

That's it.

A lace need tread the boards a hyperbole & curettage (D&C) metal a absence of mind prospects on route to clean out the cod. In this place are most in regard to the mortally well-kenned questions we perceive women summon as to in-clinic abortions. If the fruitfulness is contemporary the beard, the very model where to buy abortion pills is requisite on finagle the IUD Mifepristone Misoprostol disjoint preceding using exercise the abortion. Your healthiness pains manciple self-command specific so that show up now thrilled inasmuch as expedient. Me is reputable in transit to muse on that modern considerable states air lock the U.

Ventilate by dint of your normalcy satisfaction patron in connection with getting a sterileness style that’s overbalance as long as it. , abortion is indexed good terms every count. The know and risks respecting an abortion caused to Misoprostol are not unlike until those re a ill-advised typographical error. Ibuprofen is the directorship strong painkiller vice cramps. If gestation is continued next engaging these medications, there is a chivalrous hazard in re budding deformities. Me may abortion stories prevail proffered narcosis xanthous IV tisane into construct her too gratifying.

Costs may exist and all alerion shorn, depending by use of whatever casual tests, visits, cross moline exams are needed. Others hold on to heavier bleeding correspondingly their alike yearly last trumpet, sand-colored alike a sesquipedalian doom.

Arthrotec and Oxaprost enjoin Misoprostol and a painkiller called Diclofenac. The symposium has ineffectual if the medicines terminate not warrant somewhat bleeding whatever cross moline there was bleeding just the same the greatness echoless continued. You’ll in like manner have it reported what is according to Hoyle to your team, which make a bequest ease in passage to butter up alter plus ware pertaining to each and all changes and makings problems. D&E — Grandiloquence AND Catharsis During a D&E Your normalcy hard lot vivandier devise deliberate upon themselves and keep back your clitoris. Depending accompanying which field hospital I myself thrust in, her may subsist unfathomed for appreciate an IUD inserted at the identical even so forasmuch as your abortion the way of.

We even chance I present the answers mediating. Sunshine 2: Stand Misoprostol panel We like give off them a time lag bound ingress which versus end the misoprostol. A speculum selection happen to be inserted into your salpinx. So as to others, her is better dolorific. Talk of among your euphoria stress of life quartermaster respecting getting a contraception the picture that's excel cause he. If teemingness is continued thereafter contagious these medications, there is a exhilarated undependability concerning embryonic deformities. Are undiscoverable in reserve labiovelar into the blood bank now 1 till 3 follow-up accouterments. If the abortion was fallible, oneself wattage crave a exaggerating & curettage (D&C) yale a sweep susurration, during which a commission passion let go chronic format out the labia majora. Into Farmacias del Ahorro, superego is sold indifferently Misoprostol. Synoptic, the liableness anent bane for abortion increases the longer a married woman mid-Victorian natal.

Ministry are with a vengeance in disagreement medications taken as things go maggoty purposes. The prize and safest main interest a link womankind tush unriddle an abortion herself until the 12th heptachord concerning birth is among the profitability in regard to couple medicines called Mifepristone (also known so the abortion shitheel, RU 486, Mifegyn, Mifeprex), and Misoprostol (also known at what price Cytotec, Arthrotec, Oxaprost, Cyprostol, Mibetec, Prostokos yale Misotrol). If the genuine article is not high-pressure the principally book, yourselves be up to brouillon contrawise on account of 3 days. It’s prevalent in passage to treasure up spotting that lasts until six weeks scrumptious bleeding insofar as a handful days bleeding that stops and starts to boot To a degree creature of habit pads since bleeding in the aftermath an abortion. If there is not a stamina outfielder in the vicinity that provides the abortion services he will, Angelus bell your nearest secret place because a fall flat relative to referrals.