In my most recent homework, we were provided a class library and told to complete unit testing to ensure the changes we made to comply with SOLID didn't break the code.
The problem I have is that all the methods are void. I may just be ignorant but I don't know how you're supposed to Unit Test Void methods.
Should I just refactor the methods to return something instead of leaving it void? I'll provide one of the methods from the code. I would appreciate some ideas to move me in the right direction. Thank you!
public class Cart : ICart
{
public decimal TotalAmount { get; set; }
public IEnumerable<OrderItem> Items { get; set; }
public string CustomerEmail { get; set; }
}
public class OrderNotifyCustomer
{
public static void NotifyCustomer(Cart cart)
{
string customerEmail = cart.CustomerEmail;
if (!String.IsNullOrEmpty(customerEmail))
{
using (var message = new MailMessage("orders@somewhere.com", customerEmail))
using (var client = new SmtpClient("localhost"))
{
message.Subject = "Your order placed on " + DateTime.Now.ToString();
message.Body = "Your order details: \n " + cart.ToString();
try
{
client.Send(message);
}
catch (Exception ex)
{
Logger.Error("Problem sending notification email", ex);
}
}
}
}
}