I am looking at the Unit Tests I wrote for an email service (unsing SMTP) and I am wondering if one test inparticular is suffient. Here is a snippet of my email service:
[PluginFamily("EmailService")]
public interface IEmailService
{
Boolean SendEmail( string toAddress, string fromAddress, string bccAddress, string ccAddress, string subject,
string body, bool html );
}
[Pluggable("EmailService")]
public class EmailService : IEmailService
{
private IConfigurationReader _configReader;
public EmailService(IConfigurationReader configurationReader)
{
_configReader = configurationReader;
}
public bool SendEmail( string toAddress, string fromAddress, string bccAddress, string ccAddress, string subject, string body, bool isHtml )
{
MailMessage email = new MailMessage();
try
{
if (_configReader.TestMode)
{
toAddress = _configReader.TestEmailAddress;
}
}
//send email here
}
}
I am mocking IConfigurationReader (basically a wrapper for ConfigurationManager) and setting the test mode = true to test if I can send an email in my "test mode" in my unit test. So my unit test looks something like this (This is one of my unit tests on the method...I have 100% code coverage):
[Test]
public void Validate_Send_Email_In_Test_Mode()
{
bool result;
MockRepository mockRepository = new MockRepository();
var mockConfigReader = mockRepository.StrictMock<IConfigurationReader>();
using (mockRepository.Record())
{
SetupResult.For(mockConfigReader.TestMode).Return(true);
SetupResult.For(mockConfigReader.TestEmailAddress).Return("[email protected]");
SetupResult.For(mockConfigReader.EmailContentLocation).Return("test");
SetupResult.For( mockConfigReader.SmtpHost ).Return( "test.mail.com" );
}
ObjectFactory.InjectStub(typeof(IConfigurationReader), mockConfigReader);
emailService = ObjectFactory.GetInstance<IEmailService>();
using (mockRepository.Playback())
{
result = emailService.SendEmail( "[email protected]",
"[email protected]", "", "",
"this is a unit test - config in test mode", "body of unit test", true );
}
Assert.That( result, Is.True );
ObjectFactory.ResetDefaults();
}
Is this a sufficient enough of a unit test? What can I do to improve it?
I am concerned that just checking that my method is returing a true is not a sufficient enough of a unit test.