Example #1
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);
        }
Example #2
0
        public void ReadInboxEmails()
        {
            var imapSettings  = SettingsBuilder.GetImapSettingsFromCompany(_company);
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

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

            IList <IEmailRule> inboxRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(_log, _time),
                new AddMatchIdsEmailRule(_log, _time),
                new SetAnswerIdEmailRule(_log, _time), //NOTE: also using in Inbox for processing Amazon autocommunicate emails
                //new FeedbackBlackListEmailRule(_log, _time),
                new ReturnRequestEmailRule(_log, _time, emailService, actionService, _company, true, false),
                new OrderDeliveryInquiryEmailRule(_log, _time, emailService, actionService),
                new AddressNotChangedEmailRule(_log, _time, emailService, actionService),
                //new DhlInvoiceEmailRule(_log, _time, _dbFactory),
                //new AddCommentEmailRule(_log, actionService, _time),
                new PrepareBodyEmailRule(_log, _time),
            };

            var email = new EmailReaderService(imapSettings, _log, _dbFactory, _time);

            email.ReadEmails(EmailHelper.InboxFolder, DateTime.Now.AddDays(-5), imapSettings.AcceptingToAddresses, null, null);
            emailProcessing.ProcessEmails(email.EmailProcessResultList, inboxRules);
        }
Example #3
0
        public void ReadSentEmails()
        {
            var imapSettings  = SettingsBuilder.GetImapSettingsFromCompany(_company);
            var smtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
            var emailService  = new EmailService(_log, smtpSettings, _addressService);
            var actionService = new SystemActionService(_log, _time);

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

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

            var email = new EmailReaderService(imapSettings, _log, _dbFactory, _time);

            email.ReadEmails(EmailHelper.SentFolder, DateTime.Now.AddDays(-15), null, imapSettings.AcceptingToAddresses, null);
            emailProcessing.ProcessEmails(email.EmailProcessResultList, sentRules);
        }
Example #4
0
        public async Task ProcessEmailUpdateShouldReturnFalseWhenInvalidNameIsPassed()
        {
            var options = new DbContextOptionsBuilder <TBIContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            var userStore   = new Mock <IUserStore <User> >();
            var userManager = new Mock <UserManager <User> >(userStore.Object, null, null, null, null, null, null, null, null);

            var encrypter    = new Mock <IEncrypter>();
            var validator    = new Mock <IValidator>();
            var emailService = new Mock <IEmailService>().Object;

            var date  = DateTime.Now;
            var email = new Application
            {
                Id                = 1,
                Received          = date,
                Email             = "*****@*****.**",
                ApplicationStatus = ApplicationStatus.Open,
                Body              = "test text",
                OperatorId        = "1",
                LastChange        = date
            };
            var updateParameters = new EmailUpdateModel
            {
                EmailId            = 1,
                LoggedUserUsername = "******",
                Amount             = 23,
                NewStatus          = "Accepted",
                EGN         = "1111111111",
                PhoneNumber = "0876281932",
                FullName    = "Ivan Petrov3123"
            };

            var user = new User {
                Id = "1", UserName = "******"
            };

            userManager.Setup(g => g.FindByNameAsync("testUser")).Returns(Task.FromResult(user));
            userManager.Setup(g => g.IsInRoleAsync(user, "Operator")).Returns(Task.FromResult(true));

            validator.Setup(d => d.ValidateEGN("1111111111")).Returns(Task.FromResult(true));
            validator.Setup(d => d.ValidatePhone("0876281932")).Returns(Task.FromResult(true));

            validator.Setup(d => d.ValidateName("Ivan Petrov3123")).Returns(Task.FromResult(false));

            using (var arrangeContex = new TBIContext(options))
            {
                arrangeContex.Applications.Add(email);
                await arrangeContex.SaveChangesAsync();
            }
            using (var assertContext = new TBIContext(options))
            {
                var sut             = new EmailProcessingService(assertContext, encrypter.Object, userManager.Object, validator.Object, emailService);
                var executionResult = await sut.ProcessEmailUpdate(updateParameters);

                Assert.AreEqual(false, executionResult);
            }
        }
Example #5
0
        public async Task GetEmailFullInfoReturnsInfo()
        {
            var options = new DbContextOptionsBuilder <TBIContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            var userStore   = new Mock <IUserStore <User> >();
            var userManager = new Mock <UserManager <User> >(userStore.Object, null, null, null, null, null, null, null, null);

            var encrypter    = new Mock <IEncrypter>();
            var validator    = new Mock <IValidator>();
            var emailService = new Mock <IEmailService>().Object;

            var date  = DateTime.Now;
            var email = new Application
            {
                Id                = 1,
                Received          = date,
                Email             = "*****@*****.**",
                ApplicationStatus = ApplicationStatus.NotReviewed,
                Body              = "test text",
                OperatorId        = "1",
                LastChange        = date
            };

            var user = new User {
                Id = "1", UserName = "******"
            };

            userManager.Setup(g => g.FindByNameAsync("testUser")).Returns(Task.FromResult(user));
            userManager.Setup(g => g.IsInRoleAsync(user, "Manager")).Returns(Task.FromResult(true));

            encrypter.Setup(d => d.Decrypt("*****@*****.**")).Returns("*****@*****.**");
            encrypter.Setup(d => d.Decrypt("test text")).Returns("test text");

            using (var arrangeContex = new TBIContext(options))
            {
                arrangeContex.Applications.Add(email);
                await arrangeContex.SaveChangesAsync();
            }
            using (var assertContext = new TBIContext(options))
            {
                var sut             = new EmailProcessingService(assertContext, encrypter.Object, userManager.Object, validator.Object, emailService);
                var executionResult = await sut.GetEmailFullInfo(1, "testUser");

                Assert.AreEqual(1, executionResult.EmailId);
                Assert.AreEqual(date, executionResult.Emailreceived);
                Assert.AreEqual("*****@*****.**", executionResult.EmailSender);
                Assert.AreEqual("NotReviewed", executionResult.EmailStatus.ToString());
                Assert.AreEqual("test text", executionResult.Body);
                Assert.AreEqual("1", executionResult.OperatorId);
                Assert.AreEqual(2, executionResult.PermitedOperations.Count);
                Assert.AreEqual(true, executionResult.AllowedToWork);
                Assert.AreEqual(date.Ticks.ToString(), executionResult.CurrentDataStamp);
            }
        }
Example #6
0
        public async Task Service_Get_ReservationResourceModel()
        {
            // Arrange
            string text = FakeDataHelper.EmailProcessing.CorrectReservationTextblock;

            // Act
            ReservationResourceModel model = await EmailProcessingService.ExtractReservationAsync(text);

            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual("Viaduct Steakhouse", model.Vendor);
            Assert.AreEqual("development team’s project end celebration dinner", model.Description);
            Assert.AreEqual(DateTime.Parse("Thursday 27 April 2017"), model.Date);
        }
Example #7
0
        public async Task Service_Get_ExpenseResourceModel()
        {
            // Arrange
            string text = FakeDataHelper.EmailProcessing.CorrectExpenseTextBlock;

            // Act
            ExpenseResourceModel model = await EmailProcessingService.ExtractExpenseAsync(text);


            // Assert
            Assert.IsNotNull(model);
            Assert.AreEqual("DEV002", model.CostCentre);
            Assert.AreEqual(1024.01m, model.Total);
            Assert.AreEqual(890.44m, model.TotalExcludingGST);
            Assert.AreEqual(133.57m, model.GSTValue);
            Assert.AreEqual("personal card", model.PaymentMethod);
        }
Example #8
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);
            }
        }
Example #9
0
        public async Task ValidateEmailTimeStampShouldReturnFalse()
        {
            var options = new DbContextOptionsBuilder <TBIContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            var userStore   = new Mock <IUserStore <User> >();
            var userManager = new Mock <UserManager <User> >(userStore.Object, null, null, null, null, null, null, null, null);

            var encrypter    = new Mock <IEncrypter>();
            var validator    = new Mock <IValidator>();
            var emailService = new Mock <IEmailService>().Object;

            var date  = DateTime.Now;
            var email = new Application
            {
                Id                = 1,
                Received          = date,
                Email             = "*****@*****.**",
                ApplicationStatus = ApplicationStatus.NotReviewed,
                Body              = "test text",
                OperatorId        = "1",
                LastChange        = date
            };


            using (var arrangeContex = new TBIContext(options))
            {
                arrangeContex.Applications.Add(email);
                await arrangeContex.SaveChangesAsync();
            }
            using (var assertContext = new TBIContext(options))
            {
                var sut             = new EmailProcessingService(assertContext, encrypter.Object, userManager.Object, validator.Object, emailService);
                var executionResult = await sut.ValidateEmailTimeStamp(1, "1");

                Assert.AreEqual(false, executionResult);
            }
        }
        protected override void RunCallback()
        {
            CompanyDTO company   = null;
            var        dbFactory = new DbFactory();
            var        log       = GetLogger();

            using (var db = dbFactory.GetRDb())
            {
                company = db.Companies.GetByIdWithSettingsAsDto(CompanyId);
            }
            var time              = new TimeService(dbFactory);
            var addressService    = AddressService.Default;
            var emailImapSettings = SettingsBuilder.GetImapSettingsFromCompany(company,
                                                                               Int32.Parse(AppSettings.Support_MaxProcessMessageErrorsCount),
                                                                               Int32.Parse(AppSettings.Support_ProcessMessageThreadTimeoutSecond));
            var emailSmtpSettings  = SettingsBuilder.GetSmtpSettingsFromCompany(company, AppSettings.IsDebug, AppSettings.IsSampleLabels);
            var emailReaderService = new EmailReaderService(
                emailImapSettings,
                GetLogger(),
                dbFactory,
                time);
            var emailService  = new EmailService(log, emailSmtpSettings, addressService);
            var systemActions = new SystemActionService(log, time);


            var emailProcessingService = new EmailProcessingService(
                log,
                dbFactory,
                emailService,
                systemActions,
                company,
                time);

            //Inbox Folder
            emailReaderService.ReadEmails(EmailHelper.InboxFolder, null, emailImapSettings.AcceptingToAddresses, null, CancellationToken);
            IList <IEmailRule> inboxRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(log, time),
                new AddMatchIdsEmailRule(log, time),
                new SetAnswerIdEmailRule(log, time), //NOTE: also using in Inbox for processing Amazon autocommunicate emails
                new CancellationEmailRule(log, time, emailService, systemActions, company),
                new RemoveSignatureEmailRule(log, time, emailService, systemActions),
                new FeedbackBlackListEmailRule(log, time),
                new ReturnRequestEmailRule(log, time, emailService, systemActions, company, true, false),
                new OrderDeliveryInquiryEmailRule(log, time, emailService, systemActions),
                new AddressNotChangedEmailRule(log, time, emailService, systemActions),
                new DhlInvoiceEmailRule(log, time, dbFactory),
                new AddCommentEmailRule(log, systemActions, time),
                new PrepareBodyEmailRule(log, time),
            };

            emailProcessingService.ProcessEmails(emailReaderService.EmailProcessResultList, inboxRules);

            //Sent Folder
            emailReaderService.ReadEmails(EmailHelper.SentFolder, null, null, emailImapSettings.AcceptingToAddresses, CancellationToken);
            IList <IEmailRule> sentRules = new List <IEmailRule>()
            {
                new SetSystemTypesEmailRule(log, time),
                new AddMatchIdsEmailRule(log, time),
                new SetAnswerIdEmailRule(log, time),
                new SetSentByEmailRule(log, time)
            };

            emailProcessingService.ProcessEmails(emailReaderService.EmailProcessResultList, sentRules);

            //Update Settings
            var settingService = new SettingsService(dbFactory);

            using (var db = dbFactory.GetRWDb())
            {
                settingService.SetUnansweredMessageCount(db.Emails.GetUnansweredEmailCount());
            }
        }
 public void Init()
 {
     EmailProcessingService    = new EmailProcessingService();
     EmailProcessingController = new EmailProcessingController(EmailProcessingService);
 }