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
7 changes: 5 additions & 2 deletions src/web/Dim.Web/BusinessLogic/DimBusinessLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ private static string GetName(string name, string? additionalName = null)

public async Task<ProcessData> GetSetupProcess(string bpn, string companyName)
{
var processData = await dimRepositories.GetInstance<ITenantRepository>().GetWalletProcessForTenant(bpn, companyName)
var tenant = GetName(companyName, bpn);
var processData = await dimRepositories.GetInstance<ITenantRepository>().GetWalletProcessForTenant(bpn, tenant)
.ConfigureAwait(ConfigureAwaitOptions.None);
if (processData == null)
{
Expand All @@ -198,7 +199,9 @@ public async Task<ProcessData> GetSetupProcess(string bpn, string companyName)

public async Task<ProcessData> GetTechnicalUserProcess(string bpn, string companyName, string technicalUserName)
{
var processData = await dimRepositories.GetInstance<ITechnicalUserRepository>().GetTechnicalUserProcess(bpn, companyName, technicalUserName)
var tenant = GetName(companyName, bpn);
var techUserName = GetName(technicalUserName, bpn);
var processData = await dimRepositories.GetInstance<ITechnicalUserRepository>().GetTechnicalUserProcess(bpn, tenant, techUserName)
.ConfigureAwait(ConfigureAwaitOptions.None);
if (processData == null)
{
Expand Down
63 changes: 43 additions & 20 deletions tests/web/Dim.Web.Tests/DimBusinessLogicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,21 @@ private WalletData GetWalletData()
return new WalletData("https://example.org/token", "cl1", secret, initializationVector, 0);
}

private static string GetName(string name, string additionalName)
{
// Use reflection to call the private GetName method
var getNameMethod = typeof(DimBusinessLogic)
.GetMethod("GetName", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

if (getNameMethod == null)
throw new InvalidOperationException("GetName method not found on DimBusinessLogic.");

var normalizedTenantObj = getNameMethod.Invoke(null, new object[] { name, additionalName });
if (normalizedTenantObj is not string normalizedName)
throw new InvalidOperationException("GetName method did not return a string.");
return normalizedName;
}

#region GetSetupProcess

[Fact]
Expand All @@ -439,16 +454,16 @@ public async Task GetSetupProcess_WithValidBpnAndCompanyName_ReturnsExpectedProc
const string Bpn = "BPNL00000001TEST";
const string CompanyName = "testCompany";
var expectedProcessData = _fixture.Create<ProcessData>();

A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
var normalizedName = GetName(CompanyName, Bpn);
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
.Returns(expectedProcessData);

// Act
var result = await _sut.GetSetupProcess(Bpn, CompanyName);

// Assert
result.Should().BeEquivalentTo(expectedProcessData);
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -460,7 +475,8 @@ public async Task GetSetupProcess_WithValidBpnAndCompanyName_ReturnsExpectedProc
public async Task GetSetupProcess_WithInvalidInput_ThrowsNotFoundException(string bpn, string companyName)
{
// Arrange
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
var normalizedName = GetName(companyName, bpn);
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
.Returns(Task.FromResult<ProcessData?>(null));

// Act
Expand All @@ -469,7 +485,7 @@ public async Task GetSetupProcess_WithInvalidInput_ThrowsNotFoundException(strin
// Assert
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_COMPANY));
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -479,8 +495,8 @@ public async Task GetSetupProcess_WithNonExistingProcess_ThrowsNotFoundException
// Arrange
const string Bpn = "BPNL00000001TEST";
const string CompanyName = "nonExistingCompany";

A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
var normalizedName = GetName(CompanyName, Bpn);
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
.Returns(Task.FromResult<ProcessData?>(null));

// Act
Expand All @@ -489,7 +505,7 @@ public async Task GetSetupProcess_WithNonExistingProcess_ThrowsNotFoundException
// Assert
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_COMPANY));
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, CompanyName))
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(Bpn, normalizedName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -501,16 +517,16 @@ public async Task GetSetupProcess_WithDifferentValidInputs_ReturnsCorrectProcess
{
// Arrange
var expectedProcessData = _fixture.Create<ProcessData>();

A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
var normalizedName = GetName(companyName, bpn);
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
.Returns(expectedProcessData);

// Act
var result = await _sut.GetSetupProcess(bpn, companyName);

// Assert
result.Should().BeEquivalentTo(expectedProcessData);
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, companyName))
A.CallTo(() => _tenantRepository.GetWalletProcessForTenant(bpn, normalizedName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -525,17 +541,19 @@ public async Task GetTechnicalUserProcess_WithValidBpnAndCompanyName_ReturnsExpe
const string Bpn = "BPNL00000001TEST";
const string CompanyName = "testCompany";
const string TechnicalUserName = "testUser";
var normalizedName = GetName(CompanyName, Bpn);
var normalizedTechName = GetName(TechnicalUserName, Bpn);
var expectedProcessData = _fixture.Create<ProcessData>();

A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
.Returns(expectedProcessData);

// Act
var result = await _sut.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName);

// Assert
result.Should().BeEquivalentTo(expectedProcessData);
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -549,7 +567,9 @@ public async Task GetTechnicalUserProcess_WithValidBpnAndCompanyName_ReturnsExpe
public async Task GetTechnicalUserProcess_WithInvalidInput_ThrowsNotFoundException(string bpn, string companyName, string technicalUserName)
{
// Arrange
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
var normalizedName = GetName(companyName, bpn);
var normalizedTechName = GetName(technicalUserName, bpn);
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
.Returns(Task.FromResult<ProcessData?>(null));

// Act
Expand All @@ -558,7 +578,7 @@ public async Task GetTechnicalUserProcess_WithInvalidInput_ThrowsNotFoundExcepti
// Assert
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_TECHNICAL_USER));
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -569,8 +589,9 @@ public async Task GetTechnicalUserProcess_WithNonExistingProcess_ThrowsNotFoundE
const string Bpn = "BPNL00000001TEST";
const string CompanyName = "testCompany";
const string TechnicalUserName = "nonExistingTechUser";

A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
var normalizedName = GetName(CompanyName, Bpn);
var normalizedTechName = GetName(TechnicalUserName, Bpn);
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
.Returns(Task.FromResult<ProcessData?>(null));

// Act
Expand All @@ -579,7 +600,7 @@ public async Task GetTechnicalUserProcess_WithNonExistingProcess_ThrowsNotFoundE
// Assert
var exception = await Assert.ThrowsAsync<NotFoundException>(Act);
exception.Message.Should().Be(nameof(DimErrors.NO_PROCESS_FOR_TECHNICAL_USER));
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, CompanyName, TechnicalUserName))
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(Bpn, normalizedName, normalizedTechName))
.MustHaveHappenedOnceExactly();
}

Expand All @@ -590,17 +611,19 @@ public async Task GetTechnicalUserProcess_WithNonExistingProcess_ThrowsNotFoundE
public async Task GetTechnicalUserProcess_WithDifferentValidInputs_ReturnsCorrectProcessData(string bpn, string companyName, string technicalUserName)
{
// Arrange
var normalizedName = GetName(companyName, bpn);
var normalizedTechName = GetName(technicalUserName, bpn);
var expectedProcessData = _fixture.Create<ProcessData>();

A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
.Returns(expectedProcessData);

// Act
var result = await _sut.GetTechnicalUserProcess(bpn, companyName, technicalUserName);

// Assert
result.Should().BeEquivalentTo(expectedProcessData);
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, companyName, technicalUserName))
A.CallTo(() => _technicalUserRepository.GetTechnicalUserProcess(bpn, normalizedName, normalizedTechName))
.MustHaveHappenedOnceExactly();
}

Expand Down
Loading