コード例 #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MailKit.BodyPartMultipart"/> class.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="BodyPartMultipart"/>.
		/// </remarks>
		public BodyPartMultipart ()
		{
			BodyParts = new BodyPartCollection ();
		}
コード例 #2
0
        public void TestBodyPartCollection()
        {
            var text = new BodyPartText {
                ContentType = new ContentType("text", "plain"), ContentLocation = new Uri("body", UriKind.Relative)
            };
            var image1 = new BodyPartBasic {
                ContentType = new ContentType("image", "jpeg"), ContentLocation = new Uri("http://localhost/image1.jpg")
            };
            var image2 = new BodyPartBasic {
                ContentType = new ContentType("image", "jpeg"), ContentId = "image2@localhost"
            };
            var list  = new BodyPartCollection();
            var parts = new BodyPart[3];
            int i     = 0;

            Assert.Throws <ArgumentNullException> (() => list.Add(null));
            Assert.Throws <ArgumentNullException> (() => list.Remove(null));
            Assert.Throws <ArgumentNullException> (() => list.Contains(null));
            Assert.Throws <ArgumentNullException> (() => list.IndexOf(null));
            Assert.Throws <ArgumentNullException> (() => list.CopyTo(null, 0));
            Assert.Throws <ArgumentOutOfRangeException> (() => list.CopyTo(parts, -1));
            Assert.Throws <ArgumentOutOfRangeException> (() => { var x = list[0]; });

            Assert.IsFalse(list.IsReadOnly);
            Assert.AreEqual(0, list.Count);

            list.Add(text);
            Assert.AreEqual(1, list.Count);
            Assert.IsTrue(list.Contains(text));
            Assert.IsFalse(list.Contains(image1));
            Assert.AreEqual(0, list.IndexOf(new Uri("body", UriKind.Relative)));
            Assert.AreEqual(-1, list.IndexOf(new Uri("http://localhost/image1.jpg")));
            Assert.AreEqual(-1, list.IndexOf(new Uri("cid:image2@localhost")));
            Assert.AreEqual(text, list[0]);

            list.Add(image1);
            Assert.AreEqual(2, list.Count);
            Assert.IsTrue(list.Contains(text));
            Assert.IsTrue(list.Contains(image1));
            Assert.AreEqual(0, list.IndexOf(new Uri("body", UriKind.Relative)));
            Assert.AreEqual(1, list.IndexOf(new Uri("http://localhost/image1.jpg")));
            Assert.AreEqual(-1, list.IndexOf(new Uri("cid:image2@localhost")));
            Assert.AreEqual(text, list[0]);
            Assert.AreEqual(image1, list[1]);

            Assert.IsTrue(list.Remove(text));
            Assert.AreEqual(1, list.Count);
            Assert.IsFalse(list.Contains(text));
            Assert.IsTrue(list.Contains(image1));
            Assert.AreEqual(-1, list.IndexOf(new Uri("body", UriKind.Relative)));
            Assert.AreEqual(0, list.IndexOf(new Uri("http://localhost/image1.jpg")));
            Assert.AreEqual(-1, list.IndexOf(new Uri("cid:image2@localhost")));
            Assert.AreEqual(image1, list[0]);

            list.Clear();
            Assert.AreEqual(0, list.Count);

            list.Add(text);
            list.Add(image1);
            list.Add(image2);
            list.CopyTo(parts, 0);
            Assert.AreEqual(0, list.IndexOf(new Uri("body", UriKind.Relative)));
            Assert.AreEqual(1, list.IndexOf(new Uri("http://localhost/image1.jpg")));
            Assert.AreEqual(2, list.IndexOf(new Uri("cid:image2@localhost")));

            foreach (var part in list)
            {
                Assert.AreEqual(parts[i++], part);
            }

            i = 0;
            foreach (var part in (IEnumerable)list)
            {
                Assert.AreEqual(parts[i++], part);
            }
        }
コード例 #3
0
 internal BodyPartMultipart()
 {
     BodyParts = new BodyPartCollection ();
 }
コード例 #4
0
ファイル: BodyPart.cs プロジェクト: BehnamEmamian/MailKit
		internal static void Encode (StringBuilder builder, BodyPartCollection parts)
		{
			if (parts == null || parts.Count == 0) {
				builder.Append ("NIL");
				return;
			}

			for (int i = 0; i < parts.Count; i++) {
				if (i > 0)
					builder.Append (' ');

				Encode (builder, parts[i]);
			}
		}
コード例 #5
0
        public IBodyPartCollection GetBodyPartCollection(string id)
        {
            var bodyPartCollection = BodyPartCollection.FirstOrDefault(x => x.Id == id);

            return(bodyPartCollection);
        }