public void Process_message_if_from_contains_more_than_one_address() { client = TestClient.CreateNaked(session); address = client.Addresses[0]; supplier = TestSupplier.CreateNaked(session); supplier.WaybillSource.EMailFrom = String.Format("edata{0}@msk.katren.ru", supplier.Id); supplier.WaybillSource.SourceType = TestWaybillSourceType.Email; session.Save(supplier); FileHelper.DeleteDir(Settings.Default.DocumentPath); ImapHelper.ClearImapFolder(); var mime = PatchTo(@"..\..\Data\Unparse.eml", String.Format("{0}@waybills.analit.net", address.Id), String.Format("edata{0}@msk.katren.ru,[email protected]", supplier.Id)); ImapHelper.StoreMessage(mime.ToByteData()); Process(); var files = GetFileForAddress(DocType.Waybill); Assert.That(files.Length, Is.EqualTo(1), "не обработали документ"); }
public void SetUp(IList <string> fileNames) { client = TestClient.CreateNaked(session); supplier = TestSupplier.CreateNaked(session); var from = String.Format("{0}@test.test", client.Id); PrepareSupplier(supplier, from); byte[] bytes; if (IsEmlFile) { bytes = File.ReadAllBytes(fileNames[0]); } else { var message = ImapHelper.BuildMessageWithAttachments( String.Format("{0}@waybills.analit.net", client.Addresses[0].Id), from, fileNames.ToArray()); bytes = message.ToByteData(); } ImapHelper.StoreMessage( Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder, bytes); }
public void Ignore_document_for_wrong_address() { var begin = DateTime.Now; var supplier = TestSupplier.CreateNaked(session); var from = String.Format("{0}@test.test", supplier.Id); PrepareSupplier(supplier, from); var message = ImapHelper.BuildMessageWithAttachments( String.Format("{0}@waybills.analit.net", "1"), from, new[] { @"..\..\Data\Waybills\bi055540.DBF" }); var bytes = message.ToByteData(); ImapHelper.StoreMessage( Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder, bytes); this.supplier = supplier; Process(); var docs = session.Query <TestDocumentLog>().Where(d => d.LogTime > begin).ToList(); Assert.That(docs.Count, Is.EqualTo(0)); }
public void ProcessReaderException() { ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); ImapHelper.StoreMessage(@"..\..\Data\Unparse.eml"); var imapReader = MockRepository.GenerateStub <IIMAPReader>(); imapReader.Stub(s => s.IMAPAuth(null)) .IgnoreArguments() .Do(new Action <IMAP_Client>(client => client.Authenticate(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass))); var exception = new Exception("ошибка при разборе письма в reader'е"); imapReader.Stub(s => s.ProcessMime(null)) .IgnoreArguments() .Do(new Action <Mime>(mime => { throw exception; })); var handler = new IMAPHandler(imapReader); handler.ProcessIMAPFolder(); imapReader.AssertWasCalled(r => r.IMAPAuth(Arg <IMAP_Client> .Is.Anything)); imapReader.AssertWasCalled(r => r.PingReader()); imapReader.AssertWasCalled(r => r.ProcessMime(Arg <Mime> .Is.Anything)); imapReader.AssertWasNotCalled(r => r.ProcessBrokenMessage(Arg <IMAP_FetchItem> .Is.Anything, Arg <IMAP_FetchItem[]> .Is.Anything, Arg <Exception> .Is.Equal(exception))); var existsMessages = ImapHelper.CheckImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); Assert.That(existsMessages.Count, Is.EqualTo(1), "Письмо было удалено сразу же после возникнования ошибок"); }
public void MessageClientCheckWithExtensionExceptions() { SetSupplierAndClientConnection(); //проверка на отсутствие документов до запуска обработчика var currentDocuments = session.Query <Document>().Where(s => s.Invoice.RecipientId == recipientId); Assert.IsTrue(!currentDocuments.Any()); //новая накладная var document = GetDocument(recipientId); //прикрепление накладной к письму var msData = GetMemoryStreamForDocument(document); var message = BuildMessageWithAttachments($"to_{supplier.Id}@sup.com", $"from_{supplier.Id}@sup.com", "text.sst", msData.ToArray()); if (!session.Transaction.IsActive) { session.BeginTransaction(); } session.Transaction.Commit(); session.BeginTransaction(); var waybillExcludeFileToRemove = session.Query <WaybillExcludeFile>().ToList(); session.DeleteEach(waybillExcludeFileToRemove); session.Connection.Query( $"INSERT INTO usersettings.WaybillExcludeFile (Supplier,Mask) Values({supplier.Id} , '{"*.sst"}')") .FirstOrDefault(); ImapHelper.StoreMessage( Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder, message.ToByteData()); //запуск обработчика session.Transaction.Commit(); #if DEBUG handler.SetSessionForTest(session); #endif handler.ProcessData(); session.Flush(); //проверка на наличие документов после запуска обработчика currentDocuments = session.Query <Document>().Where(s => s.Invoice.RecipientId == recipientId); //документ отсутствует var currentDocument = currentDocuments.FirstOrDefault(); Assert.IsTrue(currentDocument == null); var logs = session.Query <DocumentReceiveLog>().Where(s => s.ClientCode == client.Id && s.Supplier.Id == supplier.Id).ToList(); Assert.IsTrue(logs.All(s => s.Comment.IndexOf($"Разбор документа не производился, применена маска исключения '{"*.sst"}'.") != -1)); }
public void Process_price_in_message() { var file = @"..\..\Data\EmailSourceHandlerTest\Price_ProgTechnologi.eml"; source.EmailTo = "*****@*****.**"; source.EmailFrom = "*****@*****.**"; source.PriceMask = "*.*"; source.ExtrMask = "*.*"; source.Save(); ImapHelper.StoreMessage( Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder, File.ReadAllBytes(file)); handler.ProcessData(); }
public void MiniMailOnUnknownProvider() { var files = new List <string> { @"..\..\Data\Waybills\bi055540.DBF", }; //SetUp без регистрации тестовой почты --begin-- client = TestClient.CreateNaked(session); supplier = TestSupplier.CreateNaked(session); var from = String.Format("{0}@test.test", client.Id); session.Save(supplier); byte[] bytes; if (IsEmlFile) { bytes = File.ReadAllBytes(files[0]); } else { var message = ImapHelper.BuildMessageWithAttachments( String.Format("{0}@waybills.analit.net", client.Addresses[0].Id), from, files.ToArray()); bytes = message.ToByteData(); } ImapHelper.StoreMessage( Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder, bytes); //--EndSetUp-- Process(); var logs = session.Query <RejectedEmail>().Where(log => log.From == from); Assert.That(logs.Count(), Is.Not.Null); }
public void MessageClientCheck() { SetSupplierAndClientConnection(); //проверка на отсутствие документов до запуска обработчика var currentDocuments = session.Query <Document>().Where(s => s.Invoice.RecipientId == recipientId); Assert.IsTrue(!currentDocuments.Any()); //новая накладная var document = GetDocument(recipientId); //прикрепление накладной к письму var msData = GetMemoryStreamForDocument(document); var message = BuildMessageWithAttachments($"to_{supplier.Id}@sup.com", $"from_{supplier.Id}@sup.com", "text.sst", msData.ToArray()); ImapHelper.StoreMessage( Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder, message.ToByteData()); //запуск обработчика session.Transaction.Commit(); #if DEBUG handler.SetSessionForTest(session); #endif handler.ProcessData(); session.Flush(); //проверка на наличие документов после запуска обработчика currentDocuments = session.Query <Document>().Where(s => s.Invoice.RecipientId == recipientId); //документ был один var currentDocument = currentDocuments.FirstOrDefault(); Assert.IsTrue(currentDocuments.Count() == 1); //проверки соответствия полей Assert.IsTrue(currentDocument.Address.Id == aIntersection.Address.Id); Assert.IsTrue(currentDocument.ClientCode == client.Id); Assert.IsTrue(currentDocument.FirmCode == supplier.Id); }
public void SimpleProcessImap() { ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); ImapHelper.StoreMessage(@"..\..\Data\Unparse.eml"); var imapReader = MockRepository.GenerateStub <IIMAPReader>(); imapReader.Stub(s => s.IMAPAuth(null)) .IgnoreArguments() .Do(new Action <IMAP_Client>(client => client.Authenticate(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass))); var handler = new IMAPHandler(imapReader); handler.ProcessIMAPFolder(); imapReader.AssertWasCalled(r => r.IMAPAuth(Arg <IMAP_Client> .Is.Anything)); imapReader.AssertWasCalled(r => r.PingReader()); imapReader.AssertWasCalled(r => r.ProcessMime(Arg <Mime> .Is.Anything)); imapReader.AssertWasNotCalled(r => r.ProcessBrokenMessage(Arg <IMAP_FetchItem> .Is.Anything, Arg <IMAP_FetchItem[]> .Is.Anything, Arg <Exception> .Is.Anything)); var existsMessages = ImapHelper.CheckImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); Assert.That(existsMessages.Count, Is.EqualTo(0), "Существуют письма в IMAP-папками с темами: {0}", existsMessages.Select(m => m.Envelope.Subject).Implode()); }
public void ProcessMessageWithTimeoutOnError() { ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); ImapHelper.StoreMessage(@"..\..\Data\Unparse.eml"); var imapReader = MockRepository.GenerateStub <IIMAPReader>(); imapReader.Stub(s => s.IMAPAuth(null)) .IgnoreArguments() .Do(new Action <IMAP_Client>(client => client.Authenticate(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass))); var exception = new Exception("ошибка при разборе письма в reader'е"); imapReader.Stub(s => s.ProcessMime(null)) .IgnoreArguments() .Do(new Action <Mime>(mime => { throw exception; })); var handler = new IMAPHandler(imapReader); //Обрабатываем письмо первый раз: оно должно попасть в ErrorInfos Assert.That(handler.ErrorInfos.Count, Is.EqualTo(0)); handler.ProcessIMAPFolder(); imapReader.AssertWasCalled(r => r.IMAPAuth(Arg <IMAP_Client> .Is.Anything)); imapReader.AssertWasCalled(r => r.PingReader()); imapReader.AssertWasCalled(r => r.ProcessMime(Arg <Mime> .Is.Anything)); imapReader.AssertWasNotCalled(r => r.ProcessBrokenMessage(Arg <IMAP_FetchItem> .Is.Anything, Arg <IMAP_FetchItem[]> .Is.Anything, Arg <Exception> .Is.Equal(exception))); var existsMessages = ImapHelper.CheckImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); Assert.That(existsMessages.Count, Is.EqualTo(1), "Письмо было удалено"); Assert.That(handler.ErrorInfos.Count, Is.EqualTo(1)); //Обрабатываем письмо второй раз: оно не должно быть обработано handler.ProcessIMAPFolder(); imapReader.AssertWasCalled(r => r.ProcessMime(Arg <Mime> .Is.Anything), options => options.Repeat.Times(2)); imapReader.AssertWasNotCalled(r => r.ProcessBrokenMessage(Arg <IMAP_FetchItem> .Is.Anything, Arg <IMAP_FetchItem[]> .Is.Anything, Arg <Exception> .Is.Equal(exception))); existsMessages = ImapHelper.CheckImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); Assert.That(existsMessages.Count, Is.EqualTo(1), "Письмо было удалено"); Assert.That(handler.ErrorInfos.Count, Is.EqualTo(1)); //Подменяем информацию о письме, чтобы сработал таймаут и в третий раз обрабатываем письмо: оно должно обработаться var realInfo = handler.ErrorInfos[0]; var info = MockRepository.GenerateMock <UIDInfoForTesting>(); info.Stub(i => i.UID).Return(realInfo.UID); info.Stub(i => i.CreateTime).Return(DateTime.Now.AddMinutes(-(Settings.Default.UIDProcessTimeout + 1))); handler.ErrorInfos.Clear(); handler.ErrorInfos.Add(info); handler.ProcessIMAPFolder(); imapReader.AssertWasCalled(r => r.ProcessMime(Arg <Mime> .Is.Anything), options => options.Repeat.Times(3)); imapReader.AssertWasCalled(r => r.ProcessBrokenMessage(Arg <IMAP_FetchItem> .Is.Anything, Arg <IMAP_FetchItem[]> .Is.Anything, Arg <Exception> .Is.Equal(exception))); existsMessages = ImapHelper.CheckImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); Assert.That(existsMessages.Count, Is.EqualTo(0), "Существуют письма в IMAP-папками с темами: {0}", existsMessages.Select(m => m.Envelope.Subject).Implode()); Assert.That(handler.ErrorInfos.Count, Is.EqualTo(0)); }