public void DeleteDirectories() { TestHelper.RecreateDirectories(); ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); filter = new EventFilter <WaybillService>(); }
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 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 DeleteDirectories() { SetDefaultValues(); _info = null; TestHelper.RecreateDirectories(); ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, ImapHelper.INBOXFolder, _responseSubject); }
public void Setup() { client = TestClient.Create(2, 2); address = client.Addresses[0]; source.SourceType = PriceSourceType.Email; source.Save(); ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); }
public void CreateDirectoryPath() { CreateDownHandlerPath(); ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, Settings.Default.IMAPSourceFolder); DownHistoryPath = Settings.Default.HistoryPath; if (!Directory.Exists(DownHistoryPath)) { Directory.CreateDirectory(DownHistoryPath); } }
public void Parse_waybill_if_parsing_enabled() { client = TestClient.CreateNaked(session); supplier = TestSupplier.CreateNaked(session); var beign = DateTime.Now; //Удаляем миллисекунды из даты, т.к. они не сохраняются в базе данных beign = beign.AddMilliseconds(-beign.Millisecond); var email = String.Format("edata{0}@msk.katren.ru", supplier.Id); supplier.WaybillSource.EMailFrom = email; supplier.WaybillSource.SourceType = TestWaybillSourceType.Email; session.Save(supplier); session.Save(client); ImapHelper.ClearImapFolder(); ImapHelper.StoreMessageWithAttachToImapFolder( String.Format("{0}@waybills.analit.net", client.Addresses[0].Id), email, @"..\..\Data\Waybills\8916.dbf"); Process(); var files = GetFileForAddress(DocType.Waybill); Assert.That(files.Length, Is.EqualTo(1)); var logs = session.Query <TestDocumentLog>().Where(d => d.Client.Id == client.Id).ToList(); Assert.That(logs.Count, Is.EqualTo(1)); var log = logs.Single(); var logTime = log.LogTime; Assert.That(logTime.Date.AddHours(logTime.Hour).AddMinutes(logTime.Minute).AddSeconds(logTime.Second), Is.GreaterThanOrEqualTo(beign.Date.AddHours(beign.Hour).AddMinutes(beign.Minute).AddSeconds(beign.Second))); Assert.That(log.DocumentSize, Is.GreaterThan(0)); var documents = session.Query <Document>().Where(d => d.Log.Id == log.Id).ToList(); Assert.That(documents.Count, Is.EqualTo(1)); Assert.That(documents.Single().Lines.Count, Is.EqualTo(7)); }
public void Parse_reject() { client = TestClient.CreateNaked(session); supplier = TestSupplier.CreateNaked(session); var price = supplier.Prices[0]; var productSynonym = price.AddProductSynonym("юниэнзим с МПС таб п/о N20", session.Query <TestProduct>().First()); var producerSynonym = price.AddProducerSynonym("юникем Лабора", session.Query <TestProducer>().First()); var email = String.Format("edata{0}@msk.katren.ru", supplier.Id); supplier.WaybillSource.EMailFrom = email; supplier.WaybillSource.SourceType = TestWaybillSourceType.Email; supplier.RejectParser = "NadezhdaFarm7579RejectParser"; session.Save(supplier); session.Save(client); ImapHelper.ClearImapFolder(); ImapHelper.StoreMessageWithAttachToImapFolder( String.Format("{0}@refused.analit.net", client.Addresses[0].Id), email, @"..\..\Data\Rejects\35115498_Надежда-Фарм Орел_Фарма Орел(protocol).txt"); Process(); var files = GetFileForAddress(DocType.Reject); Assert.That(files.Length, Is.EqualTo(1)); var logs = session.Query <TestDocumentLog>().Where(d => d.Client.Id == client.Id).ToList(); Assert.That(logs.Count, Is.EqualTo(1)); var log = logs.Single(); Assert.That(log.DocumentSize, Is.GreaterThan(0)); Assert.AreEqual(DocumentType.Reject, log.DocumentType); var reject = session.Query <RejectHeader>().FirstOrDefault(r => r.Supplier.Id == supplier.Id); Assert.AreEqual(1, reject.Lines.Count); Assert.AreEqual("NadezhdaFarm7579RejectParser", reject.Parser); Assert.AreEqual(productSynonym.Product.Id, reject.Lines[0].ProductEntity.Id); Assert.AreEqual(producerSynonym.Producer.Id, reject.Lines[0].ProducerEntity.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 DeleteResponeLetters() { ImapHelper.ClearImapFolder(Settings.Default.TestIMAPUser, Settings.Default.TestIMAPPass, ImapHelper.INBOXFolder, _responseSubject); }
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)); }