コード例 #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();
 }
コード例 #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;
        }
コード例 #3
0
        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);
        }
コード例 #6
0
        public void TimeBetweenRefreshes_TimeBetweenRefreshesIsNotSet_Returns30()
        {
            // arrange
            EmailWatcherOptions options = new EmailWatcherOptions();

            // act
            int? timeBetweenRefreshes = options.TimeBetweenRefreshes;

            // assert
            Assert.AreEqual(30, timeBetweenRefreshes);
        }
コード例 #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;
        }
コード例 #8
0
 public bool Validate(EmailWatcherOptions options)
 {
     HasBeenCalled = true;
     return ValueToReturn;
 }
コード例 #9
0
        public void Setup()
        {
            _fakeEmailWatcherOptionsValidator = new FakeEmailWatcherOptionsValidator();
            _fakeEmailService = new FakeEmailService();

            _options = new EmailWatcherOptions { TimeBetweenRefreshes = 15 };
        }
コード例 #10
0
 public void Setup()
 {
     _stubEmailWatcherOptions = new EmailWatcherOptions();
     _fakePopClientFactory = new FakePopClientFactory();
     _messageTranslator = new MessageTranslator();
 }
コード例 #11
0
 public static EmailWatcher WithOptions(EmailWatcherOptions options)
 {
     return new EmailWatcher(options, new EmailWatcherOptionsValidator(), new EmailService(options, new PopClientFactory(), new MessageTranslator()));
 }