public void oWorker_DoWork(object sender, DoWorkEventArgs e) { Login login = new Login(Settings.Default.LocationOfExchangeServer); login.ShowDialog(); BodyType type = new BodyType(); type.BodyType1 = (BodyTypeType)Enum.Parse(typeof(BodyTypeType), Settings.Default.BodyType); var surgeries = new KeyedEmailAddressRepository(Settings.Default.KeyEmailFilePath).GetAll(); var data = new KeyedDataRepository(_form.KeyedDataFilePath).GetAll(); IEnumerable<DataEmailAddressGroup> _mailerInfo = DataEmailAddressGroup.CreateGroups(surgeries, data); int emailsSent = 0; int totalEmailsToSend = _mailerInfo.SelectMany(recipient => recipient.EmailAddresses).Count(); foreach (DataEmailAddressGroup mailInfo in _mailerInfo) { var attachmentPath = CsvWriter.WriteFile(mailInfo.Data); foreach (var addressee in mailInfo.EmailAddresses) { login.Send.DetailsWithAttachment(new ModelEmailDetails { SubjectOfEmail = string.Format("{0} for {1}", _form.TextBoxSubject, addressee.Key), BodyOfEmail = _form.TextBoxBody, SenderEmail = _form.TextBoxSender, RecepientEmail = addressee.EmailAddress, //AttachmentLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), // @"GitHub\NhsCommissioningMailer\CommissioningMailer\SampleData\") + "KeyEmailAddressPair.csv", AttachmentLocation = attachmentPath.FullName, BodyType = type, ContentType = Settings.Default.ContentType }); double percentage = ((double)emailsSent / totalEmailsToSend) * 100; _oWorker.ReportProgress(Convert.ToInt32(percentage)); emailsSent++; if (_oWorker.CancellationPending) { e.Cancel = true; _oWorker.ReportProgress(0); return; } } } OWorker.ReportProgress(100); }
public void GetAll_Returns_All_KeyedData() { var keyedDatas = new KeyedDataRepository(SampleData.SusExtractForSurgeriesPath).GetAll(); Assert.That(keyedDatas.Count(), Is.EqualTo(693)); }