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
@@ -0,0 +1,48 @@
// -----------------------------------------------------------------------------------
// <copyright file="BooleanToVisibilityConverterTestFixture.cs" company="Starion Nederland B.V.">
// 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
//
// </copyright>
// -----------------------------------------------------------------------------------

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);
});
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add newline at the end of each file. We had this rule earlier and it got removed. There is good reason to make diffs more readible when using git and git extensions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line is already present on each file, just the Tests.csproj one that missed it

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// -----------------------------------------------------------------------------------
// <copyright file="FileImportExportCollectionConverterTestFixture.cs" company="Starion Nederland B.V.">
// 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
//
// </copyright>
// -----------------------------------------------------------------------------------

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<string>), null, CultureInfo.InvariantCulture), Is.EquivalentTo(new List<string>()));
}

[Test]
public void VerifyConvertBack()
{
Assert.That(this.converter.ConvertBack(null, typeof(IEnumerable<string>), null, CultureInfo.InvariantCulture), Is.Empty);
}
}
}
6 changes: 5 additions & 1 deletion EA-ModelKit.Tests/EA-ModelKit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<Reference Include="Interop.EA">
<HintPath>..\lib\Interop.EA.dll</HintPath>
</Reference>
<Reference Include="PresentationCore"/>
</ItemGroup>

<ItemGroup>
Expand All @@ -42,6 +43,9 @@
<None Update="Resources\SelectionService\EmptyElements.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\CacheService\TaggedValues.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
</Project>
58 changes: 58 additions & 0 deletions EA-ModelKit.Tests/Helpers/TestSlimElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="TestSlimElement.cs" company="Starion Group S.A.">
//
// 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.
//
// </copyright>
// -----------------------------------------------------------------------------------------------

namespace EAModelKit.Tests.Helpers
{
using EA;

using EAModelKit.Model.Slims;

using Moq;

/// <summary>
/// <see cref="TestSlimElement"/> is a <see cref="SlimElement"/> that is used for test purpose
/// </summary>
internal class TestSlimElement: SlimElement
{
/// <summary>
/// Initializes a new instance of <see cref="TestSlimElement" />
/// </summary>
/// <param name="element">The associated <see cref="Element"/></param>
/// <param name="taggedValues">The associated collection of <see cref="SlimTaggedValue"/></param>
public TestSlimElement(Element element, IReadOnlyList<SlimTaggedValue> taggedValues) : base(element, taggedValues)
{
}

public TestSlimElement(string kind, string name, string alias, string notes, IReadOnlyList<SlimTaggedValue> 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>();
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;
}
}
}
27 changes: 27 additions & 0 deletions EA-ModelKit.Tests/Resources/CacheService/TaggedValues.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<EADATA exporter="Enterprise Architect" version="1.0">
<Dataset_0>
<Data>
<Row>
<Object_ID>20</Object_ID>
<Property>"ABC"</Property>
<Value>""</Value>
</Row>
<Row>
<Object_ID>20</Object_ID>
<Property>"CDF"</Property>
<Value>"15"</Value>
</Row>
<Row>
<Object_ID>26</Object_ID>
<Property>"CDF"</Property>
<Value>"16"</Value>
</Row>
<Row>
<Object_ID>10</Object_ID>
<Property>"CDF"</Property>
<Value>"17"</Value>
</Row>
</Data>
</Dataset_0>
</EADATA>
69 changes: 69 additions & 0 deletions EA-ModelKit.Tests/Services/Cache/CacheServiceTestFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="CacheServiceTestFixture.cs" company="Starion Group S.A.">
//
// 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.
//
// </copyright>
// -----------------------------------------------------------------------------------------------

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> repository;

[SetUp]
public void Setup()
{
this.cacheService = new CacheService();
this.repository = new Mock<Repository>();
this.cacheService.Initialize(this.repository.Object);

this.repository.Setup(x => x.SQLQuery(It.Is<string>(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);
}
}
}
Loading