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
8 changes: 4 additions & 4 deletions EstateManagementUI.BlazorServer.Tests/Pages/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ protected BaseTest() {
this._mockPermissionService = new Mock<IPermissionService>();
this._mockPermissionStore = new Mock<IPermissionStore>();
this._fakeNavigationManager = new FakeNavigationManager();
this.EstateUIService = new Mock<IEstateUIService>();


this._mockPermissionKeyProvider.Setup(x => x.GetKey()).Returns("test-key");
this._mockPermissionService.Setup(x => x.HasPermissionAsync(It.IsAny<PermissionSection>(), It.IsAny<PermissionFunction>())).ReturnsAsync(true);

Expand All @@ -34,6 +33,7 @@ protected BaseTest() {
this.Services.AddSingleton(this._mockAuthStateProvider.Object);
this.Services.AddSingleton(this._mockPermissionStore.Object);
this.Services.AddSingleton(this.EstateUIService.Object);
this.Services.AddSingleton(this.OperatorUIService.Object);


// Add required permission components that render their children
Expand All @@ -53,8 +53,8 @@ protected BaseTest() {
protected readonly Mock<AuthenticationStateProvider> _mockAuthStateProvider;
protected readonly Mock<IPermissionStore> _mockPermissionStore;
protected readonly FakeNavigationManager _fakeNavigationManager;
protected readonly Mock<IEstateUIService> EstateUIService;

protected readonly Mock<IEstateUIService> EstateUIService = new Mock<IEstateUIService>();
protected readonly Mock<IOperatorUIService> OperatorUIService = new Mock<IOperatorUIService>();
/// <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
Expand Up @@ -25,8 +25,8 @@ public void EstateIndex_RendersCorrectly()
ContractCount = 0,
RecentContracts = new List<Models.RecentContractModel>(),
OperatorCount = 0,
AllOperators = new List<Models.OperatorDropDownModel>(),
AssignedOperators = new List<Models.OperatorModel>(),
AllOperators = new List<Models.OperatorModels.OperatorDropDownModel>(),
AssignedOperators = new List<OperatorModels.OperatorModel>(),
MerchantCount = 0,
RecentMerchants = new List<Models.RecentMerchantsModel>(),
UserCount = 0
Expand All @@ -51,8 +51,8 @@ public void EstateIndex_DisplaysEstateDetails()
ContractCount = 0,
RecentContracts = new List<Models.RecentContractModel>(),
OperatorCount = 0,
AllOperators = new List<Models.OperatorDropDownModel>(),
AssignedOperators = new List<Models.OperatorModel>(),
AllOperators = new List<Models.OperatorModels.OperatorDropDownModel>(),
AssignedOperators = new List<OperatorModels.OperatorModel>(),
MerchantCount = 0,
RecentMerchants = new List<Models.RecentMerchantsModel>(),
UserCount = 0
Expand All @@ -76,8 +76,8 @@ public void EstateIndex_HasCorrectPageTitle()
ContractCount = 0,
RecentContracts = new List<Models.RecentContractModel>(),
OperatorCount = 0,
AllOperators = new List<Models.OperatorDropDownModel>(),
AssignedOperators = new List<Models.OperatorModel>(),
AllOperators = new List<Models.OperatorModels.OperatorDropDownModel>(),
AssignedOperators = new List<OperatorModels.OperatorModel>(),
MerchantCount = 0,
RecentMerchants = new List<Models.RecentMerchantsModel>(),
UserCount = 0
Expand Down Expand Up @@ -135,14 +135,14 @@ public void EstateIndex_AddOperator_Success_UpdatesAssignedOperators()
{
// Arrange
Guid operatorId = Guid.NewGuid();
OperatorDropDownModel operatorToAdd = new() {
OperatorModels.OperatorDropDownModel operatorToAdd = new() {
OperatorId = operatorId,
OperatorName = "Test Operator"
};

SetupSuccessfulDataLoadWithOperators(new List<OperatorDropDownModel> { operatorToAdd });
SetupSuccessfulDataLoadWithOperators(new List<OperatorModels.OperatorDropDownModel> { operatorToAdd });

OperatorModel operatorDetails = new() {
OperatorModels.OperatorModel operatorDetails = new() {
OperatorId = operatorId,
Name = "Test Operator",
RequireCustomMerchantNumber = true,
Expand Down Expand Up @@ -183,12 +183,12 @@ public void EstateIndex_AddOperator_Failure_ShowsErrorMessage()
{
// Arrange
Guid operatorId = Guid.NewGuid();
OperatorDropDownModel operatorToAdd = new() {
OperatorModels.OperatorDropDownModel operatorToAdd = new() {
OperatorId = operatorId,
OperatorName = "Test Operator"
};

SetupSuccessfulDataLoadWithOperators(new List<OperatorDropDownModel> { operatorToAdd });
SetupSuccessfulDataLoadWithOperators(new List<OperatorModels.OperatorDropDownModel> { operatorToAdd });

this.EstateUIService.Setup(e => e.AddOperatorToEstate(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<String>())).ReturnsAsync(Result.Failure);

Expand Down Expand Up @@ -220,14 +220,14 @@ public void EstateIndex_RemoveOperator_Success_RemovesFromList()
{
// Arrange
Guid operatorId = Guid.NewGuid();
OperatorModel assignedOperator = new() {
OperatorModels.OperatorModel assignedOperator = new() {
OperatorId = operatorId,
Name = "Test Operator",
RequireCustomMerchantNumber = true,
RequireCustomTerminalNumber = false
};

SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModel> { assignedOperator });
SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModels.OperatorModel> { assignedOperator });

this.EstateUIService.Setup(e => e.RemoveOperatorFromEstate(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success);

Expand Down Expand Up @@ -255,14 +255,14 @@ public void EstateIndex_RemoveOperator_Failure_ShowsErrorMessage()
{
// Arrange
Guid operatorId = Guid.NewGuid();
OperatorModel assignedOperator = new() {
OperatorModels.OperatorModel assignedOperator = new() {
OperatorId = operatorId,
Name = "Test Operator",
RequireCustomMerchantNumber = true,
RequireCustomTerminalNumber = false
};

SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModel> { assignedOperator });
SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModels.OperatorModel> { assignedOperator });

this.EstateUIService.Setup(e => e.RemoveOperatorFromEstate(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Failure(String.Empty));

Expand Down Expand Up @@ -377,14 +377,14 @@ public void EstateIndex_DisplaysOperatorRequirements_WhenPresent()
{
// Arrange
Guid operatorId = Guid.NewGuid();
OperatorModel assignedOperator = new() {
OperatorModels.OperatorModel assignedOperator = new() {
OperatorId = operatorId,
Name = "Test Operator",
RequireCustomMerchantNumber = true,
RequireCustomTerminalNumber = true
};

SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModel> { assignedOperator });
SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModels.OperatorModel> { assignedOperator });

IRenderedComponent<EstateIndex> cut = RenderComponent<EstateIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand Down Expand Up @@ -424,14 +424,14 @@ public void EstateIndex_SuccessMessage_ClearsWhenSwitchingTabs()
{
// Arrange
Guid operatorId = Guid.NewGuid();
OperatorModel assignedOperator = new() {
OperatorModels.OperatorModel assignedOperator = new() {
OperatorId = operatorId,
Name = "Test Operator",
RequireCustomMerchantNumber = true,
RequireCustomTerminalNumber = false
};

SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModel> { assignedOperator });
SetupSuccessfulDataLoadWithAssignedOperators(new List<OperatorModels.OperatorModel> { assignedOperator });

this.EstateUIService.Setup(e => e.RemoveOperatorFromEstate(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success);

Expand Down Expand Up @@ -462,28 +462,28 @@ public void EstateIndex_SuccessMessage_ClearsWhenSwitchingTabs()
// Helper methods
private void SetupSuccessfulDataLoad(List<RecentMerchantsModel>? merchants = null,
List<RecentContractModel>? contracts = null,
List<OperatorModel>? assignedOperators = null,
List<OperatorDropDownModel>? operators = null)
List<OperatorModels.OperatorModel>? assignedOperators = null,
List<OperatorModels.OperatorDropDownModel>? operators = null)
{
BlazorServer.Models.EstateModel estate = new(Guid.NewGuid(), "Test Estate", "EST001");
estate = estate with
{
ContractCount = 5,
RecentContracts = contracts ?? new List<RecentContractModel>(),
OperatorCount = 3,
AllOperators = operators ?? new List<OperatorDropDownModel>(),
AssignedOperators = assignedOperators ?? new List<OperatorModel>(),
AllOperators = operators ?? new List<OperatorModels.OperatorDropDownModel>(),
AssignedOperators = assignedOperators ?? new List<OperatorModels.OperatorModel>(),
MerchantCount = 10,
RecentMerchants = merchants ?? new List<RecentMerchantsModel>(),
UserCount = 2
};
this.EstateUIService.Setup(e => e.LoadEstate(It.IsAny<CorrelationId>(), It.IsAny<Guid>())).ReturnsAsync(Result.Success(estate));
}

private void SetupSuccessfulDataLoadWithOperators(List<OperatorDropDownModel> operators)
private void SetupSuccessfulDataLoadWithOperators(List<OperatorModels.OperatorDropDownModel> operators)
=> SetupSuccessfulDataLoad(operators: operators);

private void SetupSuccessfulDataLoadWithAssignedOperators(List<OperatorModel> assignedOperators)
private void SetupSuccessfulDataLoadWithAssignedOperators(List<OperatorModels.OperatorModel> assignedOperators)
=> SetupSuccessfulDataLoad(assignedOperators: assignedOperators);

private void SetupSuccessfulDataLoadWithMerchants(List<RecentMerchantsModel> merchants)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Bunit;
using EstateManagementUI.BlazorServer.Components.Permissions;
using EstateManagementUI.BlazorServer.Models;
using EstateManagementUI.BlazorServer.Permissions;
using EstateManagementUI.BlazorServer.Tests.Pages.FileProcessing;
using EstateManagementUI.BusinessLogic.Models;
using EstateManagementUI.BusinessLogic.BackendAPI.DataTransferObjects;
using EstateManagementUI.BusinessLogic.Requests;
using MediatR;
using Microsoft.AspNetCore.Components;
Expand All @@ -20,9 +21,9 @@ public class OperatorsIndexPageTests : BaseTest
public void OperatorsIndex_RendersCorrectly()
{
// Arrange
var operators = new List<OperatorModel>
var operators = new List<OperatorModels.OperatorModel>
{
new OperatorModel
new OperatorModels.OperatorModel
{
OperatorId = Guid.NewGuid(),
Name = "Test Operator",
Expand All @@ -31,7 +32,7 @@ public void OperatorsIndex_RendersCorrectly()
}
};

_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorsQuery>(), default))
this.OperatorUIService.Setup(o => o.GetOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(operators));

// Act
Expand All @@ -45,10 +46,10 @@ public void OperatorsIndex_RendersCorrectly()
public void OperatorsIndex_WithNoOperators_ShowsEmptyState()
{
// Arrange
var emptyList = new List<OperatorModel>();
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorsQuery>(), default))
var emptyList = new List<OperatorModels.OperatorModel>();
this.OperatorUIService.Setup(o => o.GetOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(emptyList));

// Act
var cut = RenderComponent<OperatorsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"));
Expand All @@ -61,27 +62,27 @@ public void OperatorsIndex_WithNoOperators_ShowsEmptyState()
public void OperatorsIndex_WithOperators_DisplaysOperatorList()
{
// Arrange
var operators = new List<OperatorModel>
var operators = new List<OperatorModels.OperatorModel>
{
new OperatorModel
new OperatorModels.OperatorModel
{
OperatorId = Guid.NewGuid(),
Name = "Operator 1",
RequireCustomMerchantNumber = true,
RequireCustomTerminalNumber = false
},
new OperatorModel
new OperatorModels.OperatorModel
{
OperatorId = Guid.NewGuid(),
Name = "Operator 2",
RequireCustomMerchantNumber = false,
RequireCustomTerminalNumber = true
}
};
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorsQuery>(), default))

this.OperatorUIService.Setup(o => o.GetOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(operators));

// Act
var cut = RenderComponent<OperatorsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand All @@ -95,20 +96,20 @@ public void OperatorsIndex_WithOperators_DisplaysOperatorList()
public void OperatorsIndex_DisplaysCustomNumberRequirements()
{
// Arrange
var operators = new List<OperatorModel>
var operators = new List<OperatorModels.OperatorModel>
{
new OperatorModel
new OperatorModels.OperatorModel
{
OperatorId = Guid.NewGuid(),
Name = "Test Operator",
RequireCustomMerchantNumber = true,
RequireCustomTerminalNumber = false
}
};
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorsQuery>(), default))

this.OperatorUIService.Setup(o => o.GetOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(operators));

// Act
var cut = RenderComponent<OperatorsIndex>();
cut.WaitForState(() => !cut.Markup.Contains("animate-spin"), TimeSpan.FromSeconds(5));
Expand All @@ -122,9 +123,9 @@ public void OperatorsIndex_DisplaysCustomNumberRequirements()
public void OperatorsIndex_HasCorrectPageTitle()
{
// Arrange
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorsQuery>(), default))
.ReturnsAsync(Result.Success(new List<OperatorModel>()));
this.OperatorUIService.Setup(o => o.GetOperators(It.IsAny<CorrelationId>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(new List<OperatorModels.OperatorModel>()));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Moq;
using Shouldly;
using SimpleResults;
using OperatorModel = EstateManagementUI.BusinessLogic.Models.OperatorModel;

namespace EstateManagementUI.BlazorServer.Tests.Pages.Operators;

Expand All @@ -20,15 +19,15 @@ public void OperatorsView_RendersCorrectly()
{
// Arrange
var operatorId = Guid.NewGuid();
var operatorModel = new OperatorModel
var operatorModel = new OperatorModels.OperatorModel
{
OperatorId = operatorId,
Name = "Test Operator"
};
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorQuery>(), default))

this.OperatorUIService.Setup(o => o.GetOperator(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(operatorModel));

// Act
var cut = RenderComponent<View>(parameters => parameters
.Add(p => p.OperatorId, operatorId));
Expand All @@ -42,15 +41,15 @@ public void OperatorsView_DisplaysOperatorName()
{
// Arrange
var operatorId = Guid.NewGuid();
var operatorModel = new OperatorModel
var operatorModel = new OperatorModels.OperatorModel
{
OperatorId = operatorId,
Name = "Test Operator"
};
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorQuery>(), default))

this.OperatorUIService.Setup(o => o.GetOperator(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(operatorModel));

// Act
var cut = RenderComponent<View>(parameters => parameters
.Add(p => p.OperatorId, operatorId));
Expand All @@ -65,8 +64,8 @@ public void OperatorsView_HasCorrectPageTitle()
{
// Arrange
var operatorId = Guid.NewGuid();
_mockMediator.Setup(x => x.Send(It.IsAny<OperatorQueries.GetOperatorQuery>(), default))
.ReturnsAsync(Result.Success(new OperatorModel { OperatorId = operatorId }));
this.OperatorUIService.Setup(o => o.GetOperator(It.IsAny<CorrelationId>(), It.IsAny<Guid>(), It.IsAny<Guid>()))
.ReturnsAsync(Result.Success(new OperatorModels.OperatorModel { OperatorId = operatorId }));

// Act
var cut = RenderComponent<View>(parameters => parameters
Expand Down
Loading
Loading