Skip to content

Commit

Permalink
Merge pull request #50 from nunit/snippets
Browse files Browse the repository at this point in the history
Snippets and templates
  • Loading branch information
OsirisTerje authored Mar 10, 2019
2 parents fbade58 + 30ed059 commit a2366bc
Show file tree
Hide file tree
Showing 24 changed files with 313 additions and 22 deletions.
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ thanks for their great work.

## Download

You can download the extension for Visual Studio 2012-2017 from the [Visual Studio Gallery](https://visualstudiogallery.msdn.microsoft.com/6cd55f79-4936-49e7-b81d-c40fcd81abc7)
You can download the extension for Visual Studio 2012-2019 from the [Visual Studio Gallery](https://visualstudiogallery.msdn.microsoft.com/6cd55f79-4936-49e7-b81d-c40fcd81abc7)
or from the [GitHub Releases](https://github.com/nunit/nunit-vs-templates/releases) page.

## Content
Expand All @@ -21,16 +21,19 @@ The project currently provides the following templates.

### Project Templates

| Template | Platform | Language |
|------------------------------|------------------------------|--------------|
| NUnit 3 Unit Test Project | Desktop | C# |
| NUnit 3 Unit Test Project | Desktop | Visual Basic |
| NUnit 3 Unit Test Project | Xamarin Android <sup>1</sup> | C# |
| NUnit 3 Unit Test Project | Xamarin iOS <sup>1</sup> | C# |
| NUnit 3 Unit Test Project | Xamarin UWP <sup>1,2</sup> | C# |
| Template | Platform | Language | Project Type |
|------------------------------|------------------------------|--------------|----------------------|
| NUnit 3 Unit Test Project | Desktop | C# | Traditional Style <sup>3</sup> |
| NUnit 3 Unit Test Project | Desktop | C# | Sdk Style |
| NUnit 3 Unit Test Project | Desktop .NET Core | C# | SDK Style |
| NUnit 3 Unit Test Project | Desktop | Visual Basic | Traditional Style <sup>3</sup> |
| NUnit 3 Unit Test Project | Xamarin Android <sup>1</sup> | C# | Traditional Style |
| NUnit 3 Unit Test Project | Xamarin iOS <sup>1</sup> | C# | Traditional Style |
| NUnit 3 Unit Test Project | Xamarin UWP <sup>1,2</sup> | C# | Traditional Style |

1. Requires [Xamarin for Visual Studio](https://xamarin.com/visual-studio) be installed.
2. Requires the [Windows 10 SDK](https://dev.windows.com/en-us/downloads/windows-10-sdk) be installed.
3. Legacy csproj format

### Item Templates

Expand All @@ -43,11 +46,18 @@ The project currently provides the following templates.

### Code Snippets

| Snippet | Shortcut | Language |
|-----------------|--------------|---------------|
| Test Fixture | ntestfixture | C# |
| Test Method | ntest | C# |
| Test Case | ntestcase | C# |
| Snippet | Shortcut | Language | Comment |
|-----------------|--------------|---------------|---------|
| Test Fixture | ntestfixture | C# | |
| Test Method | ntest | C# | |
| Test Case | ntestcase | C# | |
| Test Case Source | ntestcasesource | C# | Form 1 |
| Test Case Source | ntestcasesource2 | C# | Form 2 |
| Test Case Source | ntestcasesource3 | C# | Form 3 |
| Test Case Source | ntestcasesource4 | C# | Form 3 with testdata|
| Assert.Multiple | nmultiple | C# | Surround snippet |

Note: "Form": Refer to [documentation for details](https://github.com/nunit/docs/wiki/TestCaseSource-Attribute)

## Contributing

Expand All @@ -66,7 +76,7 @@ There is also a great walkthrough on creating templates in the
We highly recommend that you use the following extensions for Visual Studio when
working on this project.

- [SideWaffle](http://sidewaffle.com/) (Required) - Adds the
- [SideWaffle](http://sidewaffle.com/) (Not needed, now included as nuget package) - Adds the
templates and functionality you will need to work on this project.
- [Snippet Designer](https://github.com/mmanela/SnippetDesigner) - Provides a
friendly UI for editing code snippets.
Expand Down
Binary file added nunit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using System;

namespace $rootnamespace$
{
[SetUpFixture]
public class $safeitemname$
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
// TODO: Add code here that is run before
// all tests in the assembly are run
}

[OneTimeTearDown]
public void OneTimeTearDown()
{
// TODO: Add code here that is run after
// all tests in the assembly have been run
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Option Explicit On

Imports System
Imports NUnit.Framework

Namespace $rootnamespace$

<SetUpFixture>
Public Class $safeitemname$

<OneTimeSetUp>
Public Sub OneTimeSetUp()
' TODO Add code here that is run before
' all tests in the assembly are run
End Sub

<OneTimeTearDown>
Public Sub OneTimeTearDown()
' TODO Add code here that is run after
' all tests in the assembly have been run
End Sub

End Class

End Namespace
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<ProjectType>CSharp</ProjectType>

<Category>CSharp</Category>
<DefaultName>TestClass.cs</DefaultName>
<Name>NUnit Test Fixture</Name>
<Description>A class that contains NUnit unit tests (C#) </Description>
<Icon>icon.png</Icon>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<TemplateID>9936e07b-28c2-44ad-99da-d00b06c4e168</TemplateID>
<SortOrder>2000</SortOrder>
<AppliesTo>CSharp</AppliesTo>
</TemplateData>
<TemplateContent>
<References />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<ProjectType>VisualBasic</ProjectType>

<Category>VisualBasic</Category>
<DefaultName>TestClass.vb</DefaultName>
<Name>NUnit Test Fixture</Name>
<Description>A class that contains NUnit unit tests (VB)</Description>
<Icon>icon.png</Icon>
<NumberOfParentCategoriesToRollUp>1</NumberOfParentCategoriesToRollUp>
<TemplateID>cb5f52ba-bd65-42e6-bbbf-f58c96cfd3c0</TemplateID>
<SortOrder>2000</SortOrder>
<AppliesTo>VisualBasic</AppliesTo>
</TemplateData>
<TemplateContent>
<References />
Expand Down
22 changes: 22 additions & 0 deletions nunit.templates/ItemTemplates/Test/NUnit Test Fixture/TestClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace $rootnamespace$
{
[TestFixture]
public class $safeitemname$
{
[Test]
public void TestMethod()
{
// TODO: Add your test code here
var answer = 42;
Assert.That(answer, Is.EqualTo(42), "Some useful error message");
}
}
}
20 changes: 20 additions & 0 deletions nunit.templates/ItemTemplates/Test/NUnit Test Fixture/TestClass.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Option Explicit On

Imports System
Imports NUnit.Framework

Namespace $rootnamespace$

<TestFixture>
Public Class $safeitemname$

<Test>
Public Sub TestMethod()
' TODO Add your test code here
Dim answer = 42
Assert.That(answer, [Is].EqualTo(42), "Some useful error message")
End Sub

End Class

End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Description>Code snippet for a testcasesource method, using Form 1 - [TestCaseSource(string sourceName)]</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>ntestcasesource1</Shortcut>
<Shortcut>ntestcasesource</Shortcut>
</Header>
<Snippet>
<Imports>
Expand Down
Binary file added nunit.templates/nunit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion nunit.templates/nunit.templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<Content Include="Packages\pclstorage.1.0.2.nupkg">
<Content Include="Packages\pclstorage.1.0.2.nupkg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
Expand Down Expand Up @@ -177,6 +177,12 @@
</Reference>
</ItemGroup>
<ItemGroup>
<TemplateReference Include="nunit.tests.sdkstyle.csharp.csproj">
<PathToProject>../nunit.tests.sdkstyle.csharp/nunit.tests.sdkstyle.csharp.csproj</PathToProject>
</TemplateReference>
<TemplateReference Include="nunit.tests.core.csharp.csproj">
<PathToProject>../nunit.tests.core.csharp/nunit.tests.core.csharp.csproj</PathToProject>
</TemplateReference>
<TemplateReference Include="nunit.tests.csharp.csproj">
<PathToProject>../nunit.tests.csharp/nunit.tests.csharp.csproj</PathToProject>
</TemplateReference>
Expand Down
2 changes: 1 addition & 1 deletion nunit.templates/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="nunit.templates.b29e95b8-bf26-4f03-983d-f1d0f21ad6ef" Version="1.4.20" Language="en-US" Publisher="Rob Prouse" />
<Identity Id="nunit.templates.b29e95b8-bf26-4f03-983d-f1d0f21ad6ef" Version="1.5.0" Language="en-US" Publisher="Rob Prouse" />
<DisplayName>NUnit VS Templates</DisplayName>
<Description xml:space="preserve">Provides Visual Studio project and item templates for NUnit 3 along with code snippets.</Description>
<MoreInfo>https://github.com/nunit/nunit-vs-templates</MoreInfo>
Expand Down
20 changes: 20 additions & 0 deletions nunit.tests.core.csharp/TestClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// NUnit 3 tests
// See documentation : https://github.com/nunit/docs/wiki/NUnit-Documentation
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

namespace $safeprojectname$
{
[TestFixture]
public class $safeitemname$
{
[Test]
public void TestMethod()
{
// TODO: Add your test code here
var answer = 42;
Assert.That(answer, Is.EqualTo(42), "Some useful error message");
}
}
}
41 changes: 41 additions & 0 deletions nunit.tests.core.csharp/_Definitions/_project.vstemplate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>NUnit 3 .NET Core Unit Test Project</Name>
<Description>A project that contains .NET Core NUnit 3 unit tests (C#)</Description>
<DefaultName>NUnit.Tests</DefaultName>
<ProjectType>CSharp</ProjectType>
<Category>CSharp</Category>
<ProjectSubType></ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<ProvideDefaultName>true</ProvideDefaultName>
<PromptForSaveOnCreation>true</PromptForSaveOnCreation>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<!-- <Icon>nunit.png</Icon> -->
<TemplateID>b0d3ff60-1340-4462-abf6-7d7cc9f175c5</TemplateID>
<!-- Indicates how many parent folders this item template should appear in -->
<NumberOfParentCategoriesToRollUp>0</NumberOfParentCategoriesToRollUp>
<AppliesTo>CSharp</AppliesTo>
<CreateInPlace>true</CreateInPlace>
</TemplateData>
<TemplateContent>
<Project TargetFileName="NUnit.Tests.Core.csproj" File="NUnit.Tests.Core.CSharp.csproj" ReplaceParameters="true">
</Project>
<CustomParameters>
<CustomParameter Name = "$language$" Value="CSharp" />
</CustomParameters>

</TemplateContent>
<WizardExtension>
<Assembly>NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>NuGet.VisualStudio.TemplateWizard</FullClassName>
</WizardExtension>
<WizardData>
<!-- <packages repository="extension" repositoryId="nunit.templates.b29e95b8-bf26-4f03-983d-f1d0f21ad6ef">
<package id="NUnit" version="3.11.0" />
<package id="NUnit3TestAdapter" version="3.13.0" />
<package id="Microsoft.NET.Test.Sdk" version="15.9.0" />
</packages> -->
</WizardData>
</VSTemplate>
11 changes: 11 additions & 0 deletions nunit.tests.core.csharp/_preprocess.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<Preprocess>
<!--
You can specify the path where this should show up in the
Add New Project / Add New Item dialog by setting the value below
-->
<TemplateInfo Path="CSharp\Test"/>
<Replacements Include="*.*" Exclude="*.vstemplate;*.fsproj;*.vbproj;*.jpg;*.png;*.ico;_preprocess.xml;_project.vstemplate.xml">
<add key="NUnit.Tests" value="$safeprojectname$"/>
</Replacements>
</Preprocess>
15 changes: 15 additions & 0 deletions nunit.tests.core.csharp/nunit.tests.core.csharp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion nunit.tests.csharp/_Definitions/_project.vstemplate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Description>A project that contains NUnit 3 unit tests (C#)</Description>
<DefaultName>NUnit.Tests</DefaultName>
<ProjectType>CSharp</ProjectType>
<Category>CSharp</Category>
<ProjectSubType></ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
Expand All @@ -12,9 +13,10 @@
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<Icon>nunit.png</Icon>
<TemplateID>b0d3ff60-1340-4462-abf6-7d7cc9f175c5</TemplateID>
<TemplateID>b0d3ff60-1340-4462-abf6-7d7cc9f175c6</TemplateID>
<!-- Indicates how many parent folders this item template should appear in -->
<NumberOfParentCategoriesToRollUp>0</NumberOfParentCategoriesToRollUp>
<AppliesTo>CSharp</AppliesTo>
</TemplateData>
<TemplateContent>
<Project TargetFileName="NUnit.Tests.csproj" File="NUnit.Tests.CSharp.csproj" ReplaceParameters="true">
Expand Down
5 changes: 5 additions & 0 deletions nunit.tests.csharp/_preprocess.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
<TemplateInfo Path="CSharp\Test"/>
<Replacements Include="*.*" Exclude="*.vstemplate;*.fsproj;*.vbproj;*.jpg;*.png;*.ico;_preprocess.xml;_project.vstemplate.xml">
<add key="NUnit.Tests" value="$safeprojectname$"/>
<!--targetFramework="4.0"-->
<add key="targetFramework=&quot;4.0&quot;" value="targetFramework=&quot;$targetframeworkversion$&quot;"/>
<!--<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>-->
<add key="&lt;TargetFrameworkVersion&gt;v4.0&lt;/TargetFrameworkVersion&gt;"
value="&lt;TargetFrameworkVersion&gt;v$targetframeworkversion$&lt;/TargetFrameworkVersion&gt;"/>
</Replacements>
</Preprocess>
20 changes: 20 additions & 0 deletions nunit.tests.sdkstyle.csharp/TestClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// NUnit 3 tests
// See documentation : https://github.com/nunit/docs/wiki/NUnit-Documentation
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;

namespace $safeprojectname$
{
[TestFixture]
public class $safeitemname$
{
[Test]
public void TestMethod()
{
// TODO: Add your test code here
var answer = 42;
Assert.That(answer, Is.EqualTo(42), "Some useful error message");
}
}
}
Loading

0 comments on commit a2366bc

Please sign in to comment.