diff --git a/ECoreNetto.Reporting.Tests/Generators/XlReportGeneratorTestFixture.cs b/ECoreNetto.Reporting.Tests/Generators/XlReportGeneratorTestFixture.cs new file mode 100644 index 0000000..e512985 --- /dev/null +++ b/ECoreNetto.Reporting.Tests/Generators/XlReportGeneratorTestFixture.cs @@ -0,0 +1,79 @@ +// ------------------------------------------------------------------------------------------------- +// +// +// Copyright 2017-2025 Starion Group S.A. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// +// ------------------------------------------------------------------------------------------------ + +namespace ECoreNetto.Reporting.Tests.Generators +{ + using System.IO; + + using ClosedXML.Excel; + + using ECoreNetto.Reporting.Generators; + + using NUnit.Framework; + + /// + /// Suite of tests for the class. + /// + [TestFixture] + public class XlReportGeneratorTestFixture + { + private XlReportGenerator generator = null!; + + private FileInfo modelFileInfo = null!; + + private FileInfo reportFileInfo = null!; + + [SetUp] + public void SetUp() + { + this.generator = new XlReportGenerator(); + + this.modelFileInfo = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "recipe.ecore")); + this.reportFileInfo = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "xl-report.xlsx")); + } + + [Test] + public void Verify_that_the_info_sheet_contains_distinct_ns_prefix_and_ns_uri_rows() + { + this.generator.GenerateReport(this.modelFileInfo, this.reportFileInfo); + + using var workbook = new XLWorkbook(this.reportFileInfo.FullName); + var info = workbook.Worksheet("Model Info"); + + Assert.Multiple(() => + { + Assert.That(info.Cell(4, 1).GetString(), Is.EqualTo("Root Package - ns prefix")); + Assert.That(info.Cell(4, 2).GetString(), Is.EqualTo("recipe")); + Assert.That(info.Cell(5, 1).GetString(), Is.EqualTo("Root Package - ns uri")); + Assert.That(info.Cell(5, 2).GetString(), Is.EqualTo("hu.bme.mit.mdsd.recipe")); + }); + } + + [Test] + public void Verify_that_IsValidReportExtension_returns_expected_results() + { + Assert.Multiple(() => + { + Assert.That(this.generator.IsValidReportExtension(new FileInfo("report.xlsx")).Item1, Is.True); + Assert.That(this.generator.IsValidReportExtension(new FileInfo("report.txt")).Item1, Is.False); + }); + } + } +} diff --git a/ECoreNetto.Reporting/Generators/XlReportGenerator.cs b/ECoreNetto.Reporting/Generators/XlReportGenerator.cs index b1432cb..393469a 100644 --- a/ECoreNetto.Reporting/Generators/XlReportGenerator.cs +++ b/ECoreNetto.Reporting/Generators/XlReportGenerator.cs @@ -142,8 +142,8 @@ private void AddInfoSheet(XLWorkbook workbook, EPackage rootPackage) infoWorksheet.Cell(4, 1).Value = "Root Package - ns prefix"; infoWorksheet.Cell(4, 2).Value = rootPackage.NsPrefix; - infoWorksheet.Cell(4, 1).Value = "Root Package - ns uri"; - infoWorksheet.Cell(4, 2).Value = rootPackage.NsUri; + infoWorksheet.Cell(5, 1).Value = "Root Package - ns uri"; + infoWorksheet.Cell(5, 2).Value = rootPackage.NsUri; this.FormatSheet(infoWorksheet); }