namespace MonoTests.System\r
{\r
[TestFixture]\r
- public class UriBuilderTest \r
+ public class UriBuilderTest : Assertion\r
{\r
private UriBuilder b, b2, b3;\r
\r
[SetUp]\r
public void GetReady()\r
{\r
- b = new UriBuilder ("http://", "www.ximian.com", 80, "foo/bar/index.html");\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html");\r
}\r
\r
[Test]\r
public void Constructors ()\r
{\r
b = new UriBuilder ();\r
- Assertion.AssertEquals ("#1", "http", b.Scheme);\r
- Assertion.AssertEquals ("#2", "loopback", b.Host);\r
- Assertion.AssertEquals ("#3", -1, b.Port);\r
+ AssertEquals ("#1", "http", b.Scheme);\r
+ AssertEquals ("#2", "loopback", b.Host);\r
+ AssertEquals ("#3", -1, b.Port);\r
\r
try {\r
- b = new UriBuilder ("http://", "www.ximian.com", 80, "foo/bar/index.html", "extras");\r
- Assertion.Fail ("#4 should have thrown an ArgumentException because extraValue must start with '?' or '#' character.");\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html", "extras");\r
+ Fail ("#4 should have thrown an ArgumentException because extraValue must start with '?' or '#' character.");\r
} catch (ArgumentException) {}\r
\r
- b = new UriBuilder ("http://", "www.ximian.com", 80, "foo/bar/index.html", "#extras");\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "foo/bar/index.html", "#extras");\r
}\r
\r
[Test]\r
public void UserInfo ()\r
{ \r
b = new UriBuilder ("mailto://myname:mypwd@contoso.com?subject=hello");\r
- Assertion.AssertEquals ("#1", "myname", b.UserName);\r
- Assertion.AssertEquals ("#2", "mypwd", b.Password);\r
+ AssertEquals ("#1", "myname", b.UserName);\r
+ AssertEquals ("#2", "mypwd", b.Password);\r
\r
- b = new UriBuilder ("mailto:", "contoso.com");\r
+ b = new UriBuilder ("mailto", "contoso.com");\r
b.UserName = "myname";\r
b.Password = "mypwd";\r
- Assertion.AssertEquals ("#3: known to fail with ms.net.", "myname:mypwd", b.Uri.UserInfo);\r
+ AssertEquals ("#3", "myname:mypwd", b.Uri.UserInfo);\r
}\r
\r
[Test]\r
public void Path ()\r
{ \r
b.Path = ((char) 0xa9) + " 2002";\r
- Assertion.AssertEquals ("#1: known to fail with ms.net, should at least return a slash.", "/%A9%202002", b.Path); \r
+ AssertEquals ("#1", "%C2%A9%202002", b.Path); \r
} \r
\r
[Test]\r
- public void Port ()\r
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
+ public void BadPort1 ()\r
{\r
- try {\r
- b.Port = -12345;\r
- Assertion.Fail ("#1 should've failed, illegal port.");\r
- } catch (ArgumentOutOfRangeException) {}\r
- try {\r
- b.Port = 123456789;\r
- Assertion.Fail ("#2 should've failed, illegal port.");\r
- } catch (ArgumentOutOfRangeException) {}\r
- try {\r
- b.Port = -1;\r
- Assertion.AssertEquals ("#3", -1, b.Port);\r
- } catch (ArgumentOutOfRangeException) {\r
- Assertion.Fail ("#4: spec should allow -1 as value.");\r
- }\r
+ b.Port = -12345;\r
}\r
- \r
+\r
+ [Test]\r
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
+ public void BadPort3 ()\r
+ {\r
+ b.Port = -1;\r
+ }\r
+\r
[Test]\r
public void Query ()\r
{\r
b.Query = ((char) 0xa9) + " 2002";\r
- Assertion.AssertEquals ("#1: known to fail with ms.net, should've been escaped.", "?%A9%202002", b.Query); \r
- Assertion.AssertEquals ("#2", String.Empty, b.Fragment);\r
+ AssertEquals ("#1", "?\xA9 2002", b.Query); \r
+ AssertEquals ("#2", String.Empty, b.Fragment);\r
b.Query = "?test";\r
- Assertion.AssertEquals ("#3", "??test", b.Query);\r
+ AssertEquals ("#3", "??test", b.Query);\r
b.Query = null;\r
- Assertion.AssertEquals ("#4", String.Empty, b.Query);\r
+ AssertEquals ("#4", String.Empty, b.Query);\r
}\r
\r
[Test]\r
public void Fragment ()\r
{\r
b.Fragment = ((char) 0xa9) + " 2002";\r
- Assertion.AssertEquals ("#1: known to fail with ms.net, should've been escaped.", "#%A9%202002", b.Fragment);\r
- Assertion.AssertEquals ("#2", String.Empty, b.Query);\r
+ AssertEquals ("#1", "#\xA9 2002", b.Fragment);\r
+ AssertEquals ("#2", String.Empty, b.Query);\r
b.Fragment = "#test";\r
- Assertion.AssertEquals ("#3", "##test", b.Fragment);\r
+ AssertEquals ("#3", "##test", b.Fragment);\r
b.Fragment = null;\r
- Assertion.AssertEquals ("#4", String.Empty, b.Fragment);\r
+ AssertEquals ("#4", String.Empty, b.Fragment);\r
}\r
\r
[Test]\r
public void Scheme ()\r
{\r
b.Scheme = "http";\r
- Assertion.AssertEquals ("#1", b.Scheme, "http");\r
+ AssertEquals ("#1", b.Scheme, "http");\r
b.Scheme = "http:";\r
- Assertion.AssertEquals ("#2", b.Scheme, "http");\r
+ AssertEquals ("#2", b.Scheme, "http");\r
b.Scheme = "http://";\r
- Assertion.AssertEquals ("#3", b.Scheme, "http");\r
+ AssertEquals ("#3", b.Scheme, "http");\r
b.Scheme = "http://foo/bar";\r
- Assertion.AssertEquals ("#4", b.Scheme, "http");\r
+ AssertEquals ("#4", b.Scheme, "http");\r
b.Scheme = "mailto:";\r
- Assertion.AssertEquals ("#5", b.Scheme, "mailto");\r
+ AssertEquals ("#5", b.Scheme, "mailto");\r
b.Scheme = "unknown";\r
- Assertion.AssertEquals ("#6", b.Scheme, "unknown");\r
+ AssertEquals ("#6", b.Scheme, "unknown");\r
b.Scheme = "unknown://";\r
- Assertion.AssertEquals ("#7", b.Scheme, "unknown");\r
+ AssertEquals ("#7", b.Scheme, "unknown");\r
}\r
\r
[Test]\r
b2 = new UriBuilder ("http", "www.ximian.com", 80, "/foo/bar/index.html", "?item=1");\r
b3 = new UriBuilder (new Uri ("http://www.ximian.com/foo/bar/index.html?item=1"));\r
\r
- Assertion.Assert ("#1", b.Equals (b2));\r
- Assertion.Assert ("#2", b.Uri.Equals (b2.Uri));\r
- Assertion.Assert ("#3", b.Equals (b3));\r
- Assertion.Assert ("#4", b2.Equals (b3));\r
- Assertion.Assert ("#5", b3.Equals (b));\r
+ Assert ("#1", b.Equals (b2));\r
+ Assert ("#2", b.Uri.Equals (b2.Uri));\r
+ Assert ("#3", b.Equals (b3));\r
+ Assert ("#4", b2.Equals (b3));\r
+ Assert ("#5", b3.Equals (b));\r
}\r
\r
[Test]\r
public void ToStringTest ()\r
{\r
- Assertion.AssertEquals ("#1 known to fail with ms.net, should've been canonicalized.", b.Uri.ToString (), b.ToString ());\r
+ AssertEquals ("ToString ()", "http://www.ximian.com:80/foo/bar/index.html", b.ToString ());\r
+ AssertEquals ("Uri.ToString ()", "http://www.ximian.com/foo/bar/index.html", b.Uri.ToString ());\r
+ }\r
+\r
+ [Test]\r
+ public void EmptyQuery () // bug 57082\r
+ {\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", null);\r
+ string noquery = "http://www.ximian.com/lalala/lelele.aspx";\r
+ AssertEquals ("#01", b.Uri.ToString (), noquery);\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "?");\r
+ AssertEquals ("#02", b.Uri.ToString (), noquery);\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "??");\r
+ AssertEquals ("#03", b.Uri.ToString (), noquery + "??");\r
+ b = new UriBuilder ("http", "www.ximian.com", 80, "/lalala/lelele.aspx", "?something");\r
+ AssertEquals ("#04", b.Uri.ToString (), noquery + "?something");\r
}\r
}\r
}\r