Ejemplo n.º 1
0
        public void BrowserHttp()
        {
            IWebRequestCreate wrc = WebRequestCreator.BrowserHttp;

            Assert.AreEqual(wrc.GetType().ToString(), "System.Net.Browser.BrowserHttpWebRequestCreator", "Type");

            WebRequest wr = wrc.Create(Uri);

            Assert.AreEqual(wr.GetType().ToString(), "System.Net.Browser.BrowserHttpWebRequest", "Type");

            Assert.AreSame(wrc, wr.CreatorInstance, "CreatorInstance");

            // default so we don't register it - since we can do so only one time!
            // Assert.IsTrue (WebRequest.RegisterPrefix ("http://", WebRequestCreator.BrowserHttp), "RegisterPrefix");
        }
Ejemplo n.º 2
0
        public void ClientHttp()
        {
            IWebRequestCreate wrc = WebRequestCreator.ClientHttp;

            Assert.AreEqual(wrc.GetType().ToString(), "System.Net.Browser.ClientHttpWebRequestCreator", "Type");

            WebRequest wr = wrc.Create(Uri);

            Assert.AreEqual(wr.GetType().ToString(), "System.Net.Browser.ClientHttpWebRequest", "Type");
            Assert.AreSame(wrc, wr.CreatorInstance, "CreatorInstance");

            // we use 'https' instead of 'http' to avoid messing with other tests

            // registering 'https:' is not valid
            Assert.IsFalse(WebRequest.RegisterPrefix("https:", WebRequestCreator.ClientHttp), "RegisterPrefix-https:");

            // registering 'https' is not good enough
            Assert.IsTrue(WebRequest.RegisterPrefix("https", WebRequestCreator.ClientHttp), "RegisterPrefix-https");
            wr = WebRequest.Create("https://www.mono-project.com");
            Assert.AreSame(WebRequestCreator.BrowserHttp, wr.CreatorInstance, "WebRequest.Create(string)-https");

            // you need to register 'https:/'
            Assert.IsTrue(WebRequest.RegisterPrefix("https:/", WebRequestCreator.ClientHttp), "RegisterPrefix-https:/");
            wr = WebRequest.Create("https://www.mono-project.com");
            Assert.AreSame(WebRequestCreator.ClientHttp, wr.CreatorInstance, "WebRequest.Create(string)-https");

            // or register 'https://'
            Assert.IsTrue(WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp), "RegisterPrefix-https://");
            wr = WebRequest.Create("https://www.mono-project.com");
            Assert.AreSame(WebRequestCreator.ClientHttp, wr.CreatorInstance, "WebRequest.Create(string)-https://");

            // we cannot register twice (e.g. go back to Browser)
            Assert.IsFalse(WebRequest.RegisterPrefix("https://", WebRequestCreator.BrowserHttp), "RegisterPrefix-https://-2");
            wr = WebRequest.Create(new Uri("https://www.mono-project.com"));
            Assert.AreSame(WebRequestCreator.ClientHttp, wr.CreatorInstance, "WebRequest.Create(Uri)-https://");

            // we cannot register twice (even with the same, Client, value)
            Assert.IsFalse(WebRequest.RegisterPrefix("https://", WebRequestCreator.ClientHttp), "RegisterPrefix-https://-2");
        }
Ejemplo n.º 3
0
        public void RegisterPrefix()
        {
            IWebRequestCreate creator = (IWebRequestCreate) new ConcreteWebRequest();

            Assert.Throws <ArgumentNullException> (delegate {
                WebRequest.RegisterPrefix(null, creator);
            }, "null,creator");
            Assert.Throws <ArgumentNullException> (delegate {
                WebRequest.RegisterPrefix("ftp", null);
            }, "ftp,null");

            Assert.Throws <NotSupportedException> (delegate {
                WebRequest.Create("ftp://ftp.novell.com");
            }, "ftp-unregistred");

            Assert.IsTrue(WebRequest.RegisterPrefix(String.Empty, creator), "Empty");
            Assert.AreEqual(creator.GetType(), WebRequest.Create("ftp://ftp.novell.com").GetType(), "empty registred");

            Assert.IsTrue(WebRequest.RegisterPrefix("ftp", new Ftp()), "ftp-1");
            Assert.AreEqual(typeof(Ftp), WebRequest.Create("ftp://ftp.novell.com").GetType(), "ftp registred");

            // not twice
            Assert.IsFalse(WebRequest.RegisterPrefix("ftp", creator), "ftp-2");
            // not case sensitive
            Assert.IsFalse(WebRequest.RegisterPrefix("FTP", creator), "ftp-3");

            // "ftp:" is not considered identical
            Assert.IsTrue(WebRequest.RegisterPrefix("ftp:", new FtpColon()), "ftp:");
            Assert.AreEqual(typeof(FtpColon), WebRequest.Create("ftp://ftp.novell.com").GetType(), "ftp: registred");

            // "ftp:/" is also not considered identical
            Assert.IsTrue(WebRequest.RegisterPrefix("ftp:/", new FtpColonSlash()), "ftp:/");
            Assert.AreEqual(typeof(FtpColonSlash), WebRequest.Create("ftp://ftp.novell.com").GetType(), "ftp:/ registred");

            // "ftp://" is also not considered identical
            Assert.IsTrue(WebRequest.RegisterPrefix("ftp://", new FtpColonSlashSlash()), "ftp://");
            Assert.AreEqual(typeof(FtpColonSlashSlash), WebRequest.Create("ftp://ftp.novell.com").GetType(), "ftp:// registred");
        }