Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lkaczanowski/10a067574a8b5e67ec68 to your computer and use it in GitHub Desktop.
Save lkaczanowski/10a067574a8b5e67ec68 to your computer and use it in GitHub Desktop.
Resharper teample for testing class with Autofixture and NUnit
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Shortcut/@EntryValue">test</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Description/@EntryValue">Creates NUnit test</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Text/@EntryValue">[Test]&#xD;
public void $MethodName$()&#xD;
{&#xD;
// assign&#xD;
$END$&#xD;
&#xD;
// act&#xD;
&#xD;
&#xD;
// assert&#xD;
}</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Reformat/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Categories/=Testing/@EntryIndexedValue">Testing</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Categories/=Imported_00202015_002D08_002D18/@EntryIndexedValue">Imported 2015-08-18</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Applicability/=Live/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Scope/=C3001E7C0DA78E4487072B7E050D86C5/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Scope/=C3001E7C0DA78E4487072B7E050D86C5/Type/@EntryValue">InCSharpFile</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Scope/=C3001E7C0DA78E4487072B7E050D86C5/CustomProperties/=minimumLanguageVersion/@EntryIndexedValue">2.0</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Field/=MethodName/@KeyIndexDefined">True</s:Boolean>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=2042F55FFF64F8489A3078E18B77EF16/Field/=MethodName/Order/@EntryValue">0</s:Int64>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Shortcut/@EntryValue">setuptest</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Description/@EntryValue">Nunit Test Class</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Text/@EntryValue">using log4net;&#xD;
using log4net.Config;&#xD;
&#xD;
using Ploeh.AutoFixture;&#xD;
using Ploeh.AutoFixture.AutoMoq;&#xD;
using Ploeh.AutoFixture.Idioms;&#xD;
using Ploeh.AutoFixture.Kernel;&#xD;
&#xD;
using NUnit.Framework;&#xD;
&#xD;
namespace $NAMESPACE$&#xD;
{&#xD;
[TestFixture]&#xD;
public class $CLASSNAME$&#xD;
{&#xD;
private $SYSTEMUNDERTEST$ _sut;&#xD;
&#xD;
private IFixture _mockFixture;&#xD;
&#xD;
[TestFixtureSetUp]&#xD;
public void TestFixtureSetup()&#xD;
{&#xD;
GlobalContext.Properties["applicationName"] = "$NAMESPACE$";&#xD;
XmlConfigurator.Configure();&#xD;
}&#xD;
&#xD;
[SetUp]&#xD;
public void Setup()&#xD;
{&#xD;
_mockFixture = new Fixture().Customize(new AutoMoqCustomization());&#xD;
&#xD;
_mockFixture.Customize&lt;$SYSTEMUNDERTEST$&gt;(c =&gt; c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())).OmitAutoProperties());&#xD;
&#xD;
// here freeze your mocks i.e.: Mock&lt;IDependencyMock&gt; dependencyMock = _mockFixture.Freeze&lt;Mock&lt;IDependencyMock&gt;&gt;();&#xD;
&#xD;
_sut = _mockFixture.Create&lt;$SYSTEMUNDERTEST$&gt;();&#xD;
}&#xD;
&#xD;
[Test]&#xD;
public void Ctor_checks_its_arguments()&#xD;
{&#xD;
// arrange &#xD;
var assertion = new GuardClauseAssertion(_mockFixture);&#xD;
&#xD;
// act assert&#xD;
assertion.Verify(typeof($SYSTEMUNDERTEST$).GetConstructors());&#xD;
}&#xD;
}&#xD;
}</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Reformat/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Categories/=Testing/@EntryIndexedValue">Testing</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Categories/=Imported_00202015_002D08_002D18/@EntryIndexedValue">Imported 2015-08-18</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Applicability/=Live/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Scope/=C3001E7C0DA78E4487072B7E050D86C5/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Scope/=C3001E7C0DA78E4487072B7E050D86C5/Type/@EntryValue">InCSharpFile</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Scope/=C3001E7C0DA78E4487072B7E050D86C5/CustomProperties/=minimumLanguageVersion/@EntryIndexedValue">2.0</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=NAMESPACE/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=NAMESPACE/Expression/@EntryValue">fileDefaultNamespace()</s:String>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=NAMESPACE/InitialRange/@EntryValue">-1</s:Int64>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=NAMESPACE/Order/@EntryValue">0</s:Int64>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=CLASSNAME/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=CLASSNAME/Expression/@EntryValue">getFileNameWithoutExtension()</s:String>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=CLASSNAME/InitialRange/@EntryValue">-1</s:Int64>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=CLASSNAME/Order/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=SYSTEMUNDERTEST/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=SYSTEMUNDERTEST/Expression/@EntryValue">getFileNameWithoutExtension()</s:String>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=765573CF3399E14AB0CD621B1251EFF7/Field/=SYSTEMUNDERTEST/Order/@EntryValue">2</s:Int64></wpf:ResourceDictionary>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment