Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,49 @@ public void Verify_that_the_generated_capella_html_contains_expected_content()
});
}

[Test]
public void Verify_that_a_single_combined_html_report_is_generated_for_the_whole_capella_metamodel()
{
var inputDirectory = new DirectoryInfo(CapellaDirectory);

var reportFileInfo = new FileInfo(Path.Combine(
TestContext.CurrentContext.TestDirectory,
"html-report.capella.combined.html"));

Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(inputDirectory, reportFileInfo), Throws.Nothing);

reportFileInfo.Refresh();
Assert.That(reportFileInfo.Exists, Is.True);

var html = File.ReadAllText(reportFileInfo.FullName);

Assert.Multiple(() =>
{
// a single document must contain classifiers that originate from several different .ecore files
Assert.That(html, Does.Contain("CapellaElement")); // CapellaCore.ecore
Assert.That(html, Does.Contain("LogicalArchitecture")); // LogicalArchitecture.ecore
Assert.That(html, Does.Contain("SystemAnalysis")); // ContextArchitecture.ecore
Assert.That(html, Does.Contain("PhysicalArchitecture")); // PhysicalArchitecture.ecore
Assert.That(html, Does.Contain("OperationalAnalysis")); // OperationalAnalysis.ecore
});
}

[Test]
public void Verify_that_a_combined_report_from_an_entry_file_includes_reachable_models()
{
// LogicalArchitecture.ecore references classifiers that live in other files (e.g. its super type
// ComponentArchitecture lives in CompositeStructure.ecore); the combined report must include them.
var modelFileInfo = new FileInfo(Path.Combine(CapellaDirectory, "LogicalArchitecture.ecore"));

var html = this.htmlReportGenerator.GenerateCombinedReport(modelFileInfo);

Assert.Multiple(() =>
{
Assert.That(html, Does.Contain("LogicalArchitecture"));
Assert.That(html, Does.Contain("ComponentArchitecture"));
});
}

/// <summary>
/// Enumerates the Capella <c>.ecore</c> file names available in the test output directory.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// ------------------------------------------------------------------------------------------------
// <copyright file="CapellaMarkdownReportGeneratorTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2017-2026 Starion Group S.A.
// SPDX-License-Identifier: Apache-2.0
//
// </copyright>
// ------------------------------------------------------------------------------------------------

namespace ECoreNetto.Tools.Tests.Generators
{
using System.Collections.Generic;
using System.IO;
using System.Linq;

using ECoreNetto.Reporting.Generators;

using Microsoft.Extensions.Logging;

using NUnit.Framework;

using Serilog;

/// <summary>
/// Suite of tests that verify the <see cref="MarkdownReportGenerator"/> produces a Markdown report for the
/// Eclipse Capella metamodel (21 cross-referencing <c>.ecore</c> files), both per file and as a single
/// combined report of the whole metamodel.
/// </summary>
[TestFixture]
public class CapellaMarkdownReportGeneratorTestFixture
{
private static readonly string CapellaDirectory = Path.Combine(
Path.GetDirectoryName(typeof(CapellaMarkdownReportGeneratorTestFixture).Assembly.Location)!,
"Data",
"capella");

private MarkdownReportGenerator markdownReportGenerator = null!;

private ILoggerFactory? loggerFactory;

[OneTimeSetUp]
public void OneTimeSetUp()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.WriteTo.Console()
.CreateLogger();

this.loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddSerilog();
});
}

[SetUp]
public void SetUp()
{
this.markdownReportGenerator = new MarkdownReportGenerator(this.loggerFactory);
}

[Test]
[TestCaseSource(nameof(CapellaModelFiles))]
public void Verify_that_a_markdown_report_is_generated_for_a_capella_model(string fileName)
{
var modelFileInfo = new FileInfo(Path.Combine(CapellaDirectory, fileName));

var reportFileInfo = new FileInfo(Path.Combine(
TestContext.CurrentContext.TestDirectory,
$"markdown-report.capella.{Path.GetFileNameWithoutExtension(fileName)}.md"));

Assert.That(() => this.markdownReportGenerator.GenerateReport(modelFileInfo, reportFileInfo), Throws.Nothing);

reportFileInfo.Refresh();
Assert.That(reportFileInfo.Exists, Is.True);
}

[Test]
public void Verify_that_a_single_combined_markdown_report_is_generated_for_the_whole_capella_metamodel()
{
var inputDirectory = new DirectoryInfo(CapellaDirectory);

var reportFileInfo = new FileInfo(Path.Combine(
TestContext.CurrentContext.TestDirectory,
"markdown-report.capella.combined.md"));

Assert.That(() => this.markdownReportGenerator.GenerateCombinedReport(inputDirectory, reportFileInfo), Throws.Nothing);

reportFileInfo.Refresh();
Assert.That(reportFileInfo.Exists, Is.True);

var markdown = File.ReadAllText(reportFileInfo.FullName);

Assert.Multiple(() =>
{
// a single document must contain classifiers that originate from several different .ecore files
Assert.That(markdown, Does.Contain("CapellaElement")); // CapellaCore.ecore
Assert.That(markdown, Does.Contain("LogicalArchitecture")); // LogicalArchitecture.ecore
Assert.That(markdown, Does.Contain("SystemAnalysis")); // ContextArchitecture.ecore
Assert.That(markdown, Does.Contain("PhysicalArchitecture")); // PhysicalArchitecture.ecore
Assert.That(markdown, Does.Contain("OperationalAnalysis")); // OperationalAnalysis.ecore
});
}

[Test]
public void Verify_that_a_combined_markdown_report_from_an_entry_file_includes_reachable_models()
{
var modelFileInfo = new FileInfo(Path.Combine(CapellaDirectory, "LogicalArchitecture.ecore"));

var markdown = this.markdownReportGenerator.GenerateCombinedReport(modelFileInfo);

Assert.Multiple(() =>
{
Assert.That(markdown, Does.Contain("LogicalArchitecture"));
Assert.That(markdown, Does.Contain("ComponentArchitecture"));
});
}

/// <summary>
/// Enumerates the Capella <c>.ecore</c> file names available in the test output directory.
/// </summary>
private static IEnumerable<string> CapellaModelFiles()
{
return Directory.EnumerateFiles(CapellaDirectory, "*.ecore").Select(file => Path.GetFileName(file)!);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// ------------------------------------------------------------------------------------------------
// <copyright file="CapellaXlReportGeneratorTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 2017-2026 Starion Group S.A.
// SPDX-License-Identifier: Apache-2.0
//
// </copyright>
// ------------------------------------------------------------------------------------------------

namespace ECoreNetto.Reporting.Tests.Generators
{
using System.Collections.Generic;
using System.IO;
using System.Linq;

using ClosedXML.Excel;

using ECoreNetto.Reporting.Generators;

using NUnit.Framework;

/// <summary>
/// Suite of tests that verify the <see cref="XlReportGenerator"/> produces an Excel report for the Eclipse
/// Capella metamodel (21 cross-referencing <c>.ecore</c> files), both per file and as a single combined
/// workbook of the whole metamodel.
/// </summary>
[TestFixture]
public class CapellaXlReportGeneratorTestFixture
{
private static readonly string CapellaDirectory = Path.Combine(
Path.GetDirectoryName(typeof(CapellaXlReportGeneratorTestFixture).Assembly.Location)!,
"Data",
"capella");

private XlReportGenerator generator = null!;

[SetUp]
public void SetUp()
{
this.generator = new XlReportGenerator();
}

[Test]
[TestCaseSource(nameof(CapellaModelFiles))]
public void Verify_that_an_excel_report_is_generated_for_a_capella_model(string fileName)
{
var modelFileInfo = new FileInfo(Path.Combine(CapellaDirectory, fileName));

var reportFileInfo = new FileInfo(Path.Combine(
TestContext.CurrentContext.TestDirectory,
$"xl-report.capella.{Path.GetFileNameWithoutExtension(fileName)}.xlsx"));

Assert.That(() => this.generator.GenerateReport(modelFileInfo, reportFileInfo), Throws.Nothing);

reportFileInfo.Refresh();
Assert.That(reportFileInfo.Exists, Is.True);
}

[Test]
public void Verify_that_a_single_combined_excel_report_is_generated_for_the_whole_capella_metamodel()
{
var inputDirectory = new DirectoryInfo(CapellaDirectory);

var reportFileInfo = new FileInfo(Path.Combine(
TestContext.CurrentContext.TestDirectory,
"xl-report.capella.combined.xlsx"));

Assert.That(() => this.generator.GenerateCombinedReport(inputDirectory, reportFileInfo), Throws.Nothing);

reportFileInfo.Refresh();
Assert.That(reportFileInfo.Exists, Is.True);

using var workbook = new XLWorkbook(reportFileInfo.FullName);

var info = workbook.Worksheet("Model Info");
var eClassSheet = workbook.Worksheet("EClass");

Assert.Multiple(() =>
{
// the info sheet lists all the included root packages
Assert.That(info.Cell(6, 1).GetString(), Is.EqualTo("Included Packages"));

// a single workbook must list classes that originate from several different .ecore files
Assert.That(eClassSheet.CellsUsed().Any(c => c.GetString() == "CapellaElement"), Is.True);
Assert.That(eClassSheet.CellsUsed().Any(c => c.GetString() == "LogicalArchitecture"), Is.True);
Assert.That(eClassSheet.CellsUsed().Any(c => c.GetString() == "SystemAnalysis"), Is.True);
Assert.That(eClassSheet.CellsUsed().Any(c => c.GetString() == "PhysicalArchitecture"), Is.True);
});
}

[Test]
public void Verify_that_a_combined_excel_report_from_an_entry_file_includes_reachable_models()
{
var modelFileInfo = new FileInfo(Path.Combine(CapellaDirectory, "LogicalArchitecture.ecore"));
var reportFileInfo = new FileInfo(Path.Combine(
TestContext.CurrentContext.TestDirectory,
"xl-report.capella.reachable.xlsx"));

Assert.That(() => this.generator.GenerateCombinedReport(modelFileInfo, reportFileInfo), Throws.Nothing);

reportFileInfo.Refresh();
Assert.That(reportFileInfo.Exists, Is.True);

using var workbook = new XLWorkbook(reportFileInfo.FullName);
var eClassSheet = workbook.Worksheet("EClass");

Assert.Multiple(() =>
{
Assert.That(eClassSheet.CellsUsed().Any(c => c.GetString() == "LogicalArchitecture"), Is.True);
Assert.That(eClassSheet.CellsUsed().Any(c => c.GetString() == "ComponentArchitecture"), Is.True);
});
}

/// <summary>
/// Enumerates the Capella <c>.ecore</c> file names available in the test output directory.
/// </summary>
private static IEnumerable<string> CapellaModelFiles()
{
return Directory.EnumerateFiles(CapellaDirectory, "*.ecore").Select(file => Path.GetFileName(file)!);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,24 @@ public void Verify_That_when_outputpath_is_null_exception_is_thrown()
{
Assert.That(() => this.htmlReportGenerator.IsValidReportExtension(null!), Throws.ArgumentNullException);
}

[Test]
public void Verify_that_combined_report_methods_throw_when_arguments_are_null()
{
FileInfo? modelFileInfo = null;
DirectoryInfo? directory = null;
var validModel = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "recipe.ecore"));
var validOutput = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "html-report.combined-null.html"));

Assert.Multiple(() =>
{
Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(modelFileInfo!), Throws.ArgumentNullException);
Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(directory!), Throws.ArgumentNullException);
Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(modelFileInfo!, validOutput), Throws.ArgumentNullException);
Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(validModel, (FileInfo)null!), Throws.ArgumentNullException);
Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(directory!, validOutput), Throws.ArgumentNullException);
Assert.That(() => this.htmlReportGenerator.GenerateCombinedReport(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), (FileInfo)null!), Throws.ArgumentNullException);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ public void Verify_that_the_report_generator_generates_a_report(string model)
Assert.That(() => this.markdownReportGenerator.GenerateReport(modelFileInfo, reportFileInfo), Throws.Nothing);
}

[Test]
public void Verify_that_combined_markdown_report_methods_throw_when_arguments_are_null()
{
var validModel = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "recipe.ecore"));
var validOutput = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "markdown-report.null.md"));

Assert.Multiple(() =>
{
Assert.That(() => this.markdownReportGenerator.GenerateCombinedReport((FileInfo)null!), Throws.ArgumentNullException);
Assert.That(() => this.markdownReportGenerator.GenerateCombinedReport((DirectoryInfo)null!), Throws.ArgumentNullException);
Assert.That(() => this.markdownReportGenerator.GenerateCombinedReport((FileInfo)null!, validOutput), Throws.ArgumentNullException);
Assert.That(() => this.markdownReportGenerator.GenerateCombinedReport(validModel, null!), Throws.ArgumentNullException);
Assert.That(() => this.markdownReportGenerator.GenerateCombinedReport(new DirectoryInfo(TestContext.CurrentContext.TestDirectory), null!), Throws.ArgumentNullException);
});
}

[Test]
public void Verify_that_the_generated_markdown_contains_the_expected_content()
{
Expand Down
23 changes: 23 additions & 0 deletions ECoreNetto.Reporting.Tests/Generators/ModelInspectorTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,29 @@ public void Verify_that_the_report_generator_generates_a_report()
Assert.That(() => this.modelInspector.GenerateReport(modelFileInfo, reportFileInfo), Throws.Nothing);
}

[Test]
public void Verify_that_a_combined_inspection_report_is_generated_for_a_multi_file_metamodel()
{
var capellaEntry = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "Data", "capella", "LogicalArchitecture.ecore"));
var output = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "inspection.capella.combined.txt"));

Assert.That(() => this.modelInspector.GenerateCombinedReport(capellaEntry, output), Throws.Nothing);

output.Refresh();
Assert.That(output.Exists, Is.True);
}

[Test]
public void Verify_that_GenerateCombinedReport_throws_when_arguments_are_null()
{
Assert.Multiple(() =>
{
Assert.That(() => this.modelInspector.GenerateCombinedReport((FileInfo)null!, reportFileInfo), Throws.ArgumentNullException);
Assert.That(() => this.modelInspector.GenerateCombinedReport(modelFileInfo, (FileInfo)null!), Throws.ArgumentNullException);
Assert.That(() => this.modelInspector.GenerateCombinedReport((DirectoryInfo)null!, reportFileInfo), Throws.ArgumentNullException);
});
}

[Test]
public void Verify_that_IsValidExcelReportExtension_returns_false_when_invalid()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public void Verify_that_the_class_enum_and_datatype_sheets_contain_the_expected_
});
}

[Test]
public void Verify_that_combined_excel_report_methods_throw_when_arguments_are_null()
{
var validDirectory = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);

Assert.Multiple(() =>
{
Assert.That(() => this.generator.GenerateCombinedReport((FileInfo)null!, this.reportFileInfo), Throws.ArgumentNullException);
Assert.That(() => this.generator.GenerateCombinedReport(this.modelFileInfo, (FileInfo)null!), Throws.ArgumentNullException);
Assert.That(() => this.generator.GenerateCombinedReport((DirectoryInfo)null!, this.reportFileInfo), Throws.ArgumentNullException);
Assert.That(() => this.generator.GenerateCombinedReport(validDirectory, null!), Throws.ArgumentNullException);
});
}

[Test]
public void Verify_that_IsValidReportExtension_returns_expected_results()
{
Expand Down
Loading
Loading