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 creating AAS service provider
Changed the implementation of the AAS repository service provider to use a factory instead of an extension method for service provider creation References eclipse-basyx#3
- Loading branch information
1 parent
cba29ea
commit 381967e
Showing
4 changed files
with
123 additions
and
8 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
BaSyx.API/Components/ServiceProvider/IAssetAdministrationShellServiceProviderFactory.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,28 @@ | ||
// /******************************************************************************* | ||
// * Copyright (c) 2022 LTSoft - Agentur für Leittechnik-Software GmbH | ||
// * Author: Björn Höper | ||
// * | ||
// * 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.AssetAdministrationShell.Extensions; | ||
using BaSyx.Models.Core.AssetAdministrationShell.Generics; | ||
|
||
namespace BaSyx.API.Components; | ||
|
||
/// <summary> | ||
/// Creates service providers for Asset Administration Shells | ||
/// </summary> | ||
public interface IAssetAdministrationShellServiceProviderFactory | ||
{ | ||
/// <summary> | ||
/// Create a new service provider for the AAS | ||
/// </summary> | ||
/// <param name="aas">Asset administration shell to create the service provider for</param> | ||
/// <returns>Created service provider</returns> | ||
public IAssetAdministrationShellServiceProvider CreateServiceProvider(IAssetAdministrationShell aas, bool includeSubmodels); | ||
} |
45 changes: 45 additions & 0 deletions
45
....API/Components/ServiceProvider/InternalAssetAdministrationShellServiceProviderFactory.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,45 @@ | ||
// /******************************************************************************* | ||
// * Copyright (c) 2022 LTSoft - Agentur für Leittechnik-Software GmbH | ||
// * Author: Björn Höper | ||
// * | ||
// * 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 System.Linq; | ||
using BaSyx.Models.Core.AssetAdministrationShell.Generics; | ||
|
||
namespace BaSyx.API.Components; | ||
|
||
/// <summary> | ||
/// Creates internal In-Memory providers for the AAS | ||
/// </summary> | ||
public class InternalAssetAdministrationShellServiceProviderFactory : IAssetAdministrationShellServiceProviderFactory | ||
{ | ||
private readonly ISubmodelServiceProviderFactory _submodelServiceProviderFactory; | ||
|
||
public InternalAssetAdministrationShellServiceProviderFactory(ISubmodelServiceProviderFactory submodelServiceProviderFactory) | ||
{ | ||
_submodelServiceProviderFactory = submodelServiceProviderFactory; | ||
} | ||
|
||
public IAssetAdministrationShellServiceProvider CreateServiceProvider(IAssetAdministrationShell aas, | ||
bool includeSubmodels) | ||
{ | ||
InternalAssetAdministrationShellServiceProvider sp = new InternalAssetAdministrationShellServiceProvider(aas); | ||
|
||
if (includeSubmodels && aas.Submodels.Any()) | ||
{ | ||
foreach (var submodel in aas.Submodels.Values) | ||
{ | ||
var submodelSp = _submodelServiceProviderFactory.CreateSubmodelServiceProvider(submodel); | ||
sp.RegisterSubmodelServiceProvider(submodel.IdShort, submodelSp); | ||
} | ||
} | ||
|
||
return sp; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ests/Components/ServiceProvider/AssetAdministrationShellRepositoryServiceProviderTests.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,40 @@ | ||
// /******************************************************************************* | ||
// * Copyright (c) 2022 LTSoft - Agentur für Leittechnik-Software GmbH | ||
// * Author: Björn Höper | ||
// * | ||
// * 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 Moq; | ||
|
||
namespace Basyx.API.Tests.Components.ServiceProvider; | ||
|
||
public class AssetAdministrationShellRepositoryServiceProviderTests | ||
{ | ||
[Fact] | ||
public async Task CreateAssetAdministrationShell_WhenSuccess_CallsFactory() | ||
{ | ||
var aasMock = new Mock<IAssetAdministrationShell>(); | ||
aasMock.Setup(a => a.Identification) | ||
.Returns(new Identifier("http://assetadminshell.io/1/0/0/testshell", KeyType.URI)); | ||
|
||
var serviceProviderMock = new Mock<IAssetAdministrationShellServiceProvider>(); | ||
serviceProviderMock.Setup(p => p.GetBinding()).Returns(aasMock.Object); | ||
|
||
var factoryMock = new Mock<IAssetAdministrationShellServiceProviderFactory>(); | ||
factoryMock.Setup(f => f.CreateServiceProvider(aasMock.Object, true)).Returns(serviceProviderMock.Object); | ||
|
||
var aasRepoProvider = new AssetAdministrationShellRepositoryServiceProvider(factoryMock.Object); | ||
var result = aasRepoProvider.CreateAssetAdministrationShell(aasMock.Object); | ||
|
||
factoryMock.Verify(f => f.CreateServiceProvider(aasMock.Object, true), Times.AtLeastOnce); | ||
Assert.Equal(aasMock.Object, result.Entity); | ||
} | ||
} |