public void Test_message() { string longM = "this is a very very very long message..."; string shortM = "short SMS"; IMessageSender smsMessageSender = new SMSMessageSender(); IMessageSender emailMessageSender = new EmailMessageSender(); // Short message ShortMessage shortMessage = new ShortMessage(smsMessageSender); { shortMessage.SendMessage(shortM); Assert.That(shortMessage.GetMessageSentCount(), Is.EqualTo(1)); shortMessage.SendMessage(shortM); shortMessage.SendMessage(shortM); shortMessage.SendMessage(shortM); shortMessage.SendMessage(shortM); Assert.That(shortMessage.GetMessageSentCount(), Is.EqualTo(5)); Assert.That(shortMessage.GetSenderType(), Is.EqualTo(SenderType.SMS)); Assert.That(shortMessage.GetSenderType(), !Is.EqualTo(SenderType.Email)); } // Null message { var ex = Assert.Throws <ArgumentNullException>(() => { shortMessage.SendMessage(string.Empty); }); Assert.That(ex.Message, Is.EqualTo("Invalid message. (Parameter 'message')")); } // Long message { var ex = Assert.Throws <ArgumentException>(() => { shortMessage.SendMessage(longM); }); Assert.That(ex.Message, Is.EqualTo("Invalid message: message is too long. (Parameter 'message')")); } // Long message LongMessage longMessage = new LongMessage(emailMessageSender); { longMessage.SendMessage(longM); Assert.That(longMessage.GetMessageSentCount(), Is.EqualTo(1)); longMessage.SendMessage(longM); longMessage.SendMessage(longM); Assert.That(longMessage.GetMessageSentCount(), Is.EqualTo(3)); Assert.That(longMessage.GetSenderType(), !Is.EqualTo(SenderType.SMS)); Assert.That(longMessage.GetSenderType(), Is.EqualTo(SenderType.Email)); } // Null message { var ex = Assert.Throws <ArgumentNullException>(() => { longMessage.SendMessage(string.Empty); }); Assert.That(ex.Message, Is.EqualTo("Invalid message. (Parameter 'message')")); } // Short message { var ex = Assert.Throws <ArgumentException>(() => { longMessage.SendMessage(shortM); }); Assert.That(ex.Message, Is.EqualTo("Invalid message: message is too short. (Parameter 'message')")); } }