public override void Execute(EmailCommandArgs args)
        {
            var madeConnection = _serverService.ServerExists(args.IMAPServer);
            Contract.Requires(madeConnection);


            args.IsSuccessful = true;
        }
 public override void Execute(EmailCommandArgs args)
 {
     //TODO, inject the email helper
     var emailHelper = new EmailHelper();
     var emailAddress = args.EmailAddress;
     var emailIsValid = emailHelper.IsValidEmail(emailAddress);
     Contract.Requires(emailIsValid);
     args.IsSuccessful = true;
 }
        public void EmailCommandRollback_ExceptionThrow()
        {
            //arrange
            Int32 execCounter = 0;
            Int32 rollbackCounter = 0;

            //mock up the counters
            var mockEmailCommandPass = new Mock<ICommand<EmailCommandArgs>>();
            mockEmailCommandPass.Setup(a => a.Execute(It.IsAny<EmailCommandArgs>())).Callback(() =>
            {
                execCounter++;
            });
            mockEmailCommandPass.Setup(a => a.RollBack(It.IsAny<EmailCommandArgs>())).Callback(() =>
            {
                rollbackCounter++;
            });

            var mockEmailCommandFail = new Mock<ICommand<EmailCommandArgs>>();
            mockEmailCommandFail.Setup(a => a.Execute(It.IsAny<EmailCommandArgs>())).Callback<EmailCommandArgs>((a) =>
            {
                execCounter++;
                //do not set the IsSuccessful flag, to false, that
                //should be taken care of within the exception handler
                throw new Exception();
            });
            mockEmailCommandFail.Setup(a => a.RollBack(It.IsAny<EmailCommandArgs>())).Callback(() =>
            {

                rollbackCounter++;
            });

            var chain = new ProcessInboxChain();
            chain.AddCommand(mockEmailCommandPass.Object);
            chain.AddCommand(mockEmailCommandPass.Object);
            chain.AddCommand(mockEmailCommandPass.Object);
            chain.AddCommand(mockEmailCommandFail.Object);
            var args = new EmailCommandArgs(null, null, null, 0, false);

            //act
            chain.ExecuteChain(args);

            //assert
            mockEmailCommandFail.VerifyAll();
            mockEmailCommandPass.VerifyAll();
            Assert.IsFalse(args.IsSuccessful);
            Assert.IsTrue(execCounter == 4);
            Assert.IsTrue(rollbackCounter == 4);
            Assert.NotNull(args.Exception);
        }
        public void EmailCommandSuccess_Test()
        {
            //arrange
            Int32 execCounter = 0;
            Int32 rollbackCounter = 0;

            //mock up the counters
            var mockEmailCommandPass = new Mock<ICommand<EmailCommandArgs>>();
            mockEmailCommandPass.Setup(a => a.Execute(It.IsAny<EmailCommandArgs>())).Callback(() =>
            {
                execCounter++;
            });
            mockEmailCommandPass.Setup(a => a.RollBack(It.IsAny<EmailCommandArgs>())).Callback(() =>
            {
                rollbackCounter++;
            });

            var mockEmailCommandFail = new Mock<ICommand<EmailCommandArgs>>();
            mockEmailCommandFail.Setup(a => a.Execute(It.IsAny<EmailCommandArgs>())).Callback<EmailCommandArgs>((a) =>
            {
                a.IsSuccessful = false;
                execCounter++;
            });
            mockEmailCommandFail.Setup(a => a.RollBack(It.IsAny<EmailCommandArgs>())).Callback(() =>
            {

                rollbackCounter++;
            });

            var chain = new ProcessInboxChain();
            chain.AddCommand(mockEmailCommandPass.Object);
            chain.AddCommand(mockEmailCommandPass.Object);
            chain.AddCommand(mockEmailCommandPass.Object);
            chain.AddCommand(mockEmailCommandPass.Object);
            var args = new EmailCommandArgs(null, null, null, 0, false);

            //act
            chain.ExecuteChain(args);

            //assert
            Assert.IsTrue(args.IsSuccessful);
            Assert.IsTrue(execCounter == 4);
            Assert.IsTrue(rollbackCounter == 0);
        }
 public override void RollBack(EmailCommandArgs args)
 {
     
 }
 public override void RollBack(EmailCommandArgs args)
 {
     Console.WriteLine(@"Rollback Create Email Directory Command.");
 }
 public override void Execute(EmailCommandArgs args)
 {
     args.IsSuccessful = true;
     
 }
 public override void RollBack(EmailCommandArgs args)
 {
     //TODO, mark somewhere that this email address is not successful
 }