示例#1
0
        private Message GetMessageById(Guid id)
        {
            var message = messages.Find(m => m.Id.Equals(id));

            if (message == null)
            {
                MessageNotFoundException exception = new MessageNotFoundException("Message not found");
                exception.Data["MessageId"] = id;
                throw exception;
            }

            return(message);
        }
示例#2
0
        public void TestMessageNotFoundException()
        {
            var expected = new MessageNotFoundException("This is the message.");

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

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

            expected = new MessageNotFoundException("This is the message.", new IOException("Inner Exception"));

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

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