diff --git a/EA-ModelKit.Tests/Converters/BooleanToVisibilityConverterTestFixture.cs b/EA-ModelKit.Tests/Converters/BooleanToVisibilityConverterTestFixture.cs
new file mode 100644
index 0000000..12224d6
--- /dev/null
+++ b/EA-ModelKit.Tests/Converters/BooleanToVisibilityConverterTestFixture.cs
@@ -0,0 +1,48 @@
+// -----------------------------------------------------------------------------------
+//
+// Copyright (c) 2024 Starion Nederland B.V.
+//
+// Authors: Alex Vorobiev, Antoine Théate, Sam Gerené, Anh-Toan Bui Long
+//
+// This file is part of ESA SysML plugin for Enterprise Architect
+// European Space Agency Community License – v2.4 Permissive (Type 3)
+// See LICENSE file for details
+//
+//
+// -----------------------------------------------------------------------------------
+
+namespace EAModelKit.Tests.Converters
+{
+ using System.Globalization;
+ using System.Windows;
+
+ using EAModelKit.Converters;
+
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class BooleanToVisibilityConverterTestFixture
+ {
+ private BooleanToVisibilityConverter converter;
+
+ [SetUp]
+ public void Setup()
+ {
+ this.converter = new BooleanToVisibilityConverter();
+ }
+
+ [Test]
+ public void VerifyConvert()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(this.converter.Convert(null, typeof(Visibility), "", CultureInfo.InvariantCulture), Is.EqualTo(Visibility.Collapsed));
+ Assert.That(this.converter.Convert(true, typeof(Visibility), "", CultureInfo.InvariantCulture), Is.EqualTo(Visibility.Visible));
+ Assert.That(this.converter.Convert(false, typeof(Visibility), "", CultureInfo.InvariantCulture), Is.EqualTo(Visibility.Collapsed));
+ Assert.That(this.converter.Convert(false, typeof(Visibility), "Invert", CultureInfo.InvariantCulture), Is.EqualTo(Visibility.Visible));
+ Assert.That(this.converter.Convert(true, typeof(Visibility), "Invert", CultureInfo.InvariantCulture), Is.EqualTo(Visibility.Collapsed));
+ Assert.That(() => this.converter.ConvertBack(Visibility.Collapsed, typeof(bool), "", CultureInfo.InvariantCulture), Throws.Exception);
+ });
+ }
+ }
+}
diff --git a/EA-ModelKit.Tests/Converters/StringCollectionConverterTestFixture.cs b/EA-ModelKit.Tests/Converters/StringCollectionConverterTestFixture.cs
new file mode 100644
index 0000000..5b52bc0
--- /dev/null
+++ b/EA-ModelKit.Tests/Converters/StringCollectionConverterTestFixture.cs
@@ -0,0 +1,45 @@
+// -----------------------------------------------------------------------------------
+//
+// Copyright (c) 2024 Starion Nederland B.V.
+//
+// Authors: Alex Vorobiev, Antoine Théate, Sam Gerené, Anh-Toan Bui Long
+//
+// This file is part of ESA SysML plugin for Enterprise Architect
+// European Space Agency Community License – v2.4 Permissive (Type 3)
+// See LICENSE file for details
+//
+//
+// -----------------------------------------------------------------------------------
+
+namespace EAModelKit.Tests.Converters
+{
+ using System.Globalization;
+
+ using EAModelKit.Converters;
+
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class StringCollectionConverterTestFixture
+ {
+ private StringCollectionConverter converter;
+
+ [SetUp]
+ public void Setup()
+ {
+ this.converter = new StringCollectionConverter();
+ }
+
+ [Test]
+ public void VerifyConvert()
+ {
+ Assert.That(this.converter.Convert(null, typeof(IEnumerable), null, CultureInfo.InvariantCulture), Is.EquivalentTo(new List()));
+ }
+
+ [Test]
+ public void VerifyConvertBack()
+ {
+ Assert.That(this.converter.ConvertBack(null, typeof(IEnumerable), null, CultureInfo.InvariantCulture), Is.Empty);
+ }
+ }
+}
diff --git a/EA-ModelKit.Tests/EA-ModelKit.Tests.csproj b/EA-ModelKit.Tests/EA-ModelKit.Tests.csproj
index 60c981d..0c07b84 100644
--- a/EA-ModelKit.Tests/EA-ModelKit.Tests.csproj
+++ b/EA-ModelKit.Tests/EA-ModelKit.Tests.csproj
@@ -30,6 +30,7 @@
..\lib\Interop.EA.dll
+
@@ -42,6 +43,9 @@
Always
+
+ Always
+
-
\ No newline at end of file
+
diff --git a/EA-ModelKit.Tests/Helpers/TestSlimElement.cs b/EA-ModelKit.Tests/Helpers/TestSlimElement.cs
new file mode 100644
index 0000000..dd1c9de
--- /dev/null
+++ b/EA-ModelKit.Tests/Helpers/TestSlimElement.cs
@@ -0,0 +1,58 @@
+// -------------------------------------------------------------------------------------------------
+//
+//
+// Copyright (C) 2024 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 EAModelKit.Tests.Helpers
+{
+ using EA;
+
+ using EAModelKit.Model.Slims;
+
+ using Moq;
+
+ ///
+ /// is a that is used for test purpose
+ ///
+ internal class TestSlimElement: SlimElement
+ {
+ ///
+ /// Initializes a new instance of
+ ///
+ /// The associated
+ /// The associated collection of
+ public TestSlimElement(Element element, IReadOnlyList taggedValues) : base(element, taggedValues)
+ {
+ }
+
+ public TestSlimElement(string kind, string name, string alias, string notes, IReadOnlyList taggedValues):
+ this(CreateElement(kind, name, alias, notes), taggedValues)
+ {
+ }
+
+ private static Element CreateElement(string kind, string name, string alias, string notes)
+ {
+ var element = new Mock();
+ element.Setup(x => x.Name).Returns(name);
+ element.Setup(x => x.Alias).Returns(alias);
+ element.Setup(x => x.Notes).Returns(notes);
+ element.Setup(x => x.Stereotype).Returns(kind);
+ return element.Object;
+ }
+ }
+}
diff --git a/EA-ModelKit.Tests/Resources/CacheService/TaggedValues.xml b/EA-ModelKit.Tests/Resources/CacheService/TaggedValues.xml
new file mode 100644
index 0000000..0a8ece5
--- /dev/null
+++ b/EA-ModelKit.Tests/Resources/CacheService/TaggedValues.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+ 20
+ "ABC"
+ ""
+
+
+ 20
+ "CDF"
+ "15"
+
+
+ 26
+ "CDF"
+ "16"
+
+
+ 10
+ "CDF"
+ "17"
+
+
+
+
diff --git a/EA-ModelKit.Tests/Services/Cache/CacheServiceTestFixture.cs b/EA-ModelKit.Tests/Services/Cache/CacheServiceTestFixture.cs
new file mode 100644
index 0000000..6e782d3
--- /dev/null
+++ b/EA-ModelKit.Tests/Services/Cache/CacheServiceTestFixture.cs
@@ -0,0 +1,69 @@
+// -------------------------------------------------------------------------------------------------
+//
+//
+// Copyright (C) 2024 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 EAModelKit.Tests.Services.Cache
+{
+ using EA;
+
+ using EAModelKit.Services.Cache;
+
+ using Moq;
+
+ using NUnit.Framework;
+
+ using File = System.IO.File;
+
+ [TestFixture]
+ public class CacheServiceTestFixture
+ {
+ private CacheService cacheService;
+ private Mock repository;
+
+ [SetUp]
+ public void Setup()
+ {
+ this.cacheService = new CacheService();
+ this.repository = new Mock();
+ this.cacheService.Initialize(this.repository.Object);
+
+ this.repository.Setup(x => x.SQLQuery(It.Is(i => i.Contains("t_objectproperties"))))
+ .Returns(QueryResourceContent("TaggedValues.xml"));
+ }
+
+ [Test]
+ public void VerifyGetTaggedValues()
+ {
+ Assert.Multiple(() =>
+ {
+ Assert.That(this.cacheService.GetTaggedValues(10).Count, Is.EqualTo(1));
+ Assert.That(this.cacheService.GetTaggedValues(20).Count, Is.EqualTo(2));
+ Assert.That(this.cacheService.GetTaggedValues(26).Count, Is.EqualTo(1));
+ Assert.That(this.cacheService.GetTaggedValues(27).Count, Is.EqualTo(0));
+ Assert.That(this.cacheService.GetTaggedValues([10,20,26]).Count, Is.EqualTo(4));
+ });
+ }
+
+ private static string QueryResourceContent(string fileName)
+ {
+ var path = Path.Combine(Directory.GetCurrentDirectory(), "Resources", "CacheService", fileName);
+ return File.ReadAllText(path);
+ }
+ }
+}
diff --git a/EA-ModelKit.Tests/Services/Dispatcher/DispatcherServiceTestFixture.cs b/EA-ModelKit.Tests/Services/Dispatcher/DispatcherServiceTestFixture.cs
index c813c8e..f95e772 100644
--- a/EA-ModelKit.Tests/Services/Dispatcher/DispatcherServiceTestFixture.cs
+++ b/EA-ModelKit.Tests/Services/Dispatcher/DispatcherServiceTestFixture.cs
@@ -20,11 +20,17 @@
namespace EAModelKit.Tests.Services.Dispatcher
{
+ using Autofac;
+
using EA;
+ using EAModelKit.Services.Cache;
using EAModelKit.Services.Dispatcher;
using EAModelKit.Services.Logger;
using EAModelKit.Services.Selection;
+ using EAModelKit.Services.ViewBuilder;
+ using EAModelKit.ViewModels.Exporter;
+ using EAModelKit.Views.Export;
using Microsoft.Extensions.Logging;
@@ -32,6 +38,8 @@ namespace EAModelKit.Tests.Services.Dispatcher
using NUnit.Framework;
+ using App = EAModelKit.App;
+
[TestFixture]
public class DispatcherServiceTestFixture
{
@@ -39,15 +47,19 @@ public class DispatcherServiceTestFixture
private Mock selectionService;
private Mock loggerService;
private Mock repository;
-
+ private Mock viewBuilderService;
+ private Mock cacheService;
+
[SetUp]
public void Setup()
{
this.selectionService = new Mock();
this.loggerService = new Mock();
this.repository = new Mock();
-
- this.dispatcher = new DispatcherService(this.loggerService.Object, this.selectionService.Object);
+ this.viewBuilderService = new Mock();
+ this.cacheService = new Mock();
+
+ this.dispatcher = new DispatcherService(this.loggerService.Object, this.selectionService.Object, this.viewBuilderService.Object, this.cacheService.Object);
}
[Test]
@@ -72,6 +84,11 @@ public void VerifyDisconnect()
[Test]
public void VerifyOnGenericExport()
{
+ this.selectionService.Setup(x => x.QuerySelectedElements(this.repository.Object)).Returns([]);
+ this.dispatcher.OnGenericExport(this.repository.Object);
+
+ this.loggerService.Verify(x => x.Log(LogLevel.Warning, It.IsAny()), Times.Once);
+
var selectedElements = new List
{
CreateNewElement("Requirement"),
@@ -83,16 +100,63 @@ public void VerifyOnGenericExport()
CreateNewElement("Block")
};
+ var exporterViewModel = new Mock();
+ var container = new ContainerBuilder();
+ container.RegisterInstance(exporterViewModel.Object);
+ App.BuildContainer(container);
this.selectionService.Setup(x => x.QuerySelectedElements(this.repository.Object)).Returns(selectedElements);
this.dispatcher.OnGenericExport(this.repository.Object);
-
+
Assert.Multiple(() =>
{
- this.loggerService.Verify(x => x.Log(LogLevel.Debug, "Found {0} Elements With Stereotype {1}", 4, "Requirement"), Times.Once);
- this.loggerService.Verify(x => x.Log(LogLevel.Debug, "Found {0} Elements With Stereotype {1}", 3, "Block"), Times.Once);
+ exporterViewModel.Verify(x => x.InitializeViewModel(selectedElements), Times.Once);
+ this.viewBuilderService.Verify(x => x.ShowDxDialog(exporterViewModel.Object), Times.Once);
});
}
+ [Test]
+ public void VerifyResetServices()
+ {
+ this.dispatcher.OnFileOpen(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Once);
+
+ this.dispatcher.OnFileNew(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(2));
+
+ this.dispatcher.OnPostNewPackage(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(3));
+
+ this.dispatcher.OnPostNewElement(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(4));
+
+ this.dispatcher.OnPostNewConnector(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(5));
+
+ this.dispatcher.OnPostNewAttribute(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(6));
+
+ this.dispatcher.OnPreDeleteElement(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(7));
+
+ this.dispatcher.OnPreDeleteAttribute(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(8));
+
+ this.dispatcher.OnPreDeleteConnector(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(9));
+
+ this.dispatcher.OnPreDeletePackage(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(10));
+
+ this.dispatcher.OnPostNewDiagram(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(11));
+
+ this.dispatcher.OnPreDeleteDiagram(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(12));
+
+ this.dispatcher.OnNotifyContextItemModified(this.repository.Object);
+ this.cacheService.Verify(x => x.Initialize(this.repository.Object), Times.Exactly(13));
+ }
+
private static Element CreateNewElement(string stereotypeName)
{
var element = new Mock();
diff --git a/EA-ModelKit.Tests/Services/Exporter/GenericExporterServiceTestFixture.cs b/EA-ModelKit.Tests/Services/Exporter/GenericExporterServiceTestFixture.cs
new file mode 100644
index 0000000..47829da
--- /dev/null
+++ b/EA-ModelKit.Tests/Services/Exporter/GenericExporterServiceTestFixture.cs
@@ -0,0 +1,90 @@
+// -------------------------------------------------------------------------------------------------
+//
+//
+// Copyright (C) 2024 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 EAModelKit.Tests.Services.Exporter
+{
+ using EA;
+
+ using EAModelKit.Model.Export;
+ using EAModelKit.Model.Slims;
+ using EAModelKit.Services.Exporter;
+ using EAModelKit.Services.Logger;
+ using EAModelKit.Services.Writer;
+
+ using Microsoft.Extensions.Logging;
+
+ using Moq;
+
+ using NUnit.Framework;
+
+ using Task = Task;
+
+ [TestFixture]
+ public class GenericExporterServiceTestFixture
+ {
+ private GenericExporterService exporterService;
+ private Mock loggerService;
+ private Mock excelWriter;
+
+ [SetUp]
+ public void Setup()
+ {
+ this.loggerService = new Mock();
+ this.excelWriter = new Mock();
+ this.exporterService = new GenericExporterService(this.loggerService.Object, this.excelWriter.Object);
+ }
+
+ [Test]
+ public async Task VerifyExportElements()
+ {
+ var slimTaggedValue = new SlimTaggedValue
+ {
+ ContainerId = 1,
+ Name = "abc",
+ Value = "15"
+ };
+
+ var element = new Mock();
+ element.Setup(x => x.Name).Returns("abc");
+ element.Setup(x => x.Stereotype).Returns("Function");
+ element.Setup(x => x.ElementID).Returns(slimTaggedValue.ContainerId);
+
+ var slimTaggedValues = new List { slimTaggedValue };
+ var slimElement = new SlimElement(element.Object, slimTaggedValues);
+
+ var genericConfigurations = new List
+ {
+ new([slimElement], [slimTaggedValue.Name])
+ };
+
+ this.excelWriter.Setup(x => x.WriteAsync(It.IsAny>>(), It.IsAny()))
+ .Returns(Task.CompletedTask);
+
+ await this.exporterService.ExportElementsAsync("abcpath", genericConfigurations);
+
+ this.loggerService.Verify(x => x.Log(LogLevel.Information, It.IsAny(), It.IsAny