示例#1
0
        public void PostMultipart()
        {
            var  httpHandler       = new TestWebRequestHandler();
            bool callbackTriggered = false;

            httpHandler.Callback = req => {
                Match m = Regex.Match(req.ContentType, "multipart/form-data; boundary=(.+)");
                Assert.IsTrue(m.Success, "Content-Type HTTP header not set correctly.");
                string boundary = m.Groups[1].Value;
                boundary = boundary.Substring(0, boundary.IndexOf(';'));                 // trim off charset
                string expectedEntity = "--{0}\r\nContent-Disposition: form-data; name=\"a\"\r\n\r\nb\r\n--{0}--\r\n";
                expectedEntity = string.Format(expectedEntity, boundary);
                string actualEntity = httpHandler.RequestEntityAsString;
                Assert.AreEqual(expectedEntity, actualEntity);
                callbackTriggered = true;
                Assert.AreEqual(req.ContentLength, actualEntity.Length);
                IncomingWebResponse resp = new CachedDirectWebResponse();
                return(resp);
            };
            var request = (HttpWebRequest)WebRequest.Create("http://someserver");
            var parts   = new[] {
                MultipartPostPart.CreateFormPart("a", "b"),
            };

            request.PostMultipart(httpHandler, parts);
            Assert.IsTrue(callbackTriggered);
        }
示例#2
0
		public override void SetUp() {
			base.SetUp();

			this.webRequestHandler = new TestWebRequestHandler();
			this.signingElement = new RsaSha1SigningBindingElement(new InMemoryTokenManager());
			this.nonceStore = new NonceMemoryStore(StandardExpirationBindingElement.MaximumMessageAge);
			this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageFactory());
			this.channel.WebRequestHandler = this.webRequestHandler;
		}