From c0cfc4b81b11d43e4c072a7074ae6cb037a78388 Mon Sep 17 00:00:00 2001 From: peterforstmeier Date: Sun, 3 Oct 2010 18:42:50 +0200 Subject: [PATCH] UnitTest for CreateGroupedReport from TableLayout.cs --- .../ReportWizard/ReportLayout/TableLayout.cs | 4 +- .../ICSharpCode.Reports.Addin.Test.csproj | 1 + .../GenerateListWithGroupFixture.cs | 5 +- .../GenertaeTableWithgroupFixture.cs | 127 ++++++++++++++++++ 4 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenertaeTableWithgroupFixture.cs diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs index 16d4cdde00..2e7ee955bb 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Project/ReportWizard/ReportLayout/TableLayout.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.Reports.Addin.ReportWizard base.ParentItem = table; ICSharpCode.Reports.Core.BaseRowItem headerRow = CreateRowWithTextColumns(ParentItem, this.reportItems); - + ParentItem.Items.Add (headerRow); Point insertLocation = new Point (margin.Left,headerRow.Location.Y + headerRow.Size.Height + margin.Bottom + margin.Top); @@ -78,8 +78,6 @@ namespace ICSharpCode.Reports.Addin.ReportWizard insertLocation = new Point(margin.Left,insertLocation.Y + detailRow.Size.Height + margin.Bottom + margin.Top); - - ParentItem.Items.Add (headerRow); ParentItem.Items.Add (detailRow); ParentItem.Size = CalculateContainerSize(ParentItem,margin); diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/ICSharpCode.Reports.Addin.Test.csproj b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/ICSharpCode.Reports.Addin.Test.csproj index 77276b77a0..4934da2604 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/ICSharpCode.Reports.Addin.Test.csproj +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/ICSharpCode.Reports.Addin.Test.csproj @@ -70,6 +70,7 @@ + diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenerateListWithGroupFixture.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenerateListWithGroupFixture.cs index a4d6bf8c98..2dfae7317d 100644 --- a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenerateListWithGroupFixture.cs +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenerateListWithGroupFixture.cs @@ -99,7 +99,7 @@ namespace ICSharpCode.Reports.Addin.Test.Wizard.Generators { // TODO: Add tear down code. } - + /* private static ReportModel CreateModel (string reportName) { @@ -120,6 +120,7 @@ namespace ICSharpCode.Reports.Addin.Test.Wizard.Generators customizer.Set("Generator", structure); customizer.Set("ReportLayout",GlobalEnums.ReportLayout.ListLayout); + IReportGenerator generator = new GeneratePushDataReport(m,customizer); generator.GenerateReport(); @@ -136,7 +137,7 @@ namespace ICSharpCode.Reports.Addin.Test.Wizard.Generators return model; } - + */ private static ReportStructure CreateReportStructure (string reportName) { ReportStructure structure = new ReportStructure(); diff --git a/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenertaeTableWithgroupFixture.cs b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenertaeTableWithgroupFixture.cs new file mode 100644 index 0000000000..e8f1029aa9 --- /dev/null +++ b/src/AddIns/Misc/Reports/ICSharpCode.Reports.Addin/Test/Wizard/Generators/GenertaeTableWithgroupFixture.cs @@ -0,0 +1,127 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 03.10.2010 + * Time: 17:26 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ + +using System; +using ICSharpCode.Reports.Addin.ReportWizard; +using ICSharpCode.Reports.Core; +using NUnit.Framework; + +namespace ICSharpCode.Reports.Addin.Test.Wizard.Generators +{ + [TestFixture] + public class GenertaeTableWithGroupFixture + { + + private const string reportName = "TableBasedReport"; + private ReportModel reportModel; + + + [Test] + public void PageDetail_First_Item_Should_Table() + { + ICSharpCode.Reports.Core.BaseSection s = this.reportModel.DetailSection; + var item = s.Items[0]; + Assert.That(item,Is.InstanceOf(typeof(ICSharpCode.Reports.Core.BaseTableItem))); + } + + + [Test] + public void Table_Should_Contain_Three_Rows() + { + ICSharpCode.Reports.Core.BaseSection s = this.reportModel.DetailSection; + ICSharpCode.Reports.Core.BaseTableItem table = s.Items[0] as ICSharpCode.Reports.Core.BaseTableItem; + Assert.That(table.Items.Count,Is.GreaterThanOrEqualTo(3)); + } + + + [Test] + public void Table_FirstItem_Should_Row () + { + ICSharpCode.Reports.Core.BaseSection s = this.reportModel.DetailSection; + ICSharpCode.Reports.Core.BaseTableItem table = s.Items[0] as ICSharpCode.Reports.Core.BaseTableItem; + var row = table.Items[0]; + Assert.That(row,Is.InstanceOf(typeof(ICSharpCode.Reports.Core.BaseRowItem))); + } + + + [Test] + public void Table_SecondItem_Should_GroupRow () + { + ICSharpCode.Reports.Core.BaseSection s = this.reportModel.DetailSection; + ICSharpCode.Reports.Core.BaseTableItem table = s.Items[0] as ICSharpCode.Reports.Core.BaseTableItem; + var row = table.Items[1]; + Assert.That(row,Is.InstanceOf(typeof(ICSharpCode.Reports.Core.BaseGroupedRow))); + } + + #region setup / TearDown + + [TestFixtureSetUp] + public void Init() + { + this.reportModel = CreateModel(reportName); + } + + [TestFixtureTearDown] + public void Dispose() + { + // TODO: Add tear down code. + } + + private static ReportModel CreateModel (string reportName) + { + + ReportStructure structure = CreateReportStructure(reportName); + + AvailableFieldsCollection abstractColumns = new AvailableFieldsCollection(); + AbstractColumn a1 = new AbstractColumn("Field1",typeof(System.String)); + structure.AvailableFieldsCollection.Add(a1); + + ICSharpCode.Reports.Core.BaseDataItem bri = new ICSharpCode.Reports.Core.BaseDataItem(); + bri.Name ="Field1"; + structure.ReportItemCollection.Add(bri); + + structure.Grouping = "group"; + + ReportModel m = structure.CreateAndFillReportModel(); + + ICSharpCode.Core.Properties customizer = new ICSharpCode.Core.Properties(); + + customizer.Set("Generator", structure); + customizer.Set("ReportLayout",GlobalEnums.ReportLayout.TableLayout); + + IReportGenerator generator = new GeneratePushDataReport(m,customizer); + + generator.GenerateReport(); + + ReportLoader rl = new ReportLoader(); + object root = rl.Load(generator.XmlReport.DocumentElement); + ReportModel model = root as ReportModel; + if (model != null) { + model.ReportSettings.FileName = GlobalValues.PlainFileName; + FilePathConverter.AdjustReportName(model); + } else { + throw new InvalidReportModelException(); + } + return model; + } + + + private static ReportStructure CreateReportStructure (string reportName) + { + ReportStructure structure = new ReportStructure(); + structure.ReportName = reportName; + structure.DataModel = GlobalEnums.PushPullModel.PushData; + structure.ReportType = GlobalEnums.ReportType.DataReport; + return structure; + } + + #endregion + + } +}