Wednesday, 17 December 2008

Code snippets for Isolator

I've worked a little with the AAA syntax of the isolator and after writing a couple of tests I felt the need to add some snippets to make things go faster. So here a couple I found useful.

(In order to use just copy each xml code into a .snippet file and use the snippet manager to import them)

The first one is for creating faked instance:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet
Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>
Expansion</SnippetType>
</SnippetTypes>
<Title>
Typemock Fake</Title>
<Shortcut>
tf</Shortcut>
<Description>
Create a fake instance</Description>
<Author>
Lior Friedman</Author>
</Header>
<Snippet>
<Declarations>
<Object
Editable="true">
<ID>
Class</ID>
<ToolTip>
</ToolTip>
<Default>
T</Default>
<Function>
</Function>
</Object>
</Declarations>
<Code
Language="csharp"><![CDATA[$Class$ fake = Isolate.Fake.Instance<$Class$>();]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

The second one if for setting the behavior of a method call:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet
Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>
Expansion</SnippetType>
</SnippetTypes>
<Title>
Typemock When Called</Title>
<Shortcut>
twc</Shortcut>
<Description>
Create a fake instance</Description>
<Author>
Lior Friedman</Author>
</Header>
<Snippet>
<Declarations>
<Object
Editable="true">
<ID>
Method</ID>
<ToolTip>
</ToolTip>
<Default>
fake.DoStuff()</Default>
<Function>
</Function>
</Object>
<Object
Editable="true">
<ID>
Action</ID>
<ToolTip>
</ToolTip>
<Default>
WillReturn</Default>
<Function>
</Function>
</Object>
<Object
Editable="true">
<ID>
Value</ID>
<ToolTip>
</ToolTip>
<Default>
0</Default>
<Function>
</Function>
</Object>
</Declarations>
<Code
Language="csharp"><![CDATA[Isolate.WhenCalled(() => $Method$).$Action$($Value$);]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

and the last one is for verification:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet
Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>
Expansion</SnippetType>
</SnippetTypes>
<Title>
Typemock Verify</Title>
<Shortcut>
tv</Shortcut>
<Description>
Verfiy a call was made</Description>
<Author>
Lior Friedman</Author>
</Header>
<Snippet>
<Declarations>
<Object
Editable="true">
<ID>
Method</ID>
<ToolTip>
</ToolTip>
<Default>
fake.DoStuff()</Default>
<Function>
</Function>
</Object>
</Declarations>
<Code
Language="csharp"><![CDATA[Isolate.Verify.WasCalledWithAnyArguments(() => $Method$);]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

0 comments:

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Walgreens Printable Coupons