예제 #1
0
파일: MultipartTest.cs 프로젝트: yhhno/nfx
        public void Charset1251()
        {
            var part = new Multipart.Part("field");
              part.FileName = "text";
              part.ContentType = "Content-type: text/plain; charset=windows-1251";
              part.Content = Encoding.GetEncoding(1251).GetBytes("Значение");

              var mpE = new Multipart(new Multipart.Part[] {part});
              var enc = mpE.Encode();

              var boundary = enc.Boundary;
              var mpD = Multipart.ReadFromBytes(enc.Buffer, ref boundary);
              Assert.AreEqual("Значение", mpD.Parts["field"].Content);
        }
예제 #2
0
파일: MultipartTest.cs 프로젝트: yhhno/nfx
        public void EncodeDecode_FieldAndFile()
        {
            var partField = getDefaultField();
              var partFile = getDefaultFile();

              var mpE = new Multipart(new Multipart.Part[] { partField, partFile });
              var encCont = mpE.Encode();

              string boundary = null;
              var mpD = Multipart.ReadFromBytes(encCont.Buffer, ref boundary);

              Assert.AreEqual(encCont.Boundary, boundary);
              Assert.AreEqual(2, mpD.Parts.Count);

              Assert.AreEqual(partField.Content.AsString(), mpD.Parts[partField.Name].Content.AsString());
              Assert.IsNull(mpD.Parts[partField.Name].ContentType);
              Assert.IsNull(mpD.Parts[partField.Name].FileName);
              Assert.AreEqual(partFile.FileName, mpD.Parts[partFile.Name].FileName);
              Assert.AreEqual(partFile.ContentType, mpD.Parts[partFile.Name].ContentType);
              Assert.IsTrue(IOMiscUtils.MemBufferEquals(partFile.Content as byte[], mpD.Parts[partFile.Name].Content as byte[]));
        }
예제 #3
0
파일: MultipartTest.cs 프로젝트: yhhno/nfx
        public void EncodeToStreamDecode()
        {
            var partField = getDefaultField();
              var partFile = getDefaultFile();

              var stream = new MemoryStream();
              stream.WriteByte(0xFF);
              stream.WriteByte(0xFF);

              var mpE = new Multipart(new Multipart.Part[] { partField, partFile });
              var enc = mpE.Encode(stream);
              Assert.AreEqual(enc.StartIdx, 2);

              var src = new byte[enc.Length];
              Array.Copy(enc.Buffer, enc.StartIdx, src, 0, src.Length);

              string boundary = null;
              var mpD = Multipart.ReadFromBytes(src, ref boundary);

              Assert.AreEqual(enc.Boundary, boundary);
              Assert.AreEqual(partField.Content.AsString(), mpD.Parts[partField.Name].Content.AsString());
              Assert.IsNull(mpD.Parts[partField.Name].ContentType);
              Assert.IsNull(mpD.Parts[partField.Name].FileName);
              Assert.AreEqual(partFile.FileName, mpD.Parts[partFile.Name].FileName);
              Assert.AreEqual(partFile.ContentType, mpD.Parts[partFile.Name].ContentType);
              Assert.IsTrue(IOMiscUtils.MemBufferEquals(partFile.Content as byte[], mpD.Parts[partFile.Name].Content as byte[]));
        }
예제 #4
0
파일: MultipartTest.cs 프로젝트: yhhno/nfx
        public void EncodeDecode_OneFile()
        {
            var part = getDefaultFile();

              var mpE = new Multipart(new Multipart.Part[] { part });
              var encCont = mpE.Encode();

              string boundary = null;
              var mpD = Multipart.ReadFromBytes(encCont.Buffer, ref boundary);

              Assert.AreEqual(encCont.Boundary, boundary);
              Assert.AreEqual(1, mpD.Parts.Count);
              Assert.IsTrue(IOMiscUtils.MemBufferEquals(part.Content as byte[], mpD.Parts[part.Name].Content as byte[]));
              Assert.AreEqual(part.FileName, mpD.Parts[part.Name].FileName);
              Assert.AreEqual(part.ContentType, mpD.Parts[part.Name].ContentType);
        }
예제 #5
0
파일: MultipartTest.cs 프로젝트: yhhno/nfx
        public void EncodeDecode_OneField_Enc1251()
        {
            var encoding = Encoding.GetEncoding(1251);
              var part = new Multipart.Part("Field");
              part.Content = "Значение";

              var mpE = new Multipart(new Multipart.Part[] { part });
              var encCont = mpE.Encode(encoding);

              string boundary = null;
              var mpD = Multipart.ReadFromBytes(encCont.Buffer, ref boundary, encoding);

              Assert.AreEqual(encCont.Boundary, boundary);
              Assert.AreEqual(encCont.Encoding, encoding);
              Assert.AreEqual(1, mpD.Parts.Count);
              Assert.AreEqual(part.Content.AsString(), mpD.Parts[part.Name].Content.AsString());
              Assert.IsNull(mpD.Parts[part.Name].ContentType);
              Assert.IsNull(mpD.Parts[part.Name].FileName);
        }
예제 #6
0
파일: MultipartTest.cs 프로젝트: yhhno/nfx
        public void EncodeDecode_OneField()
        {
            var part = getDefaultField();

              var mpE = new Multipart(new Multipart.Part[] { part });
              var encCont = mpE.Encode();

              string boundary = null;
              var mpD = Multipart.ReadFromBytes(encCont.Buffer, ref boundary);

              Assert.AreEqual(encCont.Boundary, boundary);
              Assert.AreEqual(1, mpD.Parts.Count);
              Assert.AreEqual(part.Content.AsString(), mpD.Parts[part.Name].Content.AsString());
              Assert.IsNull(mpD.Parts[part.Name].ContentType);
              Assert.IsNull(mpD.Parts[part.Name].FileName);
        }