generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet): add existence check for wallet creation (#71)
Refs: #66 Reviewed-By: Evelyn Gurschler <[email protected]>
- Loading branch information
Showing
9 changed files
with
253 additions
and
1 deletion.
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
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
20 changes: 20 additions & 0 deletions
20
tests/processes/DimProcess.Executor.Tests/DimProcess.Executor.Tests.csproj
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
20 changes: 20 additions & 0 deletions
20
tests/processes/DimProcess.Library.Tests/DimProcess.Library.Tests.csproj
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,51 @@ | ||
<!-- | ||
- Copyright (c) 2024 BMW Group AG | ||
- Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. | ||
- | ||
- See the NOTICE file(s) distributed with this work for additional | ||
- information regarding copyright ownership. | ||
- | ||
- This program and the accompanying materials are made available under the | ||
- terms of the Apache License, Version 2.0 which is available at | ||
- https://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. | ||
- | ||
- SPDX-License-Identifier: Apache-2.0 | ||
--> | ||
|
||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<RootNamespace>Dim.Web.Tests</RootNamespace> | ||
<AssemblyName>Dim.Web.Tests</AssemblyName> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="AutoFixture.AutoFakeItEasy" Version="4.18.1" /> | ||
<PackageReference Include="FakeItEasy" Version="8.1.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" /> | ||
<PackageReference Include="xunit" Version="2.7.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\clients\Dim.Clients\Dim.Clients.csproj" /> | ||
<ProjectReference Include="..\..\..\src\database\Dim.DbAccess\Dim.DbAccess.csproj" /> | ||
<ProjectReference Include="..\..\..\src\web\Dim.Web\Dim.Web.csproj" /> | ||
<ProjectReference Include="..\..\shared\Tests.Shared\Tests.Shared.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,119 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 BMW Group AG | ||
* Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Dim.Clients.Api.Cf; | ||
using Dim.Clients.Api.Dim; | ||
using Dim.DbAccess; | ||
using Dim.DbAccess.Repositories; | ||
using Dim.Entities.Entities; | ||
using Dim.Entities.Enums; | ||
using Dim.Web.BusinessLogic; | ||
using Microsoft.Extensions.Options; | ||
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; | ||
|
||
namespace Dim.Web.Tests; | ||
|
||
public class DimBusinessLogicTests | ||
{ | ||
private static readonly Guid OperatorId = Guid.NewGuid(); | ||
private readonly IDimBusinessLogic _sut; | ||
private readonly ICfClient _cfClient; | ||
private readonly IDimClient _dimClient; | ||
private readonly ITenantRepository _tenantRepository; | ||
private readonly IProcessStepRepository _processStepRepository; | ||
|
||
public DimBusinessLogicTests() | ||
{ | ||
var fixture = new Fixture().Customize(new AutoFakeItEasyCustomization { ConfigureMembers = true }); | ||
fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList() | ||
.ForEach(b => fixture.Behaviors.Remove(b)); | ||
fixture.Behaviors.Add(new OmitOnRecursionBehavior()); | ||
|
||
var repositories = A.Fake<IDimRepositories>(); | ||
_dimClient = A.Fake<IDimClient>(); | ||
_cfClient = A.Fake<ICfClient>(); | ||
|
||
_tenantRepository = A.Fake<ITenantRepository>(); | ||
_processStepRepository = A.Fake<IProcessStepRepository>(); | ||
|
||
A.CallTo(() => repositories.GetInstance<ITenantRepository>()).Returns(_tenantRepository); | ||
A.CallTo(() => repositories.GetInstance<IProcessStepRepository>()).Returns(_processStepRepository); | ||
|
||
_sut = new DimBusinessLogic(repositories, _cfClient, _dimClient, Options.Create(new DimSettings | ||
{ | ||
OperatorId = OperatorId | ||
})); | ||
} | ||
|
||
[Fact] | ||
public async Task StartSetupDim_WithExisting_ThrowsConflictException() | ||
{ | ||
// Arrange | ||
A.CallTo(() => _tenantRepository.IsTenantExisting(A<string>._, A<string>._)) | ||
.Returns(true); | ||
async Task Act() => await _sut.StartSetupDim("testCompany", "BPNL00000001TEST", "https://example.org/test", false); | ||
|
||
// Act | ||
var result = await Assert.ThrowsAsync<ConflictException>(Act); | ||
|
||
// Assert | ||
result.Message.Should().Be($"Tenant testCompany with Bpn BPNL00000001TEST already exists"); | ||
} | ||
|
||
[Fact] | ||
public async Task StartSetupDim_WithNewData_CreatesExpected() | ||
{ | ||
// Arrange | ||
var processId = Guid.NewGuid(); | ||
var processes = new List<Process>(); | ||
var processSteps = new List<ProcessStep>(); | ||
var tenants = new List<Tenant>(); | ||
A.CallTo(() => _tenantRepository.IsTenantExisting(A<string>._, A<string>._)) | ||
.Returns(false); | ||
A.CallTo(() => _processStepRepository.CreateProcess(A<ProcessTypeId>._)) | ||
.Invokes((ProcessTypeId processTypeId) => | ||
{ | ||
processes.Add(new Process(processId, processTypeId, Guid.NewGuid())); | ||
}); | ||
A.CallTo(() => _processStepRepository.CreateProcessStep(A<ProcessStepTypeId>._, A<ProcessStepStatusId>._, A<Guid>._)) | ||
.Invokes((ProcessStepTypeId processStepTypeId, ProcessStepStatusId processStepStatusId, Guid pId) => | ||
{ | ||
processSteps.Add(new ProcessStep(Guid.NewGuid(), processStepTypeId, processStepStatusId, processId, DateTimeOffset.UtcNow)); | ||
}); | ||
A.CallTo(() => | ||
_tenantRepository.CreateTenant(A<string>._, A<string>._, A<string>._, A<bool>._, A<Guid>._, A<Guid>._)) | ||
.Invokes((string companyName, string bpn, string didDocumentLocation, bool isIssuer, Guid pId, | ||
Guid operatorId) => | ||
{ | ||
tenants.Add(new Tenant(Guid.NewGuid(), companyName, bpn, didDocumentLocation, isIssuer, pId, operatorId)); | ||
}); | ||
|
||
// Act | ||
await _sut.StartSetupDim("testCompany", "BPNL00000001TEST", "https://example.org/test", false); | ||
|
||
// Assert | ||
processes.Should().ContainSingle() | ||
.Which.ProcessTypeId.Should().Be(ProcessTypeId.SETUP_DIM); | ||
processSteps.Should().ContainSingle() | ||
.And.Satisfy(x => x.ProcessId == processId && x.ProcessStepTypeId == ProcessStepTypeId.CREATE_SUBACCOUNT); | ||
tenants.Should().ContainSingle() | ||
.And.Satisfy(x => x.CompanyName == "testCompany" && x.Bpn == "BPNL00000001TEST"); | ||
} | ||
} |
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,25 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 BMW Group AG | ||
* Copyright 2024 SAP SE or an SAP affiliate company and ssi-dim-middle-layer contributors. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://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. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
global using AutoFixture; | ||
global using AutoFixture.AutoFakeItEasy; | ||
global using FakeItEasy; | ||
global using FluentAssertions; | ||
global using Xunit; |