Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4: SelectionService implemented #6

Merged
merged 11 commits into from
Dec 3, 2024
7 changes: 5 additions & 2 deletions .github/workflows/CodeQuality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: add DevExpress nuget feed
run: dotnet nuget add source https://nuget.devexpress.com/api -n DXFeed -u DevExpress -p ${{ secrets.DEVEXPRESS_NUGET_KEY }} --store-password-in-clear-text

- name: Setup DotCover
run: dotnet tool install --global JetBrains.dotCover.GlobalTool

- name: Restore dependencies
run: nuget restore ea-modelkit.sln

Expand All @@ -41,13 +44,13 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /k:"STARIONGROUP_ea-modelkit" /o:"stariongroup" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="./CoverageResults/coverage.opencover.xml"
dotnet sonarscanner begin /k:"STARIONGROUP_ea-modelkit" /o:"stariongroup" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths=dotCover.Output.html

- name: Build
run: msbuild ea-modelkit.sln -property:Configuration=CICD -property:platform="Any CPU" /p:RestorePackages=false

- name: Run Tests and Compute Coverage
run: vstest.console.exe EA-ModelKit.Tests\bin\CICD\net481\EAModelKit.Tests.dll /Platform:x64 /EnableCodeCoverage
run: dotnet dotcover test --dcReportType=HTML -c CICD --dcAttributeFilters=System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute

- name: Sonarqube end
run: dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
28 changes: 18 additions & 10 deletions EA-ModelKit.Tests/EA-ModelKit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,37 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NunitXml.TestLogger" Version="4.1.0" />
<PackageReference Include="NUnit" Version="4.2.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0"/>
<PackageReference Include="Moq" Version="4.20.72"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="NunitXml.TestLogger" Version="4.1.0"/>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EA-ModelKit\EA-ModelKit.csproj" />
<ProjectReference Include="..\EA-ModelKit\EA-ModelKit.csproj"/>
</ItemGroup>

<ItemGroup>
<Folder Include="Services\" />
<Reference Include="Interop.EA">
<HintPath>..\lib\Interop.EA.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Reference Include="Interop.EA">
<HintPath>..\lib\Interop.EA.dll</HintPath>
</Reference>
<None Update="Resources\SelectionService\AllExistingPackages.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\SelectionService\AllSelectedElements.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Resources\SelectionService\EmptyElements.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="ContainerBuilderExtensionsTestFixture.cs" company="Starion Group S.A.">
//
// Copyright 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, softwareUseCases
// 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.Extensions
{
using Autofac;

using EAModelKit.Extensions;

using NUnit.Framework;

[TestFixture]
public class ContainerBuilderExtensionsTestFixture
{
private ContainerBuilder containerBuilder;

[SetUp]
public void SetUp()
{
this.containerBuilder = new ContainerBuilder();
}

[Test]
public void VerifyContainerBuilderExtensions()
{
Assert.Multiple(() =>
{
Assert.That(() => this.containerBuilder.RegisterViewModels(), Throws.Nothing);
Assert.That(() => this.containerBuilder.RegisterServices(), Throws.Nothing);
Assert.That(() => this.containerBuilder.Build(), Throws.Nothing);
});
}
}
}
192 changes: 192 additions & 0 deletions EA-ModelKit.Tests/Helpers/TestCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="TestCollection.cs" company="Starion Group S.A.">
//
// Copyright 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, softwareUseCases
// 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 System.Collections;
using System.Diagnostics.CodeAnalysis;

using EA;

using Moq;

/// <summary>
/// Class that is there to facilitate unit tests when touching <see cref="Collection"/>, since all constructors for all EA classes are internal
/// </summary>
[ExcludeFromCodeCoverage]
public class TestCollection : Collection
{
/// <summary>
/// A containedObjects of the contained object
/// </summary>
private readonly List<object> containedObjects;

/// <summary>
/// Initializes a new instance of the <see cref="TestCollection" /> class.
/// </summary>
public TestCollection()
{
this.containedObjects = [];
}

/// <summary>
/// Initializes a new instance of the <see cref="TestCollection" /> class.
/// </summary>
/// <param name="objects">A collection of <see cref="object"/></param>
public TestCollection(IEnumerable<object> objects)
{
this.containedObjects = objects.ToList();
}

/// <summary>
/// Gets the number of contained objects
/// </summary>
public short Count => (short)this.containedObjects.Count;

/// <summary>
/// Gets the <see cref="ObjectType" /> of contained objects
/// </summary>
public ObjectType ObjectType => 0;

/// <summary>
/// Retrieves a contained object at the given index
/// </summary>
/// <param name="index">The index of the object</param>
/// <returns>The contained object</returns>
public object GetAt(short index)
{
return this.IsIndexInRange(index) ? this.containedObjects[index] : null;
}

/// <summary>
/// Removes a contained object
/// </summary>
/// <param name="index">The index of the object</param>
/// <param name="refresh">Not used</param>
public void DeleteAt(short index, bool refresh)
{
if (!this.IsIndexInRange(index))
{
return;
}

this.containedObjects.RemoveAt(index);
}

/// <summary>
/// Gets the last occured error (Not used)
/// </summary>
/// <returns>null</returns>
public string GetLastError()
{
return null;
}

/// <summary>
/// Gets a object by his name (Not used)
/// </summary>
/// <param name="name">The name of the object</param>
/// <returns>null</returns>
public object GetByName(string name)
{
foreach (var containedObject in this.containedObjects)
{
if (containedObject is TaggedValue taggedValue && taggedValue.Name == name)
{
return taggedValue;
}
}

return null;
}

/// <summary>
/// Refresh the collection (Not used)
/// </summary>
public void Refresh()
{
}

/// <summary>
/// Adds a new object to the contained objects
/// </summary>
/// <param name="Name">The name of the object</param>
/// <param name="Type">The Type if the object</param>
/// <returns>The created object</returns>
public object AddNew(string Name, string Type)
{
if (Type == nameof(TaggedValue))
{
var newTaggedValue = new Mock<TaggedValue>();
newTaggedValue.Setup(x => x.Name).Returns(Name);
this.Add(newTaggedValue.Object);
return newTaggedValue.Object;
}

return null;
}

/// <summary>
/// Removes a contained object
/// </summary>
/// <param name="index">The index of the objects to removed</param>
public void Delete(short index)
{
this.DeleteAt(index, false);
}

/// <summary>
/// Gets the <see cref="IEnumerator" /> to iterate through the collection
/// </summary>
/// <returns>The <see cref="IEnumerator" /></returns>
public IEnumerator GetEnumerator()
{
return this.containedObjects.GetEnumerator();
}

/// <summary>
/// Adds an object to the contained Object
/// </summary>
/// <param name="newObject">The new object</param>
public void Add(object newObject)
{
this.containedObjects.Add(newObject);
}

/// <summary>
/// Adds a collection of object
/// </summary>
/// <param name="objects">The collection to add</param>
public void AddRange(IEnumerable<object> objects)
{
this.containedObjects.AddRange(objects);
}

/// <summary>
/// Asserts if the given index is in range of the <see cref="containedObjects" /> collection
/// </summary>
/// <param name="index">The index</param>
/// <returns>Asserts that the index is in range</returns>
private bool IsIndexInRange(short index)
{
return index >= 0 && index < this.containedObjects.Count;
}
}
}
Loading