public void TestPop3CommandException()
        {
            Pop3CommandException expected;

            expected = new Pop3CommandException();
            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, expected);
                stream.Position = 0;

                var ex = (Pop3CommandException)formatter.Deserialize(stream);
                Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message.");
                Assert.AreEqual(expected.StatusText, ex.StatusText, "Unexpected StatusText.");
            }

            expected = new Pop3CommandException("This is the error message.");
            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, expected);
                stream.Position = 0;

                var ex = (Pop3CommandException)formatter.Deserialize(stream);
                Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message.");
                Assert.AreEqual(expected.StatusText, ex.StatusText, "Unexpected StatusText.");
            }

            expected = new Pop3CommandException("This is the error message.", new IOException("There was an IO error."));
            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, expected);
                stream.Position = 0;

                var ex = (Pop3CommandException)formatter.Deserialize(stream);
                Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message.");
                Assert.AreEqual(expected.StatusText, ex.StatusText, "Unexpected StatusText.");
            }

            expected = new Pop3CommandException("This is the error message.", "This is the status text");
            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, expected);
                stream.Position = 0;

                var ex = (Pop3CommandException)formatter.Deserialize(stream);
                Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message.");
                Assert.AreEqual(expected.StatusText, ex.StatusText, "Unexpected StatusText.");
            }

            expected = new Pop3CommandException("This is the error message.", "This is the status text", new IOException("There was an IO error."));
            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, expected);
                stream.Position = 0;

                var ex = (Pop3CommandException)formatter.Deserialize(stream);
                Assert.AreEqual(expected.Message, ex.Message, "Unexpected Message.");
                Assert.AreEqual(expected.StatusText, ex.StatusText, "Unexpected StatusText.");
            }
        }
示例#2
0
        public void TestPop3CommandException()
        {
            var expected = new Pop3CommandException("Message", "Bad boys, bad boys. Whatcha gonna do?");

            Assert.Throws <ArgumentNullException> (() => new Pop3CommandException("Message", (string)null));
            Assert.Throws <ArgumentNullException> (() => new Pop3CommandException("Message", null, new Exception("inner")));

            using (var stream = new MemoryStream()) {
                var formatter = new BinaryFormatter();
                formatter.Serialize(stream, expected);
                stream.Position = 0;

                var ex = (Pop3CommandException)formatter.Deserialize(stream);
                Assert.AreEqual(expected.StatusText, ex.StatusText, "Unexpected StatusText.");
            }
        }