Ejemplo n.º 1
0
 public static void Main()
 {
     var options = new EmailWatcherOptions { Host = Pop3Hostname, Username = Username, Password = Password, TimeBetweenRefreshes = 30 };
     var watcher = EmailWatcher.Public.EmailWatcher.WithOptions(options);
     watcher.EmailReceivedEvent += (sender, args) => Console.WriteLine("Email Received! Id {0} Subject: {1}, Body: {2}", args.Message.Id, args.Message.Subject, args.Message.Body);
     watcher.StartWatching();
 }
Ejemplo n.º 2
0
        public EmailService(EmailWatcherOptions options, IPopClientFactory factory, MessageTranslator translator)
        {
            if (options == null)
            {
                Logger.LogError(ExceptionMessageConstants.EmailOptionsCannotBeNull);
                throw new Exception();
            }

            if (factory == null)
            {
                Logger.LogError(ExceptionMessageConstants.PopClientFactoryCannotBeNull);
                throw new Exception();
            }

            if (translator == null)
            {
                Logger.LogError(ExceptionMessageConstants.EmailWatcherMessageTranslatorCannotBeNull);
                throw new Exception();
            }

            _host = options.Host;
            _username = options.Username;
            _password = options.Password;
            _factory = factory;
            _translator = translator;
        }
        public bool Validate(EmailWatcherOptions options)
        {
            if (options == null)
            {
                Logger.LogError(ExceptionMessageConstants.EmailOptionsCannotBeNull);
                return false;
            }

            if (options.Host == null)
            {
                Logger.LogError(ExceptionMessageConstants.HostCannotBeNull);
                return false;
            }

            if (options.Username == null)
            {
                Logger.LogError(ExceptionMessageConstants.UsernameCannotBeNull);
                return false;
            }

            if (options.Password == null)
            {
                Logger.LogError(ExceptionMessageConstants.PasswordCannotBeNull);
                return false;
            }

            return true;
        }
        public void Validate_UsernameIsNull_ReturnsFalse()
        {
            // arrange
            EmailWatcherOptions options = new EmailWatcherOptions { Host = StubHost, Password = StubPassword, TimeBetweenRefreshes = StubTimeBetweenRefreshes };

            // act
            bool result = _emailWatcherOptionsValidator.Validate(options);

            // assert
            Assert.AreEqual(false, result);
        }
        public void Validate_TimeBetweenRefreshesIsNull_ReturnsTrue()
        {
            // arrange
            EmailWatcherOptions options = new EmailWatcherOptions { Host = StubHost, Username = StubUsername, Password = StubPassword };

            // act
            bool result = _emailWatcherOptionsValidator.Validate(options);

            // assert
            Assert.AreEqual(true, result);
        }
        public void TimeBetweenRefreshes_TimeBetweenRefreshesIsNotSet_Returns30()
        {
            // arrange
            EmailWatcherOptions options = new EmailWatcherOptions();

            // act
            int? timeBetweenRefreshes = options.TimeBetweenRefreshes;

            // assert
            Assert.AreEqual(30, timeBetweenRefreshes);
        }
Ejemplo n.º 7
0
        internal EmailWatcher(EmailWatcherOptions options, IEmailWatcherOptionsValidator validator, IEmailService service)
        {
            if (validator == null)
            {
                Logger.LogError(ExceptionMessageConstants.ValidatorCannotBeNull);
                throw new Exception();
            }

            if (service == null)
            {
                Logger.LogError(ExceptionMessageConstants.EmailServiceCannotBeNull);
                throw new Exception();
            }

            if (validator.Validate(options) == false)
            {
                Logger.LogError(ExceptionMessageConstants.InvalidEmailOptions);
                throw new Exception();
            }

            _options = options;
            _service = service;
        }
 public bool Validate(EmailWatcherOptions options)
 {
     HasBeenCalled = true;
     return ValueToReturn;
 }
        public void Setup()
        {
            _fakeEmailWatcherOptionsValidator = new FakeEmailWatcherOptionsValidator();
            _fakeEmailService = new FakeEmailService();

            _options = new EmailWatcherOptions { TimeBetweenRefreshes = 15 };
        }
 public void Setup()
 {
     _stubEmailWatcherOptions = new EmailWatcherOptions();
     _fakePopClientFactory = new FakePopClientFactory();
     _messageTranslator = new MessageTranslator();
 }
Ejemplo n.º 11
0
 public static EmailWatcher WithOptions(EmailWatcherOptions options)
 {
     return new EmailWatcher(options, new EmailWatcherOptionsValidator(), new EmailService(options, new PopClientFactory(), new MessageTranslator()));
 }