forked from eclipse-basyx/basyx-dotnet-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factory for submodel service provider
Changed the implementation to use submodel service provider for creating provider for submodels instead of extension method and added tests for that References eclipse-basyx#3
- Loading branch information
1 parent
c9b374d
commit 938fbcb
Showing
7 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
BaSyx.API/Components/ServiceProvider/ISubmodelServiceProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 LTSoft - Agrentur für Leittechnik-Software GmbH | ||
* Author: Björn Höper ([email protected]) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
using BaSyx.Models.Core.AssetAdministrationShell.Generics; | ||
|
||
namespace BaSyx.API.Components; | ||
|
||
/// <summary> | ||
/// Creates service providers for submodels | ||
/// </summary> | ||
public interface ISubmodelServiceProviderFactory | ||
{ | ||
/// <summary> | ||
/// Create a new submodel service provider for | ||
/// </summary> | ||
/// <param name="submodel"></param> | ||
/// <returns></returns> | ||
ISubmodelServiceProvider CreateSubmodelServiceProvider(ISubmodel submodel); | ||
} |
27 changes: 27 additions & 0 deletions
27
BaSyx.API/Components/ServiceProvider/InternalSubmodelServiceProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 LTSoft - Agrentur für Leittechnik-Software GmbH | ||
* Author: Björn Höper ([email protected]) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
using BaSyx.Models.Core.AssetAdministrationShell.Generics; | ||
|
||
namespace BaSyx.API.Components; | ||
|
||
/// <summary> | ||
/// Provides the internal submodel service provider as default implementation | ||
/// </summary> | ||
public class InternalSubmodelServiceProviderFactory : ISubmodelServiceProviderFactory | ||
{ | ||
public ISubmodelServiceProvider CreateSubmodelServiceProvider(ISubmodel submodel) | ||
{ | ||
InternalSubmodelServiceProvider sp = new InternalSubmodelServiceProvider(submodel); | ||
|
||
return sp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" /> | ||
<PackageReference Include="Moq" Version="4.18.2" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Components\ServiceProvider\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\BaSyx.API\BaSyx.API.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
42 changes: 42 additions & 0 deletions
42
tests/Basyx.API.Tests/Components/ServiceProvider/SubmodelRepositoryServiceProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 LTSoft - Agrentur für Leittechnik-Software GmbH | ||
* Author: Björn Höper ([email protected]) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
using BaSyx.API.Components; | ||
using BaSyx.Models.Core.AssetAdministrationShell.Generics; | ||
using BaSyx.Models.Core.AssetAdministrationShell.Identification; | ||
using BaSyx.Models.Core.AssetAdministrationShell.Implementations; | ||
using Moq; | ||
|
||
namespace Basyx.API.Tests.Components.ServiceProvider; | ||
|
||
public class SubmodelRepositoryServiceProviderTests | ||
{ | ||
[Fact] | ||
public async Task CreateSubmodel_WhenCorrect_CallsFactory() | ||
{ | ||
var submodelMock = new Mock<ISubmodel>(); | ||
submodelMock.Setup(s => s.Identification) | ||
.Returns(new Identifier("http://assetadminshell.io/1/0/0/testmodel", KeyType.URI)); | ||
|
||
var serviceProviderMock = new Mock<ISubmodelServiceProvider>(); | ||
serviceProviderMock.Setup(p => p.GetBinding()).Returns(submodelMock.Object); | ||
|
||
var factoryMock = new Mock<ISubmodelServiceProviderFactory>(); | ||
factoryMock.Setup(f => f.CreateSubmodelServiceProvider(submodelMock.Object)).Returns(serviceProviderMock.Object); | ||
|
||
var submodelRepositoryServiceProvider = new SubmodelRepositoryServiceProvider(factoryMock.Object); | ||
var result = submodelRepositoryServiceProvider.CreateSubmodel(submodelMock.Object); | ||
|
||
factoryMock.Verify(f => f.CreateSubmodelServiceProvider(submodelMock.Object), Times.AtLeastOnce); | ||
|
||
Assert.Equal(submodelMock.Object, result.Entity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |