Posts

Showing posts with the label Moq

Using moq to test class that extends abstract class

Sometimes we've to test a class that extend an anstract class and use other components of the project. For example, we have a ExcelLoader that extend an abstract class Loader, that read an excel file and use data inserted in the file to send mail or send SMS to some users. ExcelLoader It's an important class of our project so it's usefull cover this class with some test, but could be difficult test the class with really instance of the components that send mail and SMS. So we want test only the behavior of ExcelLoader The code public abstract class Loader { public abstract void ImportFile(Stream stream); public abstract IEnumerable<RowFile> GetRows(Stream stream); } public class ExcelLoader : Loader { IMailManager mailManager; ISMSManager smsManager; public ExcelLoader(IMailManager mailManager, ISMSManager smsManager) { this.mailManager = mailManager; this.smsManager = sm