Skip to content

Commit 3a2c302

Browse files
committed
Added tests project and various snippet unit tests
1 parent 78d8084 commit 3a2c302

File tree

4 files changed

+245
-0
lines changed

4 files changed

+245
-0
lines changed

Tests/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("5138a23a-cb00-4368-bff7-bf0d62b878fd")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Tests/SnippetTests.cs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.IO;
3+
using System.Xml;
4+
using Microsoft.VisualStudio.TestTools.UnitTesting;
5+
6+
namespace Tests
7+
{
8+
[TestClass]
9+
public class SnippetTests
10+
{
11+
// update path to lcoal project directory
12+
private string path = @"C:\Projects\Visual-Studio-jQuery-Code-Snippets\jQueryCodeSnippets";
13+
14+
[TestMethod]
15+
public void SnippetTitlesAreCorrect()
16+
{
17+
foreach (var snippetFile in Directory.EnumerateFiles(path, "*.snippet", SearchOption.AllDirectories))
18+
{
19+
var filePaths = snippetFile.Split(new string[] { "\\" }, StringSplitOptions.None);
20+
var fileName = filePaths[filePaths.Length - 1];
21+
var snippetName = fileName.Split('.')[0];
22+
23+
var snippetDoc = new XmlDocument();
24+
snippetDoc.Load(snippetFile);
25+
26+
var titleNode = snippetDoc.GetElementsByTagName("Title");
27+
var title = titleNode[0].InnerText;
28+
29+
Assert.IsTrue(snippetName == title);
30+
}
31+
}
32+
33+
[TestMethod]
34+
public void SnippetShortcutsAreCorrect()
35+
{
36+
foreach (var snippetFile in Directory.EnumerateFiles(path, "*.snippet", SearchOption.AllDirectories))
37+
{
38+
var filePaths = snippetFile.Split(new string[] { "\\" }, StringSplitOptions.None);
39+
var fileName = filePaths[filePaths.Length - 1];
40+
var snippetName = fileName.Split('.')[0];
41+
42+
var snippetDoc = new XmlDocument();
43+
snippetDoc.Load(snippetFile);
44+
45+
var shortcutNode = snippetDoc.GetElementsByTagName("Shortcut");
46+
var shortcut = shortcutNode[0].InnerText;
47+
48+
Assert.IsTrue(snippetName == shortcut);
49+
}
50+
}
51+
52+
[TestMethod]
53+
public void SnippetsHaveDescriptions()
54+
{
55+
foreach (var snippetFile in Directory.EnumerateFiles(path, "*.snippet", SearchOption.AllDirectories))
56+
{
57+
var snippetDoc = new XmlDocument();
58+
snippetDoc.Load(snippetFile);
59+
60+
var descriptionNode = snippetDoc.GetElementsByTagName("Description");
61+
62+
Assert.IsTrue(descriptionNode != null && descriptionNode[0].InnerText != null);
63+
64+
var description = descriptionNode[0].InnerText;
65+
66+
Assert.IsTrue(description != string.Empty && description.Length > 10);
67+
}
68+
}
69+
70+
[TestMethod]
71+
public void SnippetsHaveAuthors()
72+
{
73+
foreach (var snippetFile in Directory.EnumerateFiles(path, "*.snippet", SearchOption.AllDirectories))
74+
{
75+
var snippetDoc = new XmlDocument();
76+
snippetDoc.Load(snippetFile);
77+
78+
var authorNode = snippetDoc.GetElementsByTagName("Author");
79+
80+
Assert.IsTrue(authorNode != null && authorNode[0].InnerText != null);
81+
82+
var author = authorNode[0].InnerText;
83+
84+
Assert.IsTrue(author != string.Empty && author.Length > 5);
85+
}
86+
}
87+
88+
[TestMethod]
89+
public void SnippetsHaveHelpUrls()
90+
{
91+
var helpUrl = "https://github.com/kspearrin/Visual-Studio-jQuery-Code-Snippets";
92+
93+
foreach (var snippetFile in Directory.EnumerateFiles(path, "*.snippet", SearchOption.AllDirectories))
94+
{
95+
var snippetDoc = new XmlDocument();
96+
snippetDoc.Load(snippetFile);
97+
98+
var urlNode = snippetDoc.GetElementsByTagName("HelpUrl");
99+
100+
Assert.IsTrue(urlNode != null && urlNode[0].InnerText != null);
101+
102+
var url = urlNode[0].InnerText;
103+
104+
Assert.IsTrue(url != string.Empty && url == helpUrl);
105+
}
106+
}
107+
108+
[TestMethod]
109+
public void SnippetsAreProperFormattedXml()
110+
{
111+
foreach (var snippetFile in Directory.EnumerateFiles(path, "*.snippet", SearchOption.AllDirectories))
112+
{
113+
var contents = File.ReadAllText(snippetFile);
114+
115+
Assert.IsTrue(contents.Contains("<?xml version=\"1.0\" encoding=\"utf-8\"?>"));
116+
}
117+
}
118+
}
119+
}

Tests/Tests.csproj

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{90164978-E461-4BD8-8F21-15B199E7AFB1}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<AppDesignerFolder>Properties</AppDesignerFolder>
9+
<RootNamespace>Tests</RootNamespace>
10+
<AssemblyName>Tests</AssemblyName>
11+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
15+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
16+
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
17+
<IsCodedUITest>False</IsCodedUITest>
18+
<TestProjectType>UnitTest</TestProjectType>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.XML" />
40+
</ItemGroup>
41+
<Choose>
42+
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
43+
<ItemGroup>
44+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
45+
</ItemGroup>
46+
</When>
47+
<Otherwise>
48+
<ItemGroup>
49+
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
50+
</ItemGroup>
51+
</Otherwise>
52+
</Choose>
53+
<ItemGroup>
54+
<Compile Include="SnippetTests.cs" />
55+
<Compile Include="Properties\AssemblyInfo.cs" />
56+
</ItemGroup>
57+
<Choose>
58+
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
59+
<ItemGroup>
60+
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
61+
<Private>False</Private>
62+
</Reference>
63+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
64+
<Private>False</Private>
65+
</Reference>
66+
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
67+
<Private>False</Private>
68+
</Reference>
69+
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
70+
<Private>False</Private>
71+
</Reference>
72+
</ItemGroup>
73+
</When>
74+
</Choose>
75+
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
76+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
78+
Other similar extension points exist, see Microsoft.Common.targets.
79+
<Target Name="BeforeBuild">
80+
</Target>
81+
<Target Name="AfterBuild">
82+
</Target>
83+
-->
84+
</Project>

jQueryCodeSnippets.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2012
44
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jQueryCodeSnippets", "jQueryCodeSnippets\jQueryCodeSnippets.csproj", "{C1131DC7-264F-467E-90E2-ED2ED49BE43F}"
55
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{90164978-E461-4BD8-8F21-15B199E7AFB1}"
7+
EndProject
68
Global
79
GlobalSection(SolutionConfigurationPlatforms) = preSolution
810
Debug|Any CPU = Debug|Any CPU
@@ -13,6 +15,10 @@ Global
1315
{C1131DC7-264F-467E-90E2-ED2ED49BE43F}.Debug|Any CPU.Build.0 = Debug|Any CPU
1416
{C1131DC7-264F-467E-90E2-ED2ED49BE43F}.Release|Any CPU.ActiveCfg = Release|Any CPU
1517
{C1131DC7-264F-467E-90E2-ED2ED49BE43F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{90164978-E461-4BD8-8F21-15B199E7AFB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{90164978-E461-4BD8-8F21-15B199E7AFB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{90164978-E461-4BD8-8F21-15B199E7AFB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{90164978-E461-4BD8-8F21-15B199E7AFB1}.Release|Any CPU.Build.0 = Release|Any CPU
1622
EndGlobalSection
1723
GlobalSection(SolutionProperties) = preSolution
1824
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)