@@ -8,13 +8,17 @@ namespace Tests
8
8
[ TestClass ]
9
9
public class SnippetTests
10
10
{
11
+ // --- CONFIGURATION ---
11
12
// update path to local project directory
12
- private string path = @"C:\Projects\Visual-Studio-jQuery-Code-Snippets\jQueryCodeSnippets" ;
13
+ private string m_path = @"C:\Projects\Visual-Studio-jQuery-Code-Snippets\jQueryCodeSnippets" ;
14
+ private string m_helpUrl = "https://github.com/kspearrin/Visual-Studio-jQuery-Code-Snippets" ;
15
+ private string m_version = "1.4.0" ;
16
+ // --- END CONFIGURATION ---
13
17
14
18
[ TestMethod ]
15
19
public void SnippetTitlesAreCorrect ( )
16
20
{
17
- foreach ( var snippetFile in Directory . EnumerateFiles ( path , "*.snippet" , SearchOption . AllDirectories ) )
21
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
18
22
{
19
23
var filePaths = snippetFile . Split ( new string [ ] { "\\ " } , StringSplitOptions . None ) ;
20
24
var fileName = filePaths [ filePaths . Length - 1 ] ;
@@ -25,15 +29,14 @@ public void SnippetTitlesAreCorrect()
25
29
26
30
var titleNode = snippetDoc . GetElementsByTagName ( "Title" ) ;
27
31
var title = titleNode [ 0 ] . InnerText ;
28
-
29
32
Assert . IsTrue ( snippetName == title ) ;
30
33
}
31
34
}
32
35
33
36
[ TestMethod ]
34
37
public void SnippetShortcutsAreCorrect ( )
35
38
{
36
- foreach ( var snippetFile in Directory . EnumerateFiles ( path , "*.snippet" , SearchOption . AllDirectories ) )
39
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
37
40
{
38
41
var filePaths = snippetFile . Split ( new string [ ] { "\\ " } , StringSplitOptions . None ) ;
39
42
var fileName = filePaths [ filePaths . Length - 1 ] ;
@@ -44,44 +47,39 @@ public void SnippetShortcutsAreCorrect()
44
47
45
48
var shortcutNode = snippetDoc . GetElementsByTagName ( "Shortcut" ) ;
46
49
var shortcut = shortcutNode [ 0 ] . InnerText ;
47
-
48
50
Assert . IsTrue ( snippetName == shortcut ) ;
49
51
}
50
52
}
51
53
52
54
[ TestMethod ]
53
55
public void SnippetsHaveDescriptions ( )
54
56
{
55
- foreach ( var snippetFile in Directory . EnumerateFiles ( path , "*.snippet" , SearchOption . AllDirectories ) )
57
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
56
58
{
57
59
var snippetDoc = new XmlDocument ( ) ;
58
60
snippetDoc . Load ( snippetFile ) ;
59
61
60
62
var descriptionNode = snippetDoc . GetElementsByTagName ( "Description" ) ;
61
-
62
- Assert . IsTrue ( descriptionNode != null && descriptionNode [ 0 ] . InnerText != null ) ;
63
+ Assert . IsTrue ( descriptionNode != null ) ;
63
64
64
65
var description = descriptionNode [ 0 ] . InnerText ;
65
-
66
- Assert . IsTrue ( description != string . Empty && description . Length > 10 ) ;
66
+ Assert . IsTrue ( ! string . IsNullOrWhiteSpace ( description ) && description . Length > 10 ) ;
67
67
}
68
68
}
69
69
70
70
[ TestMethod ]
71
71
public void SnippetsHaveAuthors ( )
72
72
{
73
- foreach ( var snippetFile in Directory . EnumerateFiles ( path , "*.snippet" , SearchOption . AllDirectories ) )
73
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
74
74
{
75
75
var snippetDoc = new XmlDocument ( ) ;
76
76
snippetDoc . Load ( snippetFile ) ;
77
77
78
78
var authorNode = snippetDoc . GetElementsByTagName ( "Author" ) ;
79
-
80
- Assert . IsTrue ( authorNode != null && authorNode [ 0 ] . InnerText != null ) ;
79
+ Assert . IsTrue ( authorNode != null ) ;
81
80
82
81
var author = authorNode [ 0 ] . InnerText ;
83
-
84
- Assert . IsTrue ( author != string . Empty && author . Length > 5 ) ;
82
+ Assert . IsTrue ( ! string . IsNullOrWhiteSpace ( author ) && author . Length > 5 ) ;
85
83
}
86
84
}
87
85
@@ -90,30 +88,46 @@ public void SnippetsHaveHelpUrls()
90
88
{
91
89
var helpUrl = "https://github.com/kspearrin/Visual-Studio-jQuery-Code-Snippets" ;
92
90
93
- foreach ( var snippetFile in Directory . EnumerateFiles ( path , "*.snippet" , SearchOption . AllDirectories ) )
91
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
94
92
{
95
93
var snippetDoc = new XmlDocument ( ) ;
96
94
snippetDoc . Load ( snippetFile ) ;
97
95
98
96
var urlNode = snippetDoc . GetElementsByTagName ( "HelpUrl" ) ;
99
-
100
- Assert . IsTrue ( urlNode != null && urlNode [ 0 ] . InnerText != null ) ;
97
+ Assert . IsTrue ( urlNode != null ) ;
101
98
102
99
var url = urlNode [ 0 ] . InnerText ;
103
-
104
- Assert . IsTrue ( url != string . Empty && url == helpUrl ) ;
100
+ Assert . IsTrue ( ! string . IsNullOrWhiteSpace ( url ) && url == helpUrl ) ;
105
101
}
106
102
}
107
103
108
104
[ TestMethod ]
109
105
public void SnippetsAreProperFormattedXml ( )
110
106
{
111
- foreach ( var snippetFile in Directory . EnumerateFiles ( path , "*.snippet" , SearchOption . AllDirectories ) )
107
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
112
108
{
113
109
var contents = File . ReadAllText ( snippetFile ) ;
114
-
115
110
Assert . IsTrue ( contents . Contains ( "<?xml version=\" 1.0\" encoding=\" utf-8\" ?>" ) ) ;
116
111
}
117
112
}
113
+
114
+ [ TestMethod ]
115
+ public void SnippetsHaveCorrectVersion ( )
116
+ {
117
+ foreach ( var snippetFile in Directory . EnumerateFiles ( m_path , "*.snippet" , SearchOption . AllDirectories ) )
118
+ {
119
+ var snippetDoc = new XmlDocument ( ) ;
120
+ snippetDoc . Load ( snippetFile ) ;
121
+
122
+ var snippetNode = snippetDoc . GetElementsByTagName ( "CodeSnippet" ) ;
123
+ Assert . IsTrue ( snippetNode != null ) ;
124
+
125
+ var formatAttr = snippetNode [ 0 ] . Attributes [ "Format" ] ;
126
+ Assert . IsTrue ( formatAttr != null ) ;
127
+
128
+ var format = formatAttr . InnerText ;
129
+ Assert . IsTrue ( ! string . IsNullOrWhiteSpace ( format ) && format == m_version ) ;
130
+ }
131
+ }
118
132
}
119
133
}
0 commit comments