public void TestArgumentExceptions() { var contentType = new ContentType("application", "octet-stream"); var attachments = new AttachmentCollection(); var items = new MimeEntity[10]; var data = new byte[1024]; using (var stream = new MemoryStream()) { Assert.Throws <ArgumentException> (() => attachments.Add(string.Empty)); Assert.Throws <ArgumentNullException> (() => attachments.Add((string)null)); Assert.Throws <ArgumentNullException> (() => attachments.Add((MimeEntity)null)); Assert.Throws <ArgumentException> (() => attachments.Add(string.Empty, data)); Assert.Throws <ArgumentNullException> (() => attachments.Add((string)null, data)); Assert.Throws <ArgumentException> (() => attachments.Add(string.Empty, stream)); Assert.Throws <ArgumentNullException> (() => attachments.Add((string)null, stream)); Assert.Throws <ArgumentException> (() => attachments.Add(string.Empty, contentType)); Assert.Throws <ArgumentNullException> (() => attachments.Add((string)null, contentType)); Assert.Throws <ArgumentException> (() => attachments.Add(string.Empty, data, contentType)); Assert.Throws <ArgumentNullException> (() => attachments.Add((string)null, data, contentType)); Assert.Throws <ArgumentException> (() => attachments.Add(string.Empty, stream, contentType)); Assert.Throws <ArgumentNullException> (() => attachments.Add((string)null, stream, contentType)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", (byte[])null)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", (Stream)null)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", (byte[])null, contentType)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", (Stream)null, contentType)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", (ContentType)null)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", data, null)); Assert.Throws <ArgumentNullException> (() => attachments.Add("file.dat", stream, null)); Assert.Throws <ArgumentNullException> (() => attachments.Contains(null)); Assert.Throws <ArgumentNullException> (() => attachments.CopyTo(null, 0)); Assert.Throws <ArgumentOutOfRangeException> (() => attachments.CopyTo(items, -1)); Assert.Throws <ArgumentNullException> (() => attachments.IndexOf(null)); Assert.Throws <ArgumentNullException> (() => attachments.Remove(null)); Assert.Throws <ArgumentOutOfRangeException> (() => attachments.RemoveAt(0)); attachments.Add(new TextPart("plain")); Assert.Throws <ArgumentOutOfRangeException> (() => { var x = attachments[10]; }); Assert.Throws <ArgumentOutOfRangeException> (() => attachments[10] = new TextPart("plain")); Assert.Throws <ArgumentNullException> (() => attachments[0] = null); Assert.Throws <ArgumentOutOfRangeException> (() => attachments.Insert(-1, new TextPart("plain"))); Assert.Throws <ArgumentNullException> (() => attachments.Insert(0, null)); } }