public void CompareShouldBeCultureInvariant() { // Get the tr-TR (Turkish-Turkey) culture. var turkish = new CultureInfo("tr-TR"); // Get the culture that is associated with the current thread. var thisCulture = Thread.CurrentThread.CurrentCulture; try { // Set the culture to Turkish Thread.CurrentThread.CurrentCulture = turkish; var comparer = new UriComparer(new Uri("http://watin.sourceforge.net"), true); Assert.IsTrue(comparer.Compare("http://WATIN.sourceforge.net/"), "Same site should match"); } finally { // Set the culture back to the original Thread.CurrentThread.CurrentCulture = thisCulture; } }
public void CompareShouldEqualUriCompare() { var target = new UriComparer(); var url1 = new Uri( "about:blank" ); var url2 = new Uri( "about:Blank" ); var url3 = new Uri( "http://www.tempuri.org" ); Assert.Equal( Uri.Compare( null, null, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( null, null ) ); Assert.Equal( Uri.Compare( url1, null, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( url1, null ) ); Assert.Equal( Uri.Compare( null, url2, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( null, url2 ) ); Assert.Equal( Uri.Compare( url1, url2, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( url1, url2 ) ); Assert.Equal( Uri.Compare( url1, url3, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( url1, url3 ) ); target = new UriComparer( UriComponents.AbsoluteUri, UriFormat.Unescaped, false ); Assert.Equal( Uri.Compare( url1, url2, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.Ordinal ), target.Compare( url1, url2 ) ); Assert.Equal( Uri.Compare( url1, url3, UriComponents.AbsoluteUri, UriFormat.Unescaped, StringComparison.Ordinal ), target.Compare( url1, url3 ) ); target = new UriComparer( UriComponents.Scheme, UriFormat.SafeUnescaped ); Assert.Equal( Uri.Compare( url1, url2, UriComponents.Scheme, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( url1, url2 ) ); Assert.Equal( Uri.Compare( url1, url3, UriComponents.Scheme, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase ), target.Compare( url1, url3 ) ); target = new UriComparer( UriComponents.Scheme, UriFormat.SafeUnescaped, false ); Assert.Equal( Uri.Compare( url1, url2, UriComponents.Scheme, UriFormat.SafeUnescaped, StringComparison.Ordinal ), target.Compare( url1, url2 ) ); Assert.Equal( Uri.Compare( url1, url3, UriComponents.Scheme, UriFormat.SafeUnescaped, StringComparison.Ordinal ), target.Compare( url1, url3 ) ); }