public void MoqPathFileWatcherException() { Mock <ISmtpSender> mockMailClient = new Mock <ISmtpSender>(); Mock <ILogger> mockNlog = new Mock <ILogger>(); FileWatcher.FileWatcher fileWatcher = new FileWatcher.FileWatcher("", mockMailClient.Object, mockNlog.Object); var ex = Assert.Throws <ArgumentException>(() => fileWatcher.Run()); Assert.That(ex.Message, Is.EqualTo("Путь имеет недопустимую форму.")); }
public void FileWatcherMethodParamException() { Mock <ILogger> mockNlog = new Mock <ILogger>(); Mock <ISmtpSender> smtpSender = new Mock <ISmtpSender>(); var fileWatcher = new FileWatcher.FileWatcher(null, smtpSender.Object, mockNlog.Object); var ex = Assert.Throws(typeof(ArgumentNullException), () => fileWatcher.Run()); Assert.That(ex.Message, Is.EqualTo("Пустое значение: директории\r\nИмя параметра: Directory")); fileWatcher = new FileWatcher.FileWatcher("C:\\MailFolder", null, mockNlog.Object); ex = Assert.Throws(typeof(ArgumentNullException), () => fileWatcher.Run()); Assert.That(ex.Message, Is.EqualTo("Пустое значение: SmtpSender\r\nИмя параметра: SmtpSender")); }
static void Main(string[] args) { NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); logger = NLog.LogManager.GetCurrentClassLogger(); string _emailFrom = ConfigurationManager.AppSettings.Get("emailFrom"); string _nameFrom = ConfigurationManager.AppSettings.Get("nameFrom"); string _password = ConfigurationManager.AppSettings.Get("password"); string _emailTo = ConfigurationManager.AppSettings.Get("emailTo"); string _directory = ConfigurationManager.AppSettings.Get("directory"); string _header = ConfigurationManager.AppSettings.Get("header"); string _pathToMessage = ConfigurationManager.AppSettings.Get("pathToMessage"); string _message = ""; using (StreamReader sr = new StreamReader(_pathToMessage)) { _message = sr.ReadToEnd(); } ISmtpSender smtpSender = new SmtpSender(_emailFrom, _password, _nameFrom, _emailTo, _header, _message, logger); IFileWatcher fileWatcher = new FileWatcher.FileWatcher(_directory, smtpSender, logger); fileWatcher.Run(); }