public static void Register_NegativePort() { TestUriParser parser = new TestUriParser(); Assert.Throws <ArgumentOutOfRangeException>(() => UriParser.Register(parser, Prefix + "negative.port", -2)); }
public static void IsWellFormedOriginalString_Null() { TestUriParser parser = new TestUriParser(); Assert.Throws <System.NullReferenceException>(() => { parser.IsWellFormedOriginalString(null); }); }
public static void GetComponents_Null() { TestUriParser parser = new TestUriParser(); Assert.Throws <NullReferenceException>(() => parser.GetComponents(null, UriComponents.Host, UriFormat.SafeUnescaped)); }
public static void Register_UInt16PortMinus1() { prefix = "unit.test."; TestUriParser parser = new TestUriParser(); UriParser.Register(parser, prefix + "uint16.minus.1.port", UInt16.MaxValue - 1); }
public static void ReRegister() { prefix = "unit.test."; string scheme = prefix + "re.register.mono"; Assert.False(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false"); TestUriParser parser = new TestUriParser(); UriParser.Register(parser, scheme, 2005); Assert.True(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true"); Assert.Throws<System.InvalidOperationException>(() => { UriParser.Register(parser, scheme, 2006); }); }
public static void Register() { prefix = "unit.test."; string scheme = prefix + "register.mono"; Assert.False(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false"); TestUriParser parser = new TestUriParser(); UriParser.Register(parser, scheme, 2005); Assert.Equal(scheme, parser.SchemeName); Assert.Equal(2005, parser.DefaultPort); Assert.True(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true"); }
public static void Register_NegativePort() { prefix = "unit.test."; TestUriParser parser = new TestUriParser(); Assert.Throws<System.ArgumentOutOfRangeException>(() => { UriParser.Register(parser, prefix + "negative.port", -2); }); }
public static void GetComponents_BadUriComponents() { TestUriParser parser = new TestUriParser(); Assert.Equal(full_http, parser.GetComponents(http, (UriComponents)Int32.MinValue, UriFormat.SafeUnescaped)); }
public static void GetComponents_BadUriFormat() { http = new Uri(full_http); TestUriParser parser = new TestUriParser(); Assert.Throws<System.ArgumentOutOfRangeException>(() => { parser.GetComponents(http, UriComponents.Host, (UriFormat)Int32.MinValue); }); }
public static void GetComponents_Ftp2() { var full_ftp = "ftp://%75sername%3a%[email protected]:21/with some spaces/mono.tgz"; ftp2 = new Uri(full_ftp); TestUriParser parser = new TestUriParser(); Assert.Equal("ftp", parser.GetComponents(ftp2, UriComponents.Scheme, UriFormat.Unescaped)); Assert.Equal("username:password", parser.GetComponents(ftp2, UriComponents.UserInfo, UriFormat.Unescaped)); Assert.Equal("ftp.go-mono.com", parser.GetComponents(ftp2, UriComponents.Host, UriFormat.Unescaped)); Assert.Equal(String.Empty, parser.GetComponents(ftp2, UriComponents.Port, UriFormat.Unescaped)); Assert.Equal("with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.Path, UriFormat.Unescaped)); Assert.Equal("with%20some%20spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.Path, UriFormat.UriEscaped)); Assert.Equal("with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.Path, UriFormat.SafeUnescaped)); Assert.Equal(String.Empty, parser.GetComponents(ftp2, UriComponents.Query, UriFormat.Unescaped)); Assert.Equal(String.Empty, parser.GetComponents(ftp2, UriComponents.Fragment, UriFormat.Unescaped)); Assert.Equal("21", parser.GetComponents(ftp2, UriComponents.StrongPort, UriFormat.Unescaped)); Assert.Equal(String.Empty, parser.GetComponents(ftp2, UriComponents.KeepDelimiter, UriFormat.Unescaped)); Assert.Equal("ftp.go-mono.com:21", parser.GetComponents(ftp2, UriComponents.HostAndPort, UriFormat.Unescaped)); Assert.Equal("username:[email protected]:21", parser.GetComponents(ftp2, UriComponents.StrongAuthority, UriFormat.Unescaped)); Assert.Equal("ftp://*****:*****@ftp.go-mono.com/with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.AbsoluteUri, UriFormat.Unescaped)); Assert.Equal("/with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.PathAndQuery, UriFormat.Unescaped)); Assert.Equal("ftp://ftp.go-mono.com/with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.HttpRequestUrl, UriFormat.Unescaped)); Assert.Equal("ftp://ftp.go-mono.com", parser.GetComponents(ftp2, UriComponents.SchemeAndServer, UriFormat.Unescaped)); Assert.Equal("ftp://*****:*****@ftp.go-mono.com/with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.SerializationInfoString, UriFormat.Unescaped)); Assert.Equal(parser, parser.OnNewUri()); // strange mixup Assert.Equal("ftp://*****:*****@", parser.GetComponents(ftp2, UriComponents.Scheme | UriComponents.UserInfo, UriFormat.Unescaped)); Assert.Equal(":21/with some spaces/mono.tgz", parser.GetComponents(ftp2, UriComponents.Path | UriComponents.StrongPort, UriFormat.Unescaped)); }
public static void GetComponents_Null() { TestUriParser parser = new TestUriParser(); Assert.Throws<System.NullReferenceException>(() => { parser.GetComponents(null, UriComponents.Host, UriFormat.SafeUnescaped); }); }
public static void Register_TooBigPort() { TestUriParser parser = new TestUriParser(); Assert.Throws <ArgumentOutOfRangeException>(() => UriParser.Register(parser, Prefix + "too.big.port", ushort.MaxValue)); }
public static void Register_UInt16PortMinus1() { TestUriParser parser = new TestUriParser(); UriParser.Register(parser, Prefix + "uint16.minus.1.port", ushort.MaxValue - 1); }
public static void Register_Minus1Port() { TestUriParser parser = new TestUriParser(); UriParser.Register(parser, Prefix + "minus1.port", -1); }
public static void Resolve_UriNull() { http = new Uri(full_http); UriFormatException error = null; TestUriParser parser = new TestUriParser(); Assert.Equal(full_http, parser.Resolve(http, null, out error)); }
public static void InitializeAndValidate() { http = new Uri(full_http); UriFormatException error = null; TestUriParser parser = new TestUriParser(); parser.InitializeAndValidate(http, out error); Assert.NotNull(error); }
public static void Resolve_NullUri() { http = new Uri(full_http); UriFormatException error = null; TestUriParser parser = new TestUriParser(); Assert.Throws<System.NullReferenceException>(() => { parser.Resolve(null, http, out error); } ); parser.Resolve(http, null, out error); }
public static void InitializeAndValidate_Null() { UriFormatException error = null; TestUriParser parser = new TestUriParser(); Assert.Throws<System.NullReferenceException>(() => { parser.InitializeAndValidate(null, out error); }); }
public static void Register_NullScheme() { TestUriParser parser = new TestUriParser(); Assert.Throws<System.ArgumentNullException>(() => { UriParser.Register(parser, null, 2006); }); }
public static void IsBaseOf() { http = new Uri(full_http); TestUriParser parser = new TestUriParser(); Assert.True(parser.IsBaseOf(http, http), "http-http"); Uri u = new Uri("http://www.mono-project.com/Main_Page#FAQ"); Assert.True(parser.IsBaseOf(u, http), "http-1a"); Assert.True(parser.IsBaseOf(http, u), "http-1b"); u = new Uri("http://www.mono-project.com/Main_Page"); Assert.True(parser.IsBaseOf(u, http), "http-2a"); Assert.True(parser.IsBaseOf(http, u), "http-2b"); u = new Uri("http://www.mono-project.com/"); Assert.True(parser.IsBaseOf(u, http), "http-3a"); Assert.True(parser.IsBaseOf(http, u), "http-3b"); u = new Uri("http://www.mono-project.com/Main_Page/"); Assert.False(parser.IsBaseOf(u, http), "http-4a"); Assert.True(parser.IsBaseOf(http, u), "http-4b"); // docs says the UserInfo isn't evaluated, but... u = new Uri("http://*****:*****@www.mono-project.com/Main_Page"); Assert.False(parser.IsBaseOf(u, http), "http-5a"); Assert.False(parser.IsBaseOf(http, u), "http-5b"); // scheme case sensitive ? no u = new Uri("HTTP://www.mono-project.com/Main_Page"); Assert.True(parser.IsBaseOf(u, http), "http-6a"); Assert.True(parser.IsBaseOf(http, u), "http-6b"); // host case sensitive ? no u = new Uri("http://www.Mono-Project.com/Main_Page"); Assert.True(parser.IsBaseOf(u, http), "http-7a"); Assert.True(parser.IsBaseOf(http, u), "http-7b"); // path case sensitive ? no u = new Uri("http://www.Mono-Project.com/MAIN_Page"); Assert.True(parser.IsBaseOf(u, http), "http-8a"); Assert.True(parser.IsBaseOf(http, u), "http-8b"); // different scheme u = new Uri("ftp://www.mono-project.com/Main_Page"); Assert.False(parser.IsBaseOf(u, http), "http-9a"); Assert.False(parser.IsBaseOf(http, u), "http-9b"); // different host u = new Uri("http://www.go-mono.com/Main_Page"); Assert.False(parser.IsBaseOf(u, http), "http-10a"); Assert.False(parser.IsBaseOf(http, u), "http-10b"); // different port u = new Uri("http://www.mono-project.com:8080/"); Assert.False(parser.IsBaseOf(u, http), "http-11a"); Assert.False(parser.IsBaseOf(http, u), "http-11b"); // specify default port u = new Uri("http://www.mono-project.com:80/"); Assert.True(parser.IsBaseOf(u, http), "http-12a"); Assert.True(parser.IsBaseOf(http, u), "http-12b"); }
public static void Register_Minus1Port() { prefix = "unit.test."; TestUriParser parser = new TestUriParser(); UriParser.Register(parser, prefix + "minus1.port", -1); }
public static void IsWellFormedOriginalString() { http = new Uri(full_http); TestUriParser parser = new TestUriParser(); Assert.True(parser.IsWellFormedOriginalString(http), "http"); }
public static void Register_TooBigPort() { prefix = "unit.test."; TestUriParser parser = new TestUriParser(); Assert.Throws<System.ArgumentOutOfRangeException>(() => { UriParser.Register(parser, prefix + "too.big.port", UInt16.MaxValue); }); }
public static void IsWellFormedOriginalString_Null() { TestUriParser parser = new TestUriParser(); Assert.Throws<System.NullReferenceException>(() => { parser.IsWellFormedOriginalString(null); } ); }
public static void GetComponents_test() { http = new Uri(full_http); TestUriParser parser = new TestUriParser(); Assert.Equal("http", parser.GetComponents(http, UriComponents.Scheme, UriFormat.SafeUnescaped)); Assert.Equal(String.Empty, parser.GetComponents(http, UriComponents.UserInfo, UriFormat.SafeUnescaped)); Assert.Equal("www.mono-project.com", parser.GetComponents(http, UriComponents.Host, UriFormat.SafeUnescaped)); Assert.Equal(String.Empty, parser.GetComponents(http, UriComponents.Port, UriFormat.SafeUnescaped)); Assert.Equal("Main_Page", parser.GetComponents(http, UriComponents.Path, UriFormat.SafeUnescaped)); Assert.Equal(String.Empty, parser.GetComponents(http, UriComponents.Query, UriFormat.SafeUnescaped)); Assert.Equal("FAQ?Edit", parser.GetComponents(http, UriComponents.Fragment, UriFormat.SafeUnescaped)); Assert.Equal("80", parser.GetComponents(http, UriComponents.StrongPort, UriFormat.SafeUnescaped)); Assert.Equal(String.Empty, parser.GetComponents(http, UriComponents.KeepDelimiter, UriFormat.SafeUnescaped)); Assert.Equal("www.mono-project.com:80", parser.GetComponents(http, UriComponents.HostAndPort, UriFormat.SafeUnescaped)); Assert.Equal("www.mono-project.com:80", parser.GetComponents(http, UriComponents.StrongAuthority, UriFormat.SafeUnescaped)); Assert.Equal(full_http, parser.GetComponents(http, UriComponents.AbsoluteUri, UriFormat.SafeUnescaped)); Assert.Equal("/Main_Page", parser.GetComponents(http, UriComponents.PathAndQuery, UriFormat.SafeUnescaped)); Assert.Equal("http://www.mono-project.com/Main_Page", parser.GetComponents(http, UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped)); Assert.Equal("http://www.mono-project.com", parser.GetComponents(http, UriComponents.SchemeAndServer, UriFormat.SafeUnescaped)); Assert.Equal(full_http, parser.GetComponents(http, UriComponents.SerializationInfoString, UriFormat.SafeUnescaped)); // strange mixup Assert.Equal("http://", parser.GetComponents(http, UriComponents.Scheme | UriComponents.Port, UriFormat.SafeUnescaped)); Assert.Equal("www.mono-project.com#FAQ?Edit", parser.GetComponents(http, UriComponents.Host | UriComponents.Fragment, UriFormat.SafeUnescaped)); Assert.Equal("/Main_Page", parser.GetComponents(http, UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped)); Assert.Equal(parser, parser.OnNewUri()); }
public static void OnRegister() { prefix = "unit.test."; string scheme = prefix + "onregister"; Assert.False(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false"); TestUriParser parser = new TestUriParser(); try { UriParser.Register(parser, scheme, 2005); } catch (NotSupportedException) { // special case / ordering } // if true then the registration is done before calling OnRegister Assert.True(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true"); }
public static void Register_NullScheme() { TestUriParser parser = new TestUriParser(); Assert.Throws <System.ArgumentNullException>(() => { UriParser.Register(parser, null, 2006); }); }
public static void OnRegister2() { prefix = "unit.test."; string scheme = prefix + "onregister2"; Assert.False(UriParser.IsKnownScheme(scheme), "IsKnownScheme-false"); TestUriParser parser = new TestUriParser(); try { UriParser.Register(parser, scheme, 2005); Uri uri = new Uri(scheme + "://foobar:2005"); Assert.Equal(scheme, uri.Scheme); Assert.Equal(2005, uri.Port); Assert.Equal("//foobar:2005", uri.LocalPath); } catch (NotSupportedException) { // special case / ordering } // if true then the registration is done before calling OnRegister Assert.True(UriParser.IsKnownScheme(scheme), "IsKnownScheme-true"); }
public static void IsBaseOf() { Uri http = new Uri(FullHttpUri); TestUriParser parser = new TestUriParser(); Assert.True(parser.IsBaseOf(http, http), "http-http"); Uri u = new Uri("http://www.mono-project.com/Main_Page#FAQ"); Assert.True(parser.IsBaseOf(u, http), "http-1a"); Assert.True(parser.IsBaseOf(http, u), "http-1b"); u = new Uri("http://www.mono-project.com/Main_Page"); Assert.True(parser.IsBaseOf(u, http), "http-2a"); Assert.True(parser.IsBaseOf(http, u), "http-2b"); u = new Uri("http://www.mono-project.com/"); Assert.True(parser.IsBaseOf(u, http), "http-3a"); Assert.True(parser.IsBaseOf(http, u), "http-3b"); u = new Uri("http://www.mono-project.com/Main_Page/"); Assert.False(parser.IsBaseOf(u, http), "http-4a"); Assert.True(parser.IsBaseOf(http, u), "http-4b"); // docs says the UserInfo isn't evaluated, but... u = new Uri("http://*****:*****@www.mono-project.com/Main_Page"); Assert.False(parser.IsBaseOf(u, http), "http-5a"); Assert.False(parser.IsBaseOf(http, u), "http-5b"); // scheme case sensitive ? no u = new Uri("HTTP://www.mono-project.com/Main_Page"); Assert.True(parser.IsBaseOf(u, http), "http-6a"); Assert.True(parser.IsBaseOf(http, u), "http-6b"); // host case sensitive ? no u = new Uri("http://www.Mono-Project.com/Main_Page"); Assert.True(parser.IsBaseOf(u, http), "http-7a"); Assert.True(parser.IsBaseOf(http, u), "http-7b"); // path case sensitive ? no u = new Uri("http://www.Mono-Project.com/MAIN_Page"); Assert.True(parser.IsBaseOf(u, http), "http-8a"); Assert.True(parser.IsBaseOf(http, u), "http-8b"); // different scheme u = new Uri("ftp://www.mono-project.com/Main_Page"); Assert.False(parser.IsBaseOf(u, http), "http-9a"); Assert.False(parser.IsBaseOf(http, u), "http-9b"); // different host u = new Uri("http://www.go-mono.com/Main_Page"); Assert.False(parser.IsBaseOf(u, http), "http-10a"); Assert.False(parser.IsBaseOf(http, u), "http-10b"); // different port u = new Uri("http://www.mono-project.com:8080/"); Assert.False(parser.IsBaseOf(u, http), "http-11a"); Assert.False(parser.IsBaseOf(http, u), "http-11b"); // specify default port u = new Uri("http://www.mono-project.com:80/"); Assert.True(parser.IsBaseOf(u, http), "http-12a"); Assert.True(parser.IsBaseOf(http, u), "http-12b"); }
public static void InitializeAndValidate_Null() { TestUriParser parser = new TestUriParser(); Assert.Throws <NullReferenceException>(() => parser.InitializeAndValidate(null, out _)); }