Ejemplo n.º 1
0
        public void TestProcessSampleReturnRequestEmail()
        {
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var rule = new ReturnRequestEmailRule(_log, _time, emailService, actionService, _company, false, true);

            using (var db = _dbFactory.GetRWDb())
            {
                var email = db.Emails.Get(4687);

                var matchingResult = new EmailReadingResult()
                {
                    Email = new EmailDTO()
                    {
                        Subject = email.Subject,
                        Message = email.Message,
                    },
                    Status        = EmailMatchingResultStatus.New,
                    MatchedIdList = new string[] { "002-1602056-5981826" }
                };

                rule.Process(db, matchingResult);
            }
        }
Ejemplo n.º 2
0
        public void TestProcessSampleRemoveSignConfirmationEmail()
        {
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var emailProcessingService = new EmailProcessingService(
                _log,
                _dbFactory,
                emailService,
                actionService,
                _company,
                _time);

            var matchingResults = new List <EmailReadingResult>()
            {
                new EmailReadingResult()
                {
                    Email = new EmailDTO()
                    {
                        Message = "Remove signature confirmation",
                    },
                    MatchedIdList = new string[] { "701-3624993-3494603" }
                }
            };

            IList <IEmailRule> rules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(_log, _time),
                new AddMatchIdsEmailRule(_log, _time),
            };

            emailProcessingService.ProcessEmails(matchingResults, rules);
        }
Ejemplo n.º 3
0
        public void SendEmails()
        {
            var settings      = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var email         = new EmailService(_log, settings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            email.ProcessEmailActions(_dbFactory,
                                      _time,
                                      _company,
                                      actionService);
        }
Ejemplo n.º 4
0
        public void RecheckAllRefundEmails()
        {
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var rule = new RefundEmailRule(_log, _time, emailService, actionService, _company,
                                           enableSendEmail: false,
                                           existanceCheck: true);

            using (var db = _dbFactory.GetRWDb())
            {
                var fromDate = DateTime.Now.AddDays(-35);
                var emails   = db.Emails.GetAll()
                               .Where(e => e.CreateDate > fromDate &&
                                      e.Subject.Contains("Refund initiated for order"))
                               .ToList();
                var emailToOrderList = db.EmailToOrders.GetAll().ToList();

                foreach (var email in emails)
                {
                    var emailToOrder = emailToOrderList.FirstOrDefault(e => e.EmailId == email.Id);

                    if (emailToOrder == null)
                    {
                        continue;
                    }

                    var matchingResult = new EmailReadingResult()
                    {
                        Email = new EmailDTO()
                        {
                            Subject = email.Subject,
                            Message = email.Message,
                        },
                        Status        = EmailMatchingResultStatus.New,
                        MatchedIdList = new string[] { emailToOrder.OrderId }
                    };

                    rule.Process(db, matchingResult);
                }
            }
        }
Ejemplo n.º 5
0
        public void TestProcessOrderCancellationEmail(long emailId)
        {
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var emailProcessingService = new EmailProcessingService(
                _log,
                _dbFactory,
                emailService,
                actionService,
                _company,
                _time);

            using (var db = _dbFactory.GetRWDb())
            {
                var email = db.Emails.Get(emailId);

                var matchingResult = new EmailReadingResult()
                {
                    Email = new EmailDTO()
                    {
                        Subject = email.Subject,
                        Message = email.Message,
                    },
                    Status        = EmailMatchingResultStatus.New,
                    MatchedIdList = new string[] { "4442088617765" }
                };

                IList <IEmailRule> rules = new List <IEmailRule>()
                {
                    //new SetSystemTypesEmailRule(_log, _time),
                    //new AddMatchIdsEmailRule(_log, _time),
                    new CancellationEmailRule(_log, _time, emailService, actionService, _company),
                };

                emailProcessingService.ProcessEmails(new List <EmailReadingResult>()
                {
                    matchingResult
                }, rules);
            }
        }
Ejemplo n.º 6
0
        public void RecheckSetSystemTypeRule(long emailId)
        {
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

            var rule = new SetSystemTypesEmailRule(_log, _time);

            using (var db = _dbFactory.GetRWDb())
            {
                var fromDate = DateTime.Now.AddDays(-35);
                var emails   = db.Emails.GetAll()
                               .Where(e => e.Id == emailId)
                               .ToList();
                var emailToOrderList = db.EmailToOrders.GetAll().ToList();

                foreach (var email in emails)
                {
                    var emailToOrder = emailToOrderList.FirstOrDefault(e => e.EmailId == email.Id);

                    if (emailToOrder == null)
                    {
                        continue;
                    }

                    var matchingResult = new EmailReadingResult()
                    {
                        Email = new EmailDTO()
                        {
                            From    = email.From,
                            Subject = email.Subject,
                            Message = email.Message,
                        },
                        Status        = EmailMatchingResultStatus.New,
                        MatchedIdList = new string[] { emailToOrder.OrderId }
                    };

                    rule.Process(db, matchingResult);
                }
            }
        }
Ejemplo n.º 7
0
        public void TestSendEmails()
        {
            var settings = SettingsBuilder.GetSmtpSettingsFromAppSettings();
            var email    = new EmailService(_log, settings, _addressService);

            var actionServiceStub = new Mock <ISystemActionService>();

            actionServiceStub
            .Setup(l => l.GetUnprocessedByType(It.IsAny <IUnitOfWork>(), It.IsAny <SystemActionType>(), null, null))
            .Returns(new List <SystemActionDTO>()
            {
                new SystemActionDTO()
                {
                    InputData = SystemActionHelper.ToStr(new SendEmailInput()
                    {
                        OrderId   = "106-0610855-5158626",
                        EmailType = EmailTypes.NoticeLeft,
                        Args      = null
                    })
                }
            });
            actionServiceStub
            .Setup(l => l.SetResult(It.IsAny <IUnitOfWork>(),
                                    It.IsAny <long>(),
                                    It.IsAny <SystemActionStatus>(),
                                    It.IsAny <ISystemActionOutput>(),
                                    It.IsAny <string>())).Callback((IUnitOfWork db,
                                                                    long actionId,
                                                                    SystemActionStatus status,
                                                                    ISystemActionOutput output,
                                                                    string groupId) =>
            {
                Console.WriteLine(SystemActionHelper.ToStr(output));
            });

            email.ProcessEmailActions(_dbFactory,
                                      _time,
                                      _company,
                                      actionServiceStub.Object);
        }