@@ -6,7 +6,7 @@ namespace HowToValidateGuidTests
66 [ TestClass ]
77 public class GuidHelperTests
88 {
9- private IFixture _fixture ;
9+ private IFixture _fixture = new Fixture ( ) ;
1010 private const string formatKey = "D" ;
1111
1212 [ TestInitialize ]
@@ -41,6 +41,14 @@ public void WhenValidateWithRegexCalled_ForAEmptyString_ThenResultMustBeFalse()
4141 Validate ( input , GuidHelper . ValidateWithRegex , false ) ;
4242 }
4343
44+ [ TestMethod ]
45+ public void WhenValidateWithRegexCalled_ForANullString_ThenResultMustBeFalse ( )
46+ {
47+ string ? input = null ;
48+
49+ Validate ( input , GuidHelper . ValidateWithRegex , false ) ;
50+ }
51+
4452 #endregion
4553
4654 #region ValidateWithGuidParse
@@ -69,6 +77,14 @@ public void WhenValidateWithGuidParseCalled_ForAEmptyString_ThenResultMustBeFals
6977 Validate ( input , GuidHelper . ValidateWithGuidParse , false ) ;
7078 }
7179
80+ [ TestMethod ]
81+ public void WhenValidateWithGuidParseCalled_ForANullString_ThenResultMustBeFalse ( )
82+ {
83+ string ? input = null ;
84+
85+ Validate ( input , GuidHelper . ValidateWithGuidParse , false ) ;
86+ }
87+
7288 #endregion
7389
7490 #region ValidateWithGuidParseExact
@@ -97,6 +113,22 @@ public void WhenValidateWithGuidParseExactCalled_ForAEmptyString_ThenResultMustB
97113 ValidateFormat ( input , formatKey , GuidHelper . ValidateWithGuidParseExact , false ) ;
98114 }
99115
116+ [ TestMethod ]
117+ public void WhenValidateWithGuidParseExactCalled_ForANullString_ThenResultMustBeFalse ( )
118+ {
119+ string ? input = null ;
120+
121+ ValidateFormat ( input , formatKey , GuidHelper . ValidateWithGuidParseExact , false ) ;
122+ }
123+
124+ [ TestMethod ]
125+ public void WhenValidateWithGuidParseExactCalled_ForAGuidStringInXFormat_ThenResultMustBeTrue ( )
126+ {
127+ var input = _fixture . Create < Guid > ( ) . ToString ( "X" ) ;
128+
129+ ValidateFormat ( input , "X" , GuidHelper . ValidateWithGuidParseExact , true ) ;
130+ }
131+
100132 #endregion
101133
102134 #region ValidateWithGuidTryParse
@@ -125,6 +157,14 @@ public void WhenValidateWithGuidTryParseCalled_ForAEmptyString_ThenResultMustBeF
125157 Validate ( input , GuidHelper . ValidateWithGuidTryParse , false ) ;
126158 }
127159
160+ [ TestMethod ]
161+ public void WhenValidateWithGuidTryParseCalled_ForANullString_ThenResultMustBeFalse ( )
162+ {
163+ string ? input = null ;
164+
165+ Validate ( input , GuidHelper . ValidateWithGuidTryParse , false ) ;
166+ }
167+
128168 #endregion
129169
130170 #region ValidateWithGuidTryParseExact
@@ -153,6 +193,22 @@ public void WhenValidateWithGuidTryParseExactCalled_ForAEmptyString_ThenResultMu
153193 ValidateFormat ( input , formatKey , GuidHelper . ValidateWithGuidTryParseExact , false ) ;
154194 }
155195
196+ [ TestMethod ]
197+ public void WhenValidateWithGuidTryParseExactCalled_ForANullString_ThenResultMustBeFalse ( )
198+ {
199+ string ? input = null ;
200+
201+ ValidateFormat ( input , formatKey , GuidHelper . ValidateWithGuidTryParseExact , false ) ;
202+ }
203+
204+ [ TestMethod ]
205+ public void WhenValidateWithGuidTryParseExactCalled_ForAGuidStringInXFormat_ThenResultMustBeTrue ( )
206+ {
207+ var input = _fixture . Create < Guid > ( ) . ToString ( "X" ) ;
208+
209+ ValidateFormat ( input , "X" , GuidHelper . ValidateWithGuidTryParseExact , true ) ;
210+ }
211+
156212 #endregion
157213
158214 #region ValidateWithNewGuid
@@ -181,16 +237,60 @@ public void WhenValidateWithNewGuidCalled_ForAEmptyString_ThenResultMustBeFalse(
181237 Validate ( input , GuidHelper . ValidateWithNewGuid , false ) ;
182238 }
183239
240+ [ TestMethod ]
241+ public void WhenValidateWithNewGuidCalled_ForANullString_ThenResultMustBeFalse ( )
242+ {
243+ string ? input = null ;
244+
245+ Validate ( input , GuidHelper . ValidateWithNewGuid , false ) ;
246+ }
247+
248+ #endregion
249+
250+ #region IsUsableGuid
251+
252+ [ TestMethod ]
253+ public void WhenIsUsableGuidCalled_ForANullString_ThenResultMustBeFalse ( )
254+ {
255+ string ? input = null ;
256+
257+ Validate ( input , GuidHelper . IsUsableGuid , false ) ;
258+ }
259+
260+ [ TestMethod ]
261+ public void WhenIsUsableGuidCalled_ForARandomString_ThenResultMustBeFalse ( )
262+ {
263+ var input = _fixture . Create < string > ( ) + _fixture . Create < string > ( ) ;
264+
265+ Validate ( input , GuidHelper . IsUsableGuid , false ) ;
266+ }
267+
268+ [ TestMethod ]
269+ public void WhenIsUsableGuidCalled_ForAnEmptyGuidString_ThenResultMustBeFalse ( )
270+ {
271+ var input = Guid . Empty . ToString ( ) ;
272+
273+ Validate ( input , GuidHelper . IsUsableGuid , false ) ;
274+ }
275+
276+ [ TestMethod ]
277+ public void WhenIsUsableGuidCalled_ForAGuidString_ThenResultMustBeTrue ( )
278+ {
279+ var input = _fixture . Create < Guid > ( ) . ToString ( ) ;
280+
281+ Validate ( input , GuidHelper . IsUsableGuid , true ) ;
282+ }
283+
184284 #endregion
185285
186- private void Validate ( string input , Func < string , bool > action , bool expected )
286+ private void Validate ( string ? input , Func < string ? , bool > action , bool expected )
187287 {
188288 var result = action ( input ) ;
189289
190290 Assert . AreEqual ( expected , result ) ;
191291 }
192292
193- private void ValidateFormat ( string input , string format , Func < string , string , bool > action , bool expected )
293+ private void ValidateFormat ( string ? input , string format , Func < string ? , string , bool > action , bool expected )
194294 {
195295 var result = action ( input , format ) ;
196296
0 commit comments