Exemplo n.º 1
0
        public void GetSpecialParserTest()
        {
            var documentLog = new DocumentReceiveLog {
                Supplier = new Supplier {
                    Id = 1
                },
            };
            var detector = new WaybillFormatDetectorFake();

            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake1));

            var type = detector.GetSpecialParser(@"..\..\Data\Waybills\KZ000130.dbf", documentLog);

            Assert.That(type.FullName.Contains("ParserFake1"), Is.True);

            detector = new WaybillFormatDetectorFake();

            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake2));
            type = detector.GetSpecialParser(@"..\..\Data\Waybills\KZ000130.dbf", documentLog);
            Assert.That(type, Is.Null);

            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake1));
            type = detector.GetSpecialParser(@"..\..\Data\Waybills\KZ000130.txt", documentLog);
            Assert.That(type, Is.Null);

            detector = new WaybillFormatDetectorFake();
            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake3));
            bool fail = false;

            try {
                detector.GetSpecialParser(@"..\..\Data\Waybills\KZ000130.dbf", documentLog);
            }
            catch (Exception e) {
                fail = e.Message.Contains("реализуй метод CheckFileFormat");
            }
            Assert.That(fail, Is.True);

            detector = new WaybillFormatDetectorFake();
            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake2));
            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake1));
            type = detector.GetSpecialParser(@"..\..\Data\Waybills\KZ000130.dbf", documentLog);
            Assert.That(type.FullName.Contains("ParserFake1"), Is.True);

            detector = new WaybillFormatDetectorFake();

            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake5));
            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake7));
            detector.AddSpecParser(documentLog.Supplier.Id, typeof(ParserFake6));
            type = detector.GetSpecialParser(@"..\..\Data\Waybills\KZ000130.dbf", documentLog);
            Assert.That(type.FullName.Contains("ParserFake6"), Is.True);
        }
Exemplo n.º 2
0
        public void ComparisonWithOrdersTestIfOrderIdInDocumentLineTest()
        {
            order1 = BuildOrder();
            order1.Items.Add(new OrderItem {
                Code = "Code1", Order = order1, Quantity = 20
            });
            order1.Items.Add(new OrderItem {
                Code = "Code2", Order = order1, Quantity = 25
            });
            order1.Items.Add(new OrderItem {
                Code = "Code3", Order = order1, Quantity = 50
            });
            order1.Items.Add(new OrderItem {
                Code = "Code4", Order = order1, Quantity = 100
            });
            session.Save(order1);

            order2 = BuildOrder();
            order2.Items.Add(new OrderItem {
                Code = "Code3", Order = order2, Quantity = 15
            });
            order2.Items.Add(new OrderItem {
                Code = "Code3", Order = order2, Quantity = 10
            });
            order2.Items.Add(new OrderItem {
                Code = "Code5", Order = order2, Quantity = 15
            });
            session.Save(order2);

            log = new DocumentReceiveLog {
                Supplier = appSupplier, ClientCode = client.Id, Address = address, MessageUid = 123, DocumentSize = 100
            };
            var document = new Document(log)
            {
                OrderId = order1.Id, DocumentDate = DateTime.Now
            };

            var docline = new DocumentLine {
                Document = document, Code = "Code1", Quantity = 20, OrderId = order1.Id
            };

            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code2", Quantity = 15, OrderId = order1.Id
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code2", Quantity = 5, OrderId = order2.Id
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code3", Quantity = 50, OrderId = order1.Id
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code3", Quantity = 25, OrderId = order2.Id
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = null, Quantity = 75
            };
            document.NewLine(docline);
            docline = new DocumentLine {
                Document = document, Code = "Code5", Quantity = 10, OrderId = order2.Id
            };
            document.NewLine(docline);
            session.Save(log);
            session.Save(document);
            session.Flush();

            order1 = session.Load <OrderHead>(order1.Id);
            order2 = session.Load <OrderHead>(order2.Id);
            orders.Add(order1);
            orders.Add(order2);

            Match(document);
            session.Save(document);

            var line = document.Lines[0];

            Assert.That(document.Lines[0].OrderItems, Is.EquivalentTo(new[] { order1.Items[0] }));

            line = document.Lines[1];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order1.Items[1] }));

            line = document.Lines[2];
            Assert.That(line.OrderItems, Is.Empty);

            line = document.Lines[3];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order1.Items[2] }));

            line = document.Lines[4];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order2.Items[0], order2.Items[1] }));

            line = document.Lines[5];
            Assert.That(line.OrderItems, Is.Empty);

            line = document.Lines[6];
            Assert.That(line.OrderItems, Is.EquivalentTo(new[] { order2.Items[2] }));

            TestHelper.Execute(String.Format("delete from documents.waybillorders where DocumentLineId in ({0});", document.Lines.Implode(l => l.Id)));

            var detector = new WaybillFormatDetectorFake(document);             // проверяем вызов функции ComparisonWithOrders из детектора

            detector.Parse(session, null, log);
            document.SaveAndFlush();

            var table = GetMatches(document);
            var rows  = table.Rows;

            Assert.That(rows.Count, Is.GreaterThan(0), "для документа {0} не нашли сопоставленную позицию", document.Id);
            Assert.That(rows[0]["DocumentLineId"], Is.EqualTo(document.Lines[0].Id));
            Assert.That(rows[0]["OrderLineId"], Is.EqualTo(order1.Items[0].Id));
        }