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
3 changes: 3 additions & 0 deletions EstateManagementUI.BlazorServer.Tests/Pages/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected BaseTest() {
this.Services.AddSingleton(this.EstateUIService.Object);
this.Services.AddSingleton(this.OperatorUIService.Object);
this.Services.AddSingleton(this.ContractUIService.Object);
this.Services.AddSingleton(this.MerchantUIService.Object);


// Add required permission components that render their children
Expand All @@ -57,6 +58,8 @@ protected BaseTest() {
protected readonly Mock<IEstateUIService> EstateUIService = new Mock<IEstateUIService>();
protected readonly Mock<IOperatorUIService> OperatorUIService = new Mock<IOperatorUIService>();
protected readonly Mock<IContractUIService> ContractUIService = new Mock<IContractUIService>();
protected readonly Mock<IMerchantUIService> MerchantUIService = new Mock<IMerchantUIService>();

/// <summary>
/// Minimal test double for NavigationManager.
/// Register in DI as NavigationManager so components receive it in tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bunit;
using EstateManagementUI.BlazorServer.Components.Permissions;
using EstateManagementUI.BlazorServer.Models;
using EstateManagementUI.BlazorServer.Permissions;
using EstateManagementUI.BlazorServer.Tests.Pages.FileProcessing;
using EstateManagementUI.BusinessLogic.BackendAPI.DataTransferObjects;
Expand All @@ -21,16 +22,19 @@ public class MerchantsIndexPageTests : BaseTest
public void MerchantsIndex_InitialState_ShowsLoadingIndicator()
{
// Arrange
var merchants = new List<MerchantListModel>
var merchants = new List<MerchantModels.MerchantListModel>
{
new MerchantListModel
{
new() {
MerchantId = Guid.NewGuid(),
MerchantName = "Test Merchant"
}
};

_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));

// Act
Expand All @@ -44,8 +48,12 @@ public void MerchantsIndex_InitialState_ShowsLoadingIndicator()
public void MerchantsIndex_WithNoMerchants_ShowsEmptyState()
{
// Arrange
var merchants = new List<MerchantListModel>();
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
var merchants = new List<MerchantModels.MerchantListModel>();
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));

// Act
Expand All @@ -60,25 +68,30 @@ public void MerchantsIndex_WithNoMerchants_ShowsEmptyState()
public void MerchantsIndex_WithMerchants_DisplaysMerchantList()
{
// Arrange
var merchants = new List<MerchantListModel>
var merchants = new List<MerchantModels.MerchantListModel>
{
new MerchantListModel()
new MerchantModels.MerchantListModel()
{
MerchantId = Guid.NewGuid(),
MerchantName = "Test Merchant 1",
MerchantReference = "REF001"
},
new MerchantListModel()
new MerchantModels.MerchantListModel()
{
MerchantId = Guid.NewGuid(),
MerchantName = "Test Merchant 2",
MerchantReference = "REF002"
}
};

_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));


// Act
var cut = RenderComponent<MerchantsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand All @@ -94,7 +107,7 @@ public void MerchantsIndex_WithMerchants_DisplaysMerchantList()
public void MerchantsIndex_WithMerchants_DisplaysSummaryCards()
{
// Arrange
var merchants = new List<MerchantListModel>
var merchants = new List<MerchantModels.MerchantListModel>
{
new()
{
Expand All @@ -108,9 +121,14 @@ public void MerchantsIndex_WithMerchants_DisplaysSummaryCards()
}
};

_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));


// Act
var cut = RenderComponent<MerchantsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand All @@ -125,9 +143,14 @@ public void MerchantsIndex_WithMerchants_DisplaysSummaryCards()
public void MerchantsIndex_HasCorrectPageTitle()
{
// Arrange
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantListModel>()));

this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(new List<MerchantModels.MerchantListModel>()));


// Act
var cut = RenderComponent<MerchantsIndex>();

Expand All @@ -140,18 +163,23 @@ public void MerchantsIndex_HasCorrectPageTitle()
public void MerchantsIndex_WithMerchants_DisplaysFilters()
{
// Arrange
var merchants = new List<MerchantListModel>
var merchants = new List<MerchantModels.MerchantListModel>
{
new MerchantListModel()
new()
{
MerchantId = Guid.NewGuid(),
MerchantName = "Test Merchant"
}
};

_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));


// Act
var cut = RenderComponent<MerchantsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand All @@ -169,15 +197,20 @@ public void MerchantsIndex_WithMerchants_DisplaysFilters()
public void MerchantsIndex_WithManyMerchants_DisplaysPagination()
{
// Arrange - Create more than 10 merchants to trigger pagination
var merchants = Enumerable.Range(1, 12).Select(i => new MerchantListModel()
var merchants = Enumerable.Range(1, 12).Select(i => new MerchantModels.MerchantListModel()
{
MerchantId = Guid.NewGuid(),
MerchantName = $"Merchant {i}"
}).ToList();

_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));


// Act
var cut = RenderComponent<MerchantsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand All @@ -192,9 +225,9 @@ public void MerchantsIndex_WithManyMerchants_DisplaysPagination()
public void MerchantsIndex_WithMerchants_DisplaysRegionAndPostcode()
{
// Arrange
var merchants = new List<MerchantListModel>
var merchants = new List<MerchantModels.MerchantListModel>
{
new MerchantListModel
new()
{
MerchantId = Guid.NewGuid(),
MerchantName = "Test Merchant",
Expand All @@ -203,9 +236,14 @@ public void MerchantsIndex_WithMerchants_DisplaysRegionAndPostcode()
}
};

_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantsQuery>(), default))
this.MerchantUIService.Setup(m => m.GetMerchants(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Int32>(),
It.IsAny<String>(),
It.IsAny<String>()))
.ReturnsAsync(Result.Success(merchants));


// Act
var cut = RenderComponent<MerchantsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using EstateManagementUI.BlazorServer.Components.Pages.Merchants;
using EstateManagementUI.BlazorServer.Models;
using EstateManagementUI.BlazorServer.Tests.Pages.FileProcessing;
using EstateManagementUI.BusinessLogic.BackendAPI.DataTransferObjects;
using EstateManagementUI.BusinessLogic.Models;
using EstateManagementUI.BusinessLogic.Requests;
using MediatR;
Expand All @@ -24,21 +25,18 @@ public void MerchantsView_InitialState_ShowsLoadingIndicator()
{
// Arrange
var merchantId = Guid.NewGuid();
var merchant = new MerchantModel
var merchant = new MerchantModels.MerchantModel
{
MerchantId = merchantId,
MerchantName = "Test Merchant",
MerchantReference = "REF001"
};
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantQuery>(), default))

this.MerchantUIService.Setup(m => m.GetMerchant(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(merchant));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantOperatorsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantOperatorModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantContractsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantContractModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantDevicesQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantDeviceModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantOperatorModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantContracts(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantContractModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantDevices(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantDeviceModel>()));

// Act
var cut = RenderComponent<View>(parameters => parameters
Expand All @@ -53,21 +51,19 @@ public void MerchantsView_WithMerchant_DisplaysMerchantName()
{
// Arrange
var merchantId = Guid.NewGuid();
var merchant = new MerchantModel
var merchant = new MerchantModels.MerchantModel
{
MerchantId = merchantId,
MerchantName = "Test Merchant",
MerchantReference = "REF001"
};
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantQuery>(), default))

this.MerchantUIService.Setup(m => m.GetMerchant(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(merchant));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantOperatorsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantOperatorModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantContractsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantContractModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantDevicesQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantDeviceModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantOperatorModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantContracts(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantContractModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantDevices(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantDeviceModel>()));


// Act
var cut = RenderComponent<View>(parameters => parameters
Expand All @@ -84,14 +80,19 @@ public void MerchantsView_HasCorrectPageTitle()
{
// Arrange
var merchantId = Guid.NewGuid();
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantQuery>(), default))
.ReturnsAsync(Result.Success(new MerchantModel { MerchantId = merchantId }));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantOperatorsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantOperatorModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantContractsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantContractModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantDevicesQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantDeviceModel>()));
var merchant = new MerchantModels.MerchantModel
{
MerchantId = merchantId,
MerchantName = "Test Merchant",
MerchantReference = "REF001"
};

this.MerchantUIService.Setup(m => m.GetMerchant(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(merchant));
this.MerchantUIService.Setup(m => m.GetMerchantOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantOperatorModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantContracts(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantContractModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantDevices(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantDeviceModel>()));

// Act
var cut = RenderComponent<View>(parameters => parameters
.Add(p => p.MerchantId, merchantId));
Expand All @@ -106,21 +107,20 @@ public void MerchantsView_HasBackButton()
{
// Arrange
var merchantId = Guid.NewGuid();
var merchant = new MerchantModel
var merchant = new MerchantModels.MerchantModel
{
MerchantId = merchantId,
MerchantName = "Test Merchant"
MerchantName = "Test Merchant",
MerchantReference = "REF001"
};
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantQuery>(), default))

this.MerchantUIService.Setup(m => m.GetMerchant(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(merchant));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantOperatorsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantOperatorModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantContractsQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantContractModel>()));
_mockMediator.Setup(x => x.Send(It.IsAny<MerchantQueries.GetMerchantDevicesQuery>(), default))
.ReturnsAsync(Result.Success(new List<MerchantDeviceModel>()));

this.MerchantUIService.Setup(m => m.GetMerchantOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantOperatorModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantContracts(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantContractModel>()));
this.MerchantUIService.Setup(m => m.GetMerchantDevices(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(new List<MerchantModels.MerchantDeviceModel>()));


// Act
var cut = RenderComponent<View>(parameters => parameters
.Add(p => p.MerchantId, merchantId));
Expand Down
Loading
Loading