public void WithNullArrayTest() { var model = new DocumentWithArray { Array = null, NonArray = "StringValue" }; var stringTemplate = new[] { new[] { "", "Template:RootTemplate:A2:D4", "", "" }, new[] { "", "Адреса:", "Имена:", "" }, new[] { "", "Value::Array[].Address", "Value::Array[].Name", "" }, new[] { "Value::NonArray", "", "", "" } }; var template = FakeTable.GenerateFromStringArray(stringTemplate); var target = new FakeTable(100, 100); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger)); var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); templateEngine.Render(tableBuilder, model); target.GetCell(new CellPosition("C2")).StringValue.Should().Be("Адреса:"); target.GetCell(new CellPosition("D2")).StringValue.Should().Be("Имена:"); target.GetCell(new CellPosition("C3")).StringValue.Should().BeEmpty(); target.GetCell(new CellPosition("D3")).StringValue.Should().BeEmpty(); target.GetCell(new CellPosition("B4")).StringValue.Should().Be("StringValue"); DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20)); }
public void ObjectWithArrayPrintingTest() { var model = new DocumentWithArray { Array = new[] { new Organization { Address = "Address1", Name = "Name1" }, new Organization { Address = "Address2", Name = "Name2" }, new Organization { Address = "Address3", Name = "Name3" }, new Organization { Address = "Address4", Name = "Name4" } }, NonArray = "StringValue" }; var stringTemplate = new[] { new[] { "", "Template:RootTemplate:A2:D4", "", "" }, new[] { "", "Адреса:", "Имена:", "" }, new[] { "", "Value::Array[].Address", "Value::Array[].Name", "" }, new[] { "Value::NonArray", "", "", "" } }; var template = FakeTable.GenerateFromStringArray(stringTemplate); var target = new FakeTable(100, 100); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger)); var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); templateEngine.Render(tableBuilder, model); target.GetCell(new CellPosition("C2")).StringValue.Should().Be("Адреса:"); target.GetCell(new CellPosition("D2")).StringValue.Should().Be("Имена:"); target.GetCell(new CellPosition("C3")).StringValue.Should().Be("Address1"); target.GetCell(new CellPosition("C4")).StringValue.Should().Be("Address2"); target.GetCell(new CellPosition("C5")).StringValue.Should().Be("Address3"); target.GetCell(new CellPosition("C6")).StringValue.Should().Be("Address4"); target.GetCell(new CellPosition("D3")).StringValue.Should().Be("Name1"); target.GetCell(new CellPosition("D4")).StringValue.Should().Be("Name2"); target.GetCell(new CellPosition("D5")).StringValue.Should().Be("Name3"); target.GetCell(new CellPosition("D6")).StringValue.Should().Be("Name4"); target.GetCell(new CellPosition("B7")).StringValue.Should().Be("StringValue"); DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20)); }
public void SimpleObjectPrintingTest() { var model = new Document { Buyer = new Organization { Address = "BuyerAddress", Name = "BuyerName" }, Supplier = new Organization { Address = "SupplierAddress", Name = "SupplierName" }, TypeName = "ORDERS" }; var stringTemplate = new[] { new[] { "", "", "", "", "" }, new[] { "", "", "", "", "" }, new[] { "", "Template:RootTemplate:B4:D5", "", "", "" }, new[] { "", "Покупатель:", "Поставщик:", "", "" }, new[] { "", "Value:Organization:Buyer", "Value:Organization:Supplier", "Value::TypeName", "" }, new[] { "", "", "", "", "" }, new[] { "Template:Organization:A8:A9", "", "", "", "" }, new[] { "Value::Name", "", "", "", "" }, new[] { "Value::Address", "", "", "", "" } }; var template = FakeTable.GenerateFromStringArray(stringTemplate); var target = new FakeTable(100, 100); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger)); var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); templateEngine.Render(tableBuilder, model); target.GetCell(new CellPosition("A1")).StringValue.Should().Be("Покупатель:"); target.GetCell(new CellPosition("B1")).StringValue.Should().Be("Поставщик:"); target.GetCell(new CellPosition("A2")).StringValue.Should().Be("BuyerName"); target.GetCell(new CellPosition("B2")).StringValue.Should().Be("SupplierName"); target.GetCell(new CellPosition("C2")).StringValue.Should().Be("ORDERS"); target.GetCell(new CellPosition("A3")).StringValue.Should().Be("BuyerAddress"); target.GetCell(new CellPosition("B3")).StringValue.Should().Be("SupplierAddress"); ((FakeCell)target.GetCell(new CellPosition("A1"))).StyleId.Should().Be("B4"); ((FakeCell)target.GetCell(new CellPosition("B1"))).StyleId.Should().Be("C4"); ((FakeCell)target.GetCell(new CellPosition("A2"))).StyleId.Should().Be("A8"); ((FakeCell)target.GetCell(new CellPosition("B2"))).StyleId.Should().Be("A8"); ((FakeCell)target.GetCell(new CellPosition("C2"))).StyleId.Should().Be("D5"); ((FakeCell)target.GetCell(new CellPosition("A3"))).StyleId.Should().Be("A9"); ((FakeCell)target.GetCell(new CellPosition("B3"))).StyleId.Should().Be("A9"); DebugPrinting(target, new CellPosition(1, 1), new CellPosition(10, 10)); }
public void WithMergeCellsTemplateExtractionTest() { var template = FakeTable.GenerateFromStringArray(stringTemplate); template.MergeCells(new Rectangle(new CellPosition("A3"), new CellPosition("B3"))); var templateCollection = new TemplateCollection(template); var rootTemplate = templateCollection.GetTemplate("RootTemplate"); var mergedCells = rootTemplate.MergedCells.ToArray(); mergedCells.Length.Should().Be(1); mergedCells[0].UpperLeft.CellReference.Should().Be("A2"); mergedCells[0].LowerRight.CellReference.Should().Be("B2"); }
public void FromStringArrayFakeTableInitializationTest() { var template = new[] { new[] { "Text", null, "" }, new[] { "Value:RootModel:Root", "qwe", "Model:ABC:A1:SD123" } }; var table = FakeTable.GenerateFromStringArray(template); table.GetCell(new CellPosition("A1")).StringValue.Should().Be("Text"); table.GetCell(new CellPosition("B1")).StringValue.Should().BeNull(); table.GetCell(new CellPosition(2, 3)).StringValue.Should().Be("Model:ABC:A1:SD123"); }
public void WithNullFiledsTest() { var model = new Organization { Address = null, Name = "Name", }; var stringTemplate = new[] { new[] { "Template:RootTemplate:A2:B2", "" }, new[] { "Value::Address", "Value::Name" } }; var template = FakeTable.GenerateFromStringArray(stringTemplate); var target = new FakeTable(100, 100); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("B2"), logger)); var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); templateEngine.Render(tableBuilder, model); DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20)); }
public void TemplateExtractionTest() { var template = FakeTable.GenerateFromStringArray(stringTemplate); var templateCollection = new TemplateCollection(template); var rootTemplateContent = new[] { new[] { "Тест:", "Value::Test" }, new[] { "Birne:", "Value::Pear" } }; var rootTemplate = templateCollection.GetTemplate("RootTemplate"); var rowNumber = 0; foreach (var row in rootTemplate.Content.Cells) { var cellNumber = 0; foreach (var cell in row) { cell.StringValue.Should().Be(rootTemplateContent[rowNumber][cellNumber]); ++cellNumber; } ++rowNumber; } var thrashTemplate = templateCollection.GetTemplate("Thrash"); thrashTemplate.Content.Cells.First().First().StringValue.Should().Be("Value::Metallica"); var emptyTemplate = templateCollection.GetTemplate("Тест:"); emptyTemplate.Should().BeNull(); thrashTemplate.Range.UpperLeft.CellReference.Should().Be("D3"); thrashTemplate.Range.LowerRight.CellReference.Should().Be("D3"); }
public void WithTemplateDecompositionTest() { var model = new Document { Buyer = new Organization { Address = "BuyerAddress", Name = "BuyerName" }, Supplier = new Organization { Address = "SupplierAddress", Name = "SupplierName", Inn = "90238192038", Kpp = "0832309812" }, Payer = new Organization { Address = "PayerAddress", Name = "PayerName" }, DeliveryParty = new Organization { Address = "DeliveryPartyAddress", Name = "DeliveryPartyName" }, Vehicle = new VehicleInfo { NameOfCarrier = "Евкакий", TransportMode = "Agressive", VehicleBrand = "Tauria", VehicleNumber = "A777AB" }, TypeName = "ORDERS" }; var stringTemplate = new[] { new[] { "Template:RootTemplate:A2:D5", "", "", "", "", "" }, new[] { "Покупатель:", "", "Поставщик:", "", "", "" }, new[] { "Value:Organization:Buyer", "Value::TypeName", "Value:DetailedOrganization:Supplier", "", "", "" }, new[] { "Плательщик:", "Средство доставки:", "", "Доставка:", "", "" }, new[] { "Value:Organization:Payer", "Value:VehicleInfo:Vehicle", "Value:Organization:DeliveryParty", "", "", "" }, new[] { "", "", "", "", "", "" }, new[] { "Template:Organization:A8:A9", "", "", "", "", "" }, new[] { "Value::Name", "", "", "", "", "" }, new[] { "Value::Address", "", "", "", "", "" }, new[] { "", "", "", "", "", "" }, new[] { "Template:VehicleInfo:A12:B13", "", "", "", "", "" }, new[] { "Value::NameOfCarrier", "Value::VehicleBrand", "", "", "", "" }, new[] { "Value::TransportMode", "Value::VehicleNumber", "", "", "", "" }, new[] { "", "", "", "", "", "" }, new[] { "Template:DetailedOrganization:A16:B17", "", "", "", "", "" }, new[] { "Value::Name", "Value::Inn", "", "", "", "" }, new[] { "Value::Address", "Value::Kpp", "", "", "", "" } }; var template = FakeTable.GenerateFromStringArray(stringTemplate); var target = new FakeTable(100, 100); var tableBuilder = new TableBuilder(target, new TableNavigator(new CellPosition("A1"), logger)); var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); templateEngine.Render(tableBuilder, model); target.GetCell(new CellPosition("A1")).StringValue.Should().Be("Покупатель:"); target.GetCell(new CellPosition("C1")).StringValue.Should().Be("Поставщик:"); target.GetCell(new CellPosition("A2")).StringValue.Should().Be("BuyerName"); target.GetCell(new CellPosition("A3")).StringValue.Should().Be("BuyerAddress"); target.GetCell(new CellPosition("B2")).StringValue.Should().Be("ORDERS"); target.GetCell(new CellPosition("C2")).StringValue.Should().Be("SupplierName"); target.GetCell(new CellPosition("D2")).StringValue.Should().Be("90238192038"); target.GetCell(new CellPosition("C3")).StringValue.Should().Be("SupplierAddress"); target.GetCell(new CellPosition("D3")).StringValue.Should().Be("0832309812"); target.GetCell(new CellPosition("A4")).StringValue.Should().Be("Плательщик:"); target.GetCell(new CellPosition("B4")).StringValue.Should().Be("Средство доставки:"); target.GetCell(new CellPosition("D4")).StringValue.Should().Be("Доставка:"); target.GetCell(new CellPosition("A5")).StringValue.Should().Be("PayerName"); target.GetCell(new CellPosition("A6")).StringValue.Should().Be("PayerAddress"); target.GetCell(new CellPosition("B5")).StringValue.Should().Be("Евкакий"); target.GetCell(new CellPosition("C5")).StringValue.Should().Be("Tauria"); target.GetCell(new CellPosition("B6")).StringValue.Should().Be("Agressive"); target.GetCell(new CellPosition("C6")).StringValue.Should().Be("A777AB"); target.GetCell(new CellPosition("D5")).StringValue.Should().Be("DeliveryPartyName"); target.GetCell(new CellPosition("D6")).StringValue.Should().Be("DeliveryPartyAddress"); DebugPrinting(target, new CellPosition(1, 1), new CellPosition(20, 20)); }