Ejemplo n.º 1
0
        public void SendStatementEmails(DateTime statementDate)
        {
            var housekeepers = _unitOfWork.Query <Housekeeper>();

            foreach (var housekeeper in housekeepers)
            {
                if (String.IsNullOrWhiteSpace(housekeeper.Email))
                {
                    continue;
                }

                var statementFilename =
                    _statementGenerator.SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate);

                if (string.IsNullOrWhiteSpace(statementFilename))
                {
                    continue;
                }

                var emailAddress = housekeeper.Email;
                var emailBody    = housekeeper.StatementEmailBody;

                try
                {
                    _emailSender.EmailFile(emailAddress, emailBody, statementFilename,
                                           string.Format("Sandpiper Statement {0:yyyy-MM} {1}", statementDate, housekeeper.FullName));
                }
                catch (Exception e)
                {
                    _messageBox.Show(e.Message, string.Format("Email failure: {0}", emailAddress),
                                     MessageBoxButtons.OK);
                }
            }
        }
Ejemplo n.º 2
0
        // This is a Command Function that is also returning something like a Query Function... (Majority is Action -> Command)
        // So here comes Unit as well as Interaction Tests...
        // But no need of return statement here, since it is only present at the last.
        // so, we change return type to void and remove the return statement... (so no state based tests here)
        public void SendStatementEmails(DateTime statementDate)   // We made this function non-static to ue Constructor Parameters Injection...
        {
            var housekeepers = _unitOfWork.Query <Housekeeper>(); // External Dependency 1 -> Unit Of Work

            // As all the housekeepers are got here, there's no sense of making another class for HouseKeeper...
            // So we make instance of UnitOfWork...
            foreach (var housekeeper in housekeepers)
            {
                if (String.IsNullOrWhiteSpace(housekeeper.Email))
                {
                    continue;
                }

                var statementFilename = _statementGenerator.SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate); // External Dependency 2

                if (string.IsNullOrWhiteSpace(statementFilename))
                {
                    continue;
                }

                var emailAddress = housekeeper.Email;
                var emailBody    = housekeeper.StatementEmailBody;

                try
                {
                    _emailSender.EmailFile(emailAddress, emailBody, statementFilename,
                                           string.Format("Sandpiper Statement {0:yyyy-MM} {1}", statementDate, housekeeper.FullName));// External Dependency 3
                }
                catch (Exception e)
                {
                    _messageBox.Show(e.Message, string.Format("Email failure: {0}", emailAddress),
                                     MessageBoxButtons.OK);// External Dependency 4 - WPF (here we simply make an interface since class already present)
                }
            }
        }
        // This function is more of Command type than Query type, hence we've to do Interaction testing here more than state based testing
        public void SendStatementEmails(DateTime statementDate)
        {
            // Returns List of Housekeeper objects from database
            var housekeepers = _unitOfWork.Query <Housekeeper>();

            foreach (var housekeeper in housekeepers)
            {
                // Earlier it was housekeeper.Email == null which was breaking our test case. So we catched the bug and changed the implementation
                if (string.IsNullOrWhiteSpace(housekeeper.Email))
                {
                    continue;
                }

                var statementFilename = _statementGenerator.SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate);

                if (string.IsNullOrWhiteSpace(statementFilename))
                {
                    continue;
                }

                var emailAddress = housekeeper.Email;
                var emailBody    = housekeeper.StatementEmailBody;

                try
                {
                    _emailSender.EmailFile(emailAddress, emailBody, statementFilename,
                                           string.Format("Sandpiper Statement {0:yyyy-MM} {1}", statementDate, housekeeper.FullName));
                }
                catch (Exception e)
                {
                    _messageBox.Show(e.Message, string.Format("Email failure: {0}", emailAddress),
                                     MessageBoxButtons.OK);
                }
            }
        }
        public void SendStatementEmails(DateTime statementDate)
        {
            foreach (var housekeeper in _houseKeeperRepository.GetHouseKeepers())
            {
                if (housekeeper.Email == null)
                {
                    continue;
                }
                var statementFilename = _statementGenerator.SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate);
                if (string.IsNullOrWhiteSpace(statementFilename))
                {
                    continue;
                }

                TrySendStatementEmail(statementDate, housekeeper, statementFilename);
            }
        }
Ejemplo n.º 5
0
        public static bool SendStatementEmails(IUnitOfWork unitOfWork, IStatementGenerator statementGenerator, IEmailer emailer, DateTime statementDate)
        {
            var housekeepers = unitOfWork.Query <Housekeeper>();

            if (housekeepers.Count() == 0)
            {
                return(false);
            }

            foreach (var housekeeper in housekeepers)
            {
                if (housekeeper.Email == null)
                {
                    continue;
                }

                var statementFilename = statementGenerator.SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate);

                if (string.IsNullOrWhiteSpace(statementFilename))
                {
                    continue;
                }

                var emailAddress = housekeeper.Email;
                var emailBody    = housekeeper.StatementEmailBody;

                try
                {
                    emailer.Email(emailAddress, emailBody, statementFilename,
                                  string.Format("Sandpiper Statement {0:yyyy-MM} {1}", statementDate, housekeeper.FullName));
                }
                catch (Exception e)
                {
                    XtraMessageBox.Show(e.Message, string.Format("Email failure: {0}", emailAddress),
                                        MessageBoxButtons.OK);
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        public bool SendStatementEmails(DateTime statementDate)
        {
            bool success      = true;
            var  housekeepers = _unitOfWork.Query <HouseKeeper>();

            foreach (var housekeeper in housekeepers)
            {
                if (string.IsNullOrWhiteSpace(housekeeper.Email))
                {
                    continue;
                }

                var statementFilename = _statementGenerator.SaveStatement(housekeeper.Oid, housekeeper.FullName, statementDate);

                if (string.IsNullOrWhiteSpace(statementFilename))
                {
                    continue;
                }

                var emailAddress = housekeeper.Email;
                var emailBody    = housekeeper.StatementEmailBody;

                try
                {
                    _emailSender.EmailFile(emailAddress, emailBody, statementFilename,
                                           string.Format("Sandpiper Statement {0:yyyy-MM} {1}", statementDate, housekeeper.FullName));
                }
                catch (Exception e)
                {
                    success = false;
                    break;
                }
            }

            return(success);
        }