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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ await Retry.For(async () =>
public async Task NavigateToHomePage()
{
await this.Page.GotoAsync($"https://localhost:{this.EstateManagementUiPort}");
await this.VerifyPageTitle("Welcome - Estate Management");
if (TestConfiguration.IsTestMode == false) {
await this.VerifyPageTitle("Welcome - Estate Management");
}
}

public async Task ClickContractsSidebarOption()
Expand Down Expand Up @@ -561,11 +563,7 @@ await Retry.For(async () =>
// Fill in the field based on the tab
if (tab.Equals("Merchant Details", StringComparison.OrdinalIgnoreCase))
{
if (field.Equals("Name", StringComparison.OrdinalIgnoreCase))
{
// For now, skip updating the name as it may require special handling
// The test may need adjustment as the Blazor app might not support name updates
}
await this.Page.FillIn(field, value);
}
else if (tab.Equals("Address Details", StringComparison.OrdinalIgnoreCase))
{
Expand Down
21 changes: 14 additions & 7 deletions EstateManagementUI.BlazorIntegrationTests/Common/DockerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Networks;
using EstateManagementUI.BlazorIntegrationTests.Common;
using EstateManagementUI.BusinessLogic.PermissionService;
using EstateManagementUI.BusinessLogic.PermissionService.Database;
using EstateManagementUI.BusinessLogic.PermissionService.Database.Entities;
Expand All @@ -13,6 +15,9 @@
using SecurityService.Client;
using Shared.Exceptions;
using Shared.IntegrationTesting;
using Shared.IntegrationTesting.TestContainers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -21,10 +26,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Networks;
using Shared.IntegrationTesting.TestContainers;
using TransactionProcessor.Client;

namespace EstateManagementUI.IntegrationTests.Common
Expand Down Expand Up @@ -117,7 +118,10 @@ private static void ExecuteBashCommand(String command)
proc.WaitForExit();
}

public override async Task CreateSubscriptions(){
public override async Task CreateSubscriptions() {
if (TestConfiguration.IsUIOnlyTestMode)
return;

List<(String streamName, String groupName, Int32 maxRetries)> subscriptions = new();
subscriptions.AddRange(MessagingService.IntegrationTesting.Helpers.SubscriptionsHelper.GetSubscriptions());
subscriptions.AddRange(TransactionProcessor.IntegrationTesting.Helpers.SubscriptionsHelper.GetSubscriptions());
Expand All @@ -134,6 +138,9 @@ public override async Task CreateSubscriptions(){

protected override List<String> GetRequiredProjections()
{
if (TestConfiguration.IsUIOnlyTestMode)
return new List<String>();

List<String> requiredProjections = new List<String>();

requiredProjections.Add("EstateAggregator.js");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public async Task StartSystem()
DockerServices.FileProcessor | DockerServices.MessagingService | DockerServices.SecurityService |
DockerServices.TestHost | DockerServices.SqlServer | DockerServices.TransactionProcessor |
DockerServices.TransactionProcessorAcl;
dockerServices = DockerServices.None;

this.TestingContext.DockerHelper = new DockerHelper();
this.TestingContext.DockerHelper.Logger = logger;
Expand Down
140 changes: 120 additions & 20 deletions EstateManagementUI.BlazorIntegrationTests/Common/SharedSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using EstateManagementUI.BlazorIntegrationTests.Common;
using TransactionProcessor.Database.Contexts;
using TransactionProcessor.DataTransferObjects.Requests.Contract;
using TransactionProcessor.DataTransferObjects.Requests.Estate;
Expand Down Expand Up @@ -70,10 +71,21 @@ public SharedSteps(ScenarioContext scenarioContext, TestingContext testingContex
[Given(@"I create the following api resources")]
public async Task GivenICreateTheFollowingApiResources(DataTable table)
{
List<CreateApiResourceRequest> requests = table.Rows.ToCreateApiResourceRequests();
await this.SecurityServiceSteps.GivenTheFollowingApiResourcesExist(requests);
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
List<CreateApiResourceRequest> requests = table.Rows.ToCreateApiResourceRequests();
foreach (CreateApiResourceRequest createApiResourceRequest in requests)
{
this.TestingContext.ApiResources.Add(createApiResourceRequest.Name);
}
return;
}

List<CreateApiResourceRequest> requests2 = table.Rows.ToCreateApiResourceRequests();
await this.SecurityServiceSteps.GivenTheFollowingApiResourcesExist(requests2);

foreach (CreateApiResourceRequest createApiResourceRequest in requests)
foreach (CreateApiResourceRequest createApiResourceRequest in requests2)
{
this.TestingContext.ApiResources.Add(createApiResourceRequest.Name);
}
Expand All @@ -82,15 +94,33 @@ public async Task GivenICreateTheFollowingApiResources(DataTable table)
[Given(@"I create the following api scopes")]
public async Task GivenICreateTheFollowingApiScopes(DataTable table)
{
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
return;
}

List<CreateApiScopeRequest> requests = table.Rows.ToCreateApiScopeRequests();
await this.SecurityServiceSteps.GivenICreateTheFollowingApiScopes(requests);
}

[Given(@"I create the following clients")]
public async Task GivenICreateTheFollowingClients(DataTable table)
{
List<CreateClientRequest> requests = table.Rows.ToCreateClientRequests(this.TestingContext.DockerHelper.TestId, this.TestingContext.DockerHelper.EstateManagementUiPort);
List<(String clientId, String secret, List<String> allowedGrantTypes)> clients = await this.SecurityServiceSteps.GivenTheFollowingClientsExist(requests);
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
// Just track client details locally
List<CreateClientRequest> requests = table.Rows.ToCreateClientRequests(Guid.Empty, 5004);
foreach (var request in requests)
{
this.TestingContext.AddClientDetails(request.ClientId, "Secret1", request.AllowedGrantTypes);
}
return;
}

List<CreateClientRequest> requests2 = table.Rows.ToCreateClientRequests(this.TestingContext.DockerHelper.TestId, this.TestingContext.DockerHelper.EstateManagementUiPort);
List<(String clientId, String secret, List<String> allowedGrantTypes)> clients = await this.SecurityServiceSteps.GivenTheFollowingClientsExist(requests2);
foreach ((String clientId, String secret, List<String> allowedGrantTypes) client in clients)
{
this.TestingContext.AddClientDetails(client.clientId, client.secret, client.allowedGrantTypes);
Expand All @@ -100,6 +130,17 @@ public async Task GivenICreateTheFollowingClients(DataTable table)
[Given(@"I create the following identity resources")]
public async Task GivenICreateTheFollowingIdentityResources(DataTable table)
{
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
foreach (DataTableRow tableRow in table.Rows)
{
String name = ReqnrollTableHelper.GetStringRowValue(tableRow, "Name");
this.TestingContext.IdentityResources.Add(name);
}
return;
}

foreach (DataTableRow tableRow in table.Rows)
{
// Get the scopes
Expand All @@ -120,8 +161,19 @@ public async Task GivenICreateTheFollowingIdentityResources(DataTable table)
[Given(@"I create the following roles")]
public async Task GivenICreateTheFollowingRoles(DataTable table)
{
List<CreateRoleRequest> requests = table.Rows.ToCreateRoleRequests();
List<(String, Guid)> responses = await this.SecurityServiceSteps.GivenICreateTheFollowingRoles(requests, CancellationToken.None);
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
List<CreateRoleRequest> requests = table.Rows.ToCreateRoleRequests();
foreach (var request in requests)
{
this.TestingContext.Roles.Add(request.RoleName, Guid.NewGuid());
}
return;
}

List<CreateRoleRequest> requests2 = table.Rows.ToCreateRoleRequests();
List<(String, Guid)> responses = await this.SecurityServiceSteps.GivenICreateTheFollowingRoles(requests2, CancellationToken.None);

foreach ((String, Guid) response in responses)
{
Expand All @@ -133,6 +185,17 @@ public async Task GivenICreateTheFollowingRoles(DataTable table)
public async Task GivenICreateTheFollowingUsers(DataTable table)
{
List<CreateUserRequest> requests = table.Rows.ToCreateUserRequests();

if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
foreach (CreateUserRequest request in requests)
{
this.TestingContext.Users.Add(request.EmailAddress, Guid.NewGuid());
}
return;
}

foreach (CreateUserRequest createUserRequest in requests)
{
createUserRequest.EmailAddress = createUserRequest.EmailAddress.Replace("[id]", this.TestingContext.DockerHelper.TestId.ToString("N"));
Expand All @@ -156,6 +219,14 @@ public async Task GivenICreateTheFollowingUsers(DataTable table)
[Given(@"I have a token to access the estate management resource")]
public async Task GivenIHaveATokenToAccessTheEstateManagementResource(DataTable table)
{
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
// Set a dummy token since authentication is bypassed
this.TestingContext.AccessToken = "test-mode-token";
return;
}

DataTableRow firstRow = table.Rows.First();
String clientId = ReqnrollTableHelper.GetStringRowValue(firstRow, "ClientId").Replace("[id]", this.TestingContext.DockerHelper.TestId.ToString("N"));
ClientDetails clientDetails = this.TestingContext.GetClientDetails(clientId);
Expand All @@ -168,29 +239,39 @@ public async Task GivenIHaveCreatedTheFollowingEstates(DataTable table)
{
List<CreateEstateRequest> requests = table.Rows.ToCreateEstateRequests();

if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
// Use default estate ID from TestDataStore
foreach (var request in requests)
{
Guid estateId = Guid.Parse("11111111-1111-1111-1111-111111111111");
this.TestingContext.AddEstateDetails(estateId, request.EstateName, request.EstateName);
this.TestingContext.Logger.LogInformation($"Estate {request.EstateName} registered with Id {estateId} (UI-only test mode)");
}
return;
}

List<EstateResponse> verifiedEstates = await this.TransactionProcessorSteps.WhenICreateTheFollowingEstatesX(this.TestingContext.AccessToken, requests);

foreach (EstateResponse verifiedEstate in verifiedEstates)
{
//await Retry.For(async () =>
//{
// String databaseName = $"EstateReportingReadModel{verifiedEstate.EstateId}";
// var connString = Setup.GetLocalConnectionString(databaseName);
// connString = $"{connString};Encrypt=false";
// var ctx = new EstateManagementContext(connString);

// var estates = ctx.Estates.ToList();
// estates.Count.ShouldBe(1);

this.TestingContext.AddEstateDetails(verifiedEstate.EstateId, verifiedEstate.EstateName, verifiedEstate.EstateReference);
this.TestingContext.Logger.LogInformation($"Estate {verifiedEstate.EstateName} created with Id {verifiedEstate.EstateId}");
//});
this.TestingContext.AddEstateDetails(verifiedEstate.EstateId, verifiedEstate.EstateName, verifiedEstate.EstateReference);
this.TestingContext.Logger.LogInformation($"Estate {verifiedEstate.EstateName} created with Id {verifiedEstate.EstateId}");
}
}

[Given(@"I have created the following operators")]
public async Task GivenIHaveCreatedTheFollowingOperators(DataTable table)
{
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
// Operators are pre-populated in TestDataStore
this.TestingContext.Logger.LogInformation("Operators setup skipped (UI-only test mode - using TestDataStore)");
return;
}

List<(EstateDetails estate, CreateOperatorRequest request)> requests = table.Rows.ToCreateOperatorRequests(this.TestingContext.Estates);

List<(Guid, EstateOperatorResponse)> results = await this.TransactionProcessorSteps.WhenICreateTheFollowingOperators(this.TestingContext.AccessToken, requests);
Expand All @@ -204,6 +285,13 @@ public async Task GivenIHaveCreatedTheFollowingOperators(DataTable table)
[Given("I have assigned the following operators to the estates")]
public async Task GivenIHaveAssignedTheFollowingOperatorsToTheEstates(DataTable dataTable)
{
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
this.TestingContext.Logger.LogInformation("Operator assignment skipped (UI-only test mode)");
return;
}

List<(EstateDetails estate, AssignOperatorRequest request)> requests = dataTable.Rows.ToAssignOperatorToEstateRequests(this.TestingContext.Estates);

await this.TransactionProcessorSteps.GivenIHaveAssignedTheFollowingOperatorsToTheEstates(this.TestingContext.AccessToken, requests);
Expand All @@ -216,6 +304,8 @@ public async Task GivenIHaveAssignedTheFollowingOperatorsToTheEstates(DataTable
[When(@"I add the following devices to the merchant")]
public async Task WhenIAddTheFollowingDevicesToTheMerchant(DataTable table)
{
if (TestConfiguration.IsTestMode)
return;
List<(EstateDetails, Guid, AddMerchantDeviceRequest)> requests = table.Rows.ToAddMerchantDeviceRequests(this.TestingContext.Estates);

List<(EstateDetails, MerchantResponse, String)> results = await this.TransactionProcessorSteps.GivenIHaveAssignedTheFollowingDevicesToTheMerchants(this.TestingContext.AccessToken, requests);
Expand All @@ -228,6 +318,8 @@ public async Task WhenIAddTheFollowingDevicesToTheMerchant(DataTable table)
[When(@"I assign the following operator to the merchants")]
public async Task WhenIAssignTheFollowingOperatorToTheMerchants(DataTable table)
{
if (TestConfiguration.IsTestMode)
return;
List<(EstateDetails, Guid, TransactionProcessor.DataTransferObjects.Requests.Merchant.AssignOperatorRequest)> requests = table.Rows.ToAssignOperatorRequests(this.TestingContext.Estates);

List<(EstateDetails, TransactionProcessor.DataTransferObjects.Responses.Merchant.MerchantOperatorResponse)> results = await this.TransactionProcessorSteps.WhenIAssignTheFollowingOperatorToTheMerchants(this.TestingContext.AccessToken, requests);
Expand All @@ -244,6 +336,8 @@ public async Task WhenIAssignTheFollowingOperatorToTheMerchants(DataTable table)
[When(@"I create the following merchants")]
public async Task WhenICreateTheFollowingMerchants(DataTable table)
{
if (TestConfiguration.IsTestMode)
return;
List<(EstateDetails estate, CreateMerchantRequest)> requests = table.Rows.ToCreateMerchantRequests(this.TestingContext.Estates);

List<MerchantResponse> verifiedMerchants = await this.TransactionProcessorSteps.WhenICreateTheFollowingMerchants(this.TestingContext.AccessToken, requests);
Expand All @@ -260,6 +354,12 @@ public async Task WhenICreateTheFollowingMerchants(DataTable table)
[Given("I have created the following security users")]
public async Task WhenICreateTheFollowingSecurityUsers(DataTable table)
{
if (TestConfiguration.SkipRemoteCalls)
{
// Skip remote API call when running in UI-only test mode
this.TestingContext.Logger.LogInformation("Security users creation skipped (UI-only test mode)");
return;
}

List<CreateNewUserRequest> createUserRequests = table.Rows.ToCreateNewUserRequests(this.TestingContext.Estates);
await this.TransactionProcessorSteps.WhenICreateTheFollowingSecurityUsers(this.TestingContext.AccessToken, createUserRequests, this.TestingContext.Estates);
Expand Down
Loading
Loading