Skip to content

Instantly share code, notes, and snippets.

@sionjlewis
Created December 21, 2016 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sionjlewis/91934e7ab43b967a76db9637b3201b28 to your computer and use it in GitHub Desktop.
Save sionjlewis/91934e7ab43b967a76db9637b3201b28 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Unit Test Async Method</Title>
<Author>Siôn J. Lewis</Author>
<Description>Adds an async unit test method with comments based on the AAA (Arrange,Act,Assert) pattern</Description>
<HelpUrl>https://msdn.microsoft.com/en-us/library/ms165394.aspx</HelpUrl>
<Shortcut>utestasync</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>MethodName</ID>
<ToolTip>Method name: e.g. IsStrawberryRed</ToolTip>
<Default>MethodName</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>Condition</ID>
<ToolTip>Condition: e.g. WhenRipe</ToolTip>
<Default>Condition</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>ExpectedResult</ID>
<ToolTip>Expected result: e.g. True</ToolTip>
<Default>ExpectedResult</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="CSharp" Kind="method decl"><![CDATA[[TestMethod]
public async Task $MethodName$_$Condition$_$ExpectedResult$()
{
// Arrange
$end$
// Act
var result = await Task.FromResult<object>(null);
// Assert
Assert.Fail();
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
@sionjlewis
Copy link
Author

Based upon my original UnitTestMethod.Snippet Gist, this C# Code Snippet can be used within Visual Studio to generates Async Unit Test Methods (Functions).

How to Use

  1. Save the Code Snippet file as UnitTestAsyncMethod.Snippet
  2. For for VS 2015, move the UnitTestMethod.Snippet file into this directory: %userprofile%\Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets
  3. Once installed type: utestasync + [Tab] + [Tab]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment