Created
February 22, 2018 13:56
-
-
Save philipmat/45f079fcc88cb205834b3264229cd694 to your computer and use it in GitHub Desktop.
Code Snippets for C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>ilog</Title> | |
<Shortcut>ilog</Shortcut> | |
<Description>Generates a private field to hold a Common.Logging.ILog</Description> | |
<Author>Philip Mateescu</Author> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
</Header> | |
<Snippet> | |
<Declarations> | |
<Literal Editable="false"> | |
<ID>classname</ID> | |
<ToolTip>Class name</ToolTip> | |
<Function>ClassName()</Function> | |
<Default>ClassNamePlaceholder</Default> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp"><![CDATA[private readonly Common.Logging.ILog _log = Common.Logging.LogManager.GetLogger<$classname$>(); | |
$end$]]> | |
</Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> | |
<CodeSnippet Format="1.0.0"> | |
<Header> | |
<Title>Test Fixture (Class)</Title> | |
<Shortcut>testf</Shortcut> | |
<Description>Code snippet for a test fixture (class)</Description> | |
<Author>Philip Mateescu</Author> | |
<SnippetTypes> | |
<SnippetType>Expansion</SnippetType> | |
</SnippetTypes> | |
</Header> | |
<Snippet> | |
<Imports> | |
<Import> | |
<Namespace>FluentAssertions</Namespace> | |
<Namespace>NSubstitute</Namespace> | |
<Namespace>NUnit.Framework</Namespace> | |
</Import> | |
</Imports> | |
<Declarations> | |
<Literal> | |
<ID>name</ID> | |
<ToolTip>Replace with the name of the class being tested</ToolTip> | |
<Default>ClassName</Default> | |
</Literal> | |
<Literal> | |
<ID>method</ID> | |
<ToolTip>Replace with the name of the test method</ToolTip> | |
<Default>Method_WhenCondition_ThenExpectation</Default> | |
</Literal> | |
<Literal Editable="false"> | |
<ID>TestFixture</ID> | |
<Function>SimpleTypeName(global::NUnit.Framework.TestFixture)</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp"><![CDATA[[$TestFixture$] | |
public class $name$Tests | |
{ | |
[Test] | |
public void $method$() | |
{ | |
// Arrange - set up all mocks | |
$end$ | |
// Act - execute the method under test | |
var returnValue = new $name$().Method(); | |
// Assert - check the return value | |
} | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>Test Method</Title> | |
<Shortcut>test</Shortcut> | |
<Description>Code snippet for a test method</Description> | |
<Author>Philip Mateescu</Author> | |
</Header> | |
<Snippet> | |
<Imports> | |
<Import> | |
<Namespace>FluentAssertions</Namespace> | |
<Namespace>NSubstitute</Namespace> | |
<Namespace>NUnit.Framework</Namespace> | |
</Import> | |
</Imports> | |
<Declarations> | |
<Literal> | |
<ID>method</ID> | |
<ToolTip>Replace with the name of the test method</ToolTip> | |
<Default>MethodName</Default> | |
</Literal> | |
<Literal> | |
<ID>condition</ID> | |
<ToolTip>The presumptions and expectations of this test</ToolTip> | |
<Default>DoesWhat_WhenCondition</Default> | |
</Literal> | |
<Literal> | |
<ID>interface</ID> | |
<ToolTip>A dependent interface to be mocked for testing</ToolTip> | |
<Default>IDependendInterface</Default> | |
</Literal> | |
<Literal> | |
<ID>mockmethod</ID> | |
<ToolTip>Method of the mock interface being called by the method under test</ToolTip> | |
<Default>DependentMethod</Default> | |
</Literal> | |
<Literal> | |
<ID>argtype</ID> | |
<ToolTip>The type of the argument received by the mocked method</ToolTip> | |
<Default>string</Default> | |
</Literal> | |
<Literal> | |
<ID>classname</ID> | |
<ToolTip>The class to whom the method under test belongs</ToolTip> | |
<Default>ClassBeingTested</Default> | |
</Literal> | |
<Literal Editable="false"> | |
<ID>Test</ID> | |
<Function>SimpleTypeName(global::NUnit.Framework.Test)</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp"><![CDATA[[$Test$] | |
public void $method$_$condition$() | |
{ | |
// Arrange - set up all mocks | |
var mock = Substitute.For<$interface$>(); | |
mock.$mockmethod$(Arg.Any<$argtype$>()) | |
.Returns($end$); | |
// Act - execute the method under test | |
var returnValue = new $classname$(mock).$method$(); | |
// Assert - check the return value | |
returnValue.Should().Be("expectedValue"); | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>Simple AAA Test Method</Title> | |
<Shortcut>testsimple</Shortcut> | |
<Description>Code snippet for a simple AAA test method</Description> | |
<Author>Philip Mateescu</Author> | |
</Header> | |
<Snippet> | |
<Imports> | |
<Import> | |
<Namespace>FluentAssertions</Namespace> | |
<Namespace>NSubstitute</Namespace> | |
<Namespace>NUnit.Framework</Namespace> | |
</Import> | |
</Imports> | |
<Declarations> | |
<Literal> | |
<ID>method</ID> | |
<ToolTip>Replace with the name of the test method</ToolTip> | |
<Default>MethodName</Default> | |
</Literal> | |
<Literal> | |
<ID>condition</ID> | |
<ToolTip>The presumptions and expectations of this test</ToolTip> | |
<Default>DoesWhat_WhenCondition</Default> | |
</Literal> | |
<Literal Editable="false"> | |
<ID>Test</ID> | |
<Function>SimpleTypeName(global::NUnit.Framework.Test)</Function> | |
</Literal> | |
</Declarations> | |
<Code Language="csharp"><![CDATA[[$Test$] | |
public void $method$_$condition$() | |
{ | |
// Arrange - set up all mocks | |
$end$ | |
// Act - execute the method under test | |
// Assert - check the return value | |
}]]></Code> | |
</Snippet> | |
</CodeSnippet> | |
</CodeSnippets> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment