Posted by andrewmyhre on April 5, 2008
I discovered the difference between System.Web.HttpUtility.UrlEncode() and System.Web.HttpUtility.UrlPathEncode:
System.Web.HttpUtility.UrlEncode(“http://something.com/some page.html”) == “http://something.com/some+page.html”
Whereas
System.Web.HttpUtility.UrlPathEncode(“http://something.com/some page.html” == “http://something.com/some%20page.html”);
the System.Web.Uri class automatically uses UrlPathEncode() when constructed from a string value, so when comparing a string Url to a Uri instance, make sure to run the string through UrlPathEncode before the comparison, and NOT UrlEncode().
Posted in Uncategorized | Leave a Comment »
Posted by andrewmyhre on April 5, 2008
I ran into this issue today where asserting equality on two arrays always fails, even if the arrays really are equal:
Assert.Equals(new string[] {“value”}, new string[] {“value”}); // always fails
Evidently for arrays the Assert.Equals() method tests object identity, rather object equality, which is what you would expect. There is an Assert.AreSame() method which should test object identity, shouldn’t it?
I found this post from 2005 which notes the problem – I can’t believe they haven’t fixed it by now!
Posted in testing | Tagged: mstest, testing | 1 Comment »