Exemplo n.º 1
0
        public async Task ReadAsStringAsync_NoSubContent_MatchesExpected()
        {
            var mc = new MultipartContent("someSubtype", "theBoundary");

            Assert.Equal(
                "--theBoundary\r\n" +
                "\r\n" +
                "--theBoundary--\r\n",
                await mc.ReadAsStringAsync());
        }
        public void Add()
        {
            var m = new MultipartContent ("a", "b");

            var other = new MultipartContent ("2", "44");
            other.Headers.Expires = new DateTimeOffset (2020, 11, 30, 19, 55, 22, TimeSpan.Zero);
            m.Add (other);

            Assert.AreEqual ("multipart/a", m.Headers.ContentType.MediaType, "#1");
            Assert.AreEqual (114, m.Headers.ContentLength, "#2");
            Assert.AreEqual ("--b\r\nContent-Type: multipart/2; boundary=\"44\"\r\nExpires: Mon, 30 Nov 2020 19:55:22 GMT\r\n\r\n--44\r\n\r\n--44--\r\n\r\n--b--\r\n", m.ReadAsStringAsync ().Result, "#3");
            Assert.AreEqual (other, m.First (), "#4");
        }
        public void Add_2()
        {
            var m = new MultipartContent ("a", "X");

            var other = new MultipartContent ("2", "2a");
            m.Add (other);
            var other2 = new MultipartContent ("3", "3a");
            other2.Headers.Add ("9", "9n");
            m.Add (other2);

            Assert.AreEqual ("multipart/a", m.Headers.ContentType.MediaType, "#1");
            Assert.AreEqual (148, m.Headers.ContentLength, "#2");
            Assert.AreEqual ("--X\r\nContent-Type: multipart/2; boundary=\"2a\"\r\n\r\n--2a\r\n\r\n--2a--\r\n\r\n--X\r\nContent-Type: multipart/3; boundary=\"3a\"\r\n9: 9n\r\n\r\n--3a\r\n\r\n--3a--\r\n\r\n--X--\r\n",
                m.ReadAsStringAsync ().Result, "#3");
            Assert.AreEqual (other, m.First (), "#4");
        }
        public void Add_Resursive()
        {
            var m = new MultipartContent("1", "1a");

            var other = new MultipartContent("2", "2a");

            m.Add(other);

            var other2 = new MultipartContent("3", "3a");

            other.Add(other2);

            Assert.AreEqual("multipart/1", m.Headers.ContentType.MediaType, "#1");
            Assert.AreEqual(136, m.Headers.ContentLength, "#2");
            Assert.AreEqual("--1a\r\nContent-Type: multipart/2; boundary=\"2a\"\r\n\r\n--2a\r\nContent-Type: multipart/3; boundary=\"3a\"\r\n\r\n--3a\r\n\r\n--3a--\r\n\r\n--2a--\r\n\r\n--1a--\r\n",
                            m.ReadAsStringAsync().Result, "#3");
            Assert.AreEqual(other, m.First(), "#4");
        }
        public void Add_2()
        {
            var m = new MultipartContent("a", "X");

            var other = new MultipartContent("2", "2a");

            m.Add(other);
            var other2 = new MultipartContent("3", "3a");

            other2.Headers.Add("9", "9n");
            m.Add(other2);

            Assert.AreEqual("multipart/a", m.Headers.ContentType.MediaType, "#1");
            Assert.AreEqual(148, m.Headers.ContentLength, "#2");
            Assert.AreEqual("--X\r\nContent-Type: multipart/2; boundary=\"2a\"\r\n\r\n--2a\r\n\r\n--2a--\r\n\r\n--X\r\nContent-Type: multipart/3; boundary=\"3a\"\r\n9: 9n\r\n\r\n--3a\r\n\r\n--3a--\r\n\r\n--X--\r\n",
                            m.ReadAsStringAsync().Result, "#3");
            Assert.AreEqual(other, m.First(), "#4");
        }
Exemplo n.º 6
0
        public async Task ReadAsStringAsync_TwoSubContents_MatchesExpected()
        {
            var mc = new MultipartContent("someSubtype", "theBoundary");

            mc.Add(new ByteArrayContent(Encoding.UTF8.GetBytes("This is a ByteArrayContent")));
            mc.Add(new StringContent("This is a StringContent"));

            Assert.Equal(
                "--theBoundary\r\n" +
                "\r\n" +
                "This is a ByteArrayContent\r\n" +
                "--theBoundary\r\n" +
                "Content-Type: text/plain; charset=utf-8\r\n" +
                "\r\n" +
                "This is a StringContent\r\n" +
                "--theBoundary--\r\n",
                await mc.ReadAsStringAsync());
        }
        public void Ctor()
        {
            using (var m = new MultipartContent("a", "b")) {
                m.Headers.Add("extra", "value");
                Assert.AreEqual("multipart/a", m.Headers.ContentType.MediaType, "#1");
                Assert.AreEqual(14, m.Headers.ContentLength, "#2");
                Assert.AreEqual("--b\r\n\r\n--b--\r\n", m.ReadAsStringAsync().Result, "#3");
            }

            using (var m = new MultipartContent()) {
                Assert.AreEqual("multipart/mixed", m.Headers.ContentType.MediaType, "#11");
                Assert.AreEqual(84, m.Headers.ContentLength, "#12");
            }

            using (var m = new MultipartContent("ggg")) {
                Assert.AreEqual("multipart/ggg", m.Headers.ContentType.MediaType, "#21");
                Assert.AreEqual(84, m.Headers.ContentLength, "#22");
            }
        }
Exemplo n.º 8
0
        public async Task ReadAsStringAsync_OneSubContentWithHeaders_MatchesExpected()
        {
            var subContent = new ByteArrayContent(Encoding.UTF8.GetBytes("This is a ByteArrayContent"));

            subContent.Headers.Add("someHeaderName", "andSomeHeaderValue");
            subContent.Headers.Add("someOtherHeaderName", new[] { "withNotOne", "ButTwoValues" });
            subContent.Headers.Add("oneMoreHeader", new[] { "withNotOne", "AndNotTwo", "butThreeValues" });

            var mc = new MultipartContent("someSubtype", "theBoundary");

            mc.Add(subContent);

            Assert.Equal(
                "--theBoundary\r\n" +
                "someHeaderName: andSomeHeaderValue\r\n" +
                "someOtherHeaderName: withNotOne, ButTwoValues\r\n" +
                "oneMoreHeader: withNotOne, AndNotTwo, butThreeValues\r\n" +
                "\r\n" +
                "This is a ByteArrayContent\r\n" +
                "--theBoundary--\r\n",
                await mc.ReadAsStringAsync());
        }
Exemplo n.º 9
0
		public void Ctor ()
		{
			using (var m = new MultipartContent ("a", "b")) {
				m.Headers.Add ("extra", "value");
				Assert.AreEqual ("multipart/a", m.Headers.ContentType.MediaType, "#1");
				Assert.AreEqual (14, m.Headers.ContentLength, "#2");
				Assert.AreEqual ("--b\r\n\r\n--b--\r\n", m.ReadAsStringAsync ().Result, "#3");
			}

			using (var m = new MultipartContent ()) {
				Assert.AreEqual ("multipart/mixed", m.Headers.ContentType.MediaType, "#11");
				Assert.AreEqual (84, m.Headers.ContentLength, "#12");
			}

			using (var m = new MultipartContent ("ggg")) {
				Assert.AreEqual ("multipart/ggg", m.Headers.ContentType.MediaType, "#21");
				Assert.AreEqual (84, m.Headers.ContentLength, "#22");
			}
		}
Exemplo n.º 10
0
		public void Add_Resursive ()
		{
			var m = new MultipartContent ("1", "1a");

			var other = new MultipartContent ("2", "2a");
			m.Add (other);

			var other2 = new MultipartContent ("3", "3a");
			other.Add (other2);

			Assert.AreEqual ("multipart/1", m.Headers.ContentType.MediaType, "#1");
			Assert.AreEqual (136, m.Headers.ContentLength, "#2");
			Assert.AreEqual ("--1a\r\nContent-Type: multipart/2; boundary=\"2a\"\r\n\r\n--2a\r\nContent-Type: multipart/3; boundary=\"3a\"\r\n\r\n--3a\r\n\r\n--3a--\r\n\r\n--2a--\r\n\r\n--1a--\r\n",
				m.ReadAsStringAsync ().Result, "#3");
			Assert.AreEqual (other, m.First (), "#4");
		}
Exemplo n.º 11
0
        public void Add()
        {
            var m = new MultipartContent("a", "b");

            var other = new MultipartContent("2", "44");

            other.Headers.Expires = new DateTimeOffset(2020, 11, 30, 19, 55, 22, TimeSpan.Zero);
            m.Add(other);

            Assert.AreEqual("multipart/a", m.Headers.ContentType.MediaType, "#1");
            Assert.AreEqual(114, m.Headers.ContentLength, "#2");
            Assert.AreEqual("--b\r\nContent-Type: multipart/2; boundary=\"44\"\r\nExpires: Mon, 30 Nov 2020 19:55:22 GMT\r\n\r\n--44\r\n\r\n--44--\r\n\r\n--b--\r\n", m.ReadAsStringAsync().Result, "#3");
            Assert.AreEqual(other, m.First(), "#4");
        }
Exemplo n.º 12
0
        public async Task ReadAsStringAsync_TwoSubContents_MatchesExpected()
        {
            var mc = new MultipartContent("someSubtype", "theBoundary");
            mc.Add(new ByteArrayContent(Encoding.UTF8.GetBytes("This is a ByteArrayContent")));
            mc.Add(new StringContent("This is a StringContent"));

            Assert.Equal(
                "--theBoundary\r\n" +
                "\r\n" +
                "This is a ByteArrayContent\r\n" +
                "--theBoundary\r\n" +
                "Content-Type: text/plain; charset=utf-8\r\n" +
                "\r\n" +
                "This is a StringContent\r\n" +
                "--theBoundary--\r\n",
                await mc.ReadAsStringAsync());
        }
Exemplo n.º 13
0
        public async Task ReadAsStringAsync_OneSubContentWithHeaders_MatchesExpected()
        {
            var subContent = new ByteArrayContent(Encoding.UTF8.GetBytes("This is a ByteArrayContent"));
            subContent.Headers.Add("someHeaderName", "andSomeHeaderValue");
            subContent.Headers.Add("someOtherHeaderName", new[] { "withNotOne", "ButTwoValues" });
            subContent.Headers.Add("oneMoreHeader", new[] { "withNotOne", "AndNotTwo", "butThreeValues" });

            var mc = new MultipartContent("someSubtype", "theBoundary");
            mc.Add(subContent);

            Assert.Equal(
                "--theBoundary\r\n" +
                "someHeaderName: andSomeHeaderValue\r\n" +
                "someOtherHeaderName: withNotOne, ButTwoValues\r\n" +
                "oneMoreHeader: withNotOne, AndNotTwo, butThreeValues\r\n" +
                "\r\n" +
                "This is a ByteArrayContent\r\n" +
                "--theBoundary--\r\n", 
                await mc.ReadAsStringAsync());
        }
Exemplo n.º 14
0
        public async Task ReadAsStringAsync_NoSubContent_MatchesExpected()
        {
            var mc = new MultipartContent("someSubtype", "theBoundary");

            Assert.Equal(
                "--theBoundary\r\n" +
                "\r\n" +
                "--theBoundary--\r\n", 
                await mc.ReadAsStringAsync());
        }