Created
June 12, 2012 22:53
-
-
Save jamesrcounts/2920631 to your computer and use it in GitHub Desktop.
A patch that updates ScrubPath to handle when the "text" parameter is null.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I expected scrub path to handle null input. There is no reason to let the | |
// NullReferenceException to propogate, since Verify can handle nulls. | |
// This test will pass or fail based on the contents of approved.txt | |
[TestMethod] | |
public void MyTestMethod() | |
{ | |
string file = null; | |
ApprovalTests.Approvals.Verify(file); | |
} | |
// This test always fails with a NullReferenceException. | |
[TestMethod] | |
public void MyTestMethod1() | |
{ | |
var dir = PathUtilities.GetDirectoryForCaller(); | |
string file = null; | |
ApprovalTests.Approvals.Verify(file.ScrubPath(dir)); | |
} | |
// This test will pass or fail based on the contents of approved.txt | |
[TestMethod] | |
public void MyTestMethod3() | |
{ | |
var dir = PathUtilities.GetDirectoryForCaller(); | |
string file = string.Empty; | |
ApprovalTests.Approvals.Verify(file.ScrubPath(dir)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: ApprovalUtilities.Tests/Utilities/PathUtilitiesTest.cs | |
=================================================================== | |
--- ApprovalUtilities.Tests/Utilities/PathUtilitiesTest.cs (revision 411) | |
+++ ApprovalUtilities.Tests/Utilities/PathUtilitiesTest.cs (working copy) | |
@@ -17,5 +17,13 @@ | |
var file = dir + "PathUtilitiesTest.cs"; | |
Assert.AreEqual(@"...\PathUtilitiesTest.cs", PathUtilities.ScrubPath(file, dir)); | |
} | |
+ | |
+ [TestMethod] | |
+ public void ReturnNullForNullTest() | |
+ { | |
+ var dir = PathUtilities.GetDirectoryForCaller(); | |
+ string file = null; | |
+ Assert.IsNull(file.ScrubPath(dir)); | |
+ } | |
} | |
} | |
Index: ApprovalUtilities/Utilities/PathUtilities.cs | |
=================================================================== | |
--- ApprovalUtilities/Utilities/PathUtilities.cs (revision 411) | |
+++ ApprovalUtilities/Utilities/PathUtilities.cs (working copy) | |
@@ -23,6 +23,11 @@ | |
public static string ScrubPath(this string text, string path) | |
{ | |
+ if (text == null) | |
+ { | |
+ return null; | |
+ } | |
+ | |
return text.Replace(path, @"...\"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment