Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arphox/9f37fa5c88851b779539a65c5abac2cd to your computer and use it in GitHub Desktop.
Save arphox/9f37fa5c88851b779539a65c5abac2cd to your computer and use it in GitHub Desktop.
ReSharper live template to create an NUnit test method which tests that the given code throws `ArgumentNullException`

Use the .DotSettings file to import.

Preview:

[Test] 
public void If$ParameterName$IsNull_ThrowsException() 
{ 
    // Arrange & Act 
    Action act = () => $END$;

    // Assert 
    act.Should().Throw<ArgumentNullException>() 
        .WithMessage("*$ParameterName$*"); 
} 

Also uses FluentAssertions!

<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/=4F7BBE6511DA884A97FABC3C86928FB2/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Shortcut/@EntryValue">testargexnull</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Description/@EntryValue">Expect ArgumentNullException</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Text/@EntryValue">[Test]&#xD;
public void If$ParameterName$IsNull_ThrowsException()&#xD;
{&#xD;
// Arrange &amp; Act&#xD;
Action act = () =&gt; $END$;&#xD;
&#xD;
// Assert&#xD;
act.Should().Throw&lt;ArgumentNullException&gt;()&#xD;
.WithMessage("*$ParameterName$*");&#xD;
}</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Reformat/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/ShortenQualifiedReferences/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Applicability/=Live/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Scope/=B68999B9D6B43E47A02B22C12A54C3CC/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Scope/=B68999B9D6B43E47A02B22C12A54C3CC/Type/@EntryValue">InCSharpTypeMember</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Scope/=B68999B9D6B43E47A02B22C12A54C3CC/CustomProperties/=minimumLanguageVersion/@EntryIndexedValue">2.0</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Scope/=ABDFB0613102DF4DBB59387506ADA616/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Scope/=ABDFB0613102DF4DBB59387506ADA616/Type/@EntryValue">InProjectWithReference</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Scope/=ABDFB0613102DF4DBB59387506ADA616/CustomProperties/=mask/@EntryIndexedValue">nunit.framework|nunit</s:String>
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Field/=ParameterName/@KeyIndexDefined">True</s:Boolean>
<s:Int64 x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=4F7BBE6511DA884A97FABC3C86928FB2/Field/=ParameterName/Order/@EntryValue">0</s:Int64></wpf:ResourceDictionary>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment