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 @@ -3,6 +3,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Models;
using Moq;
using RequestHandlers;
using Requests;
Expand All @@ -17,12 +18,30 @@ public async Task LoginRequestHandler_Handle_LoginRequest_IsHandled()
{
Mock<IAuthenticationService> authenticationService = new Mock<IAuthenticationService>();
authenticationService.Setup(a => a.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.AccessToken);
LoginRequestHandler handler = new LoginRequestHandler(authenticationService.Object);
Mock<IConfigurationService> configurationService = new Mock<IConfigurationService>();
configurationService.Setup(c => c.GetConfiguration(It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(new Configuration());
LoginRequestHandler handler = new LoginRequestHandler(authenticationService.Object,configurationService.Object);

LoginRequest request = LoginRequest.Create(TestData.UserName,TestData.Password);

String accessToken = await handler.Handle(request, CancellationToken.None);

accessToken.ShouldBe(TestData.AccessToken);
}

[Fact]
public async Task LoginRequestHandler_Handle_GetConfigurationRequest_IsHandled()
{
Mock<IAuthenticationService> authenticationService = new Mock<IAuthenticationService>();
authenticationService.Setup(a => a.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.AccessToken);
Mock<IConfigurationService> configurationService = new Mock<IConfigurationService>();
configurationService.Setup(c => c.GetConfiguration(It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(new Configuration());
LoginRequestHandler handler = new LoginRequestHandler(authenticationService.Object, configurationService.Object);

GetConfigurationRequest request = GetConfigurationRequest.Create(TestData.DeviceIdentifier);

Configuration configuration = await handler.Handle(request, CancellationToken.None);

configuration.ShouldNotBeNull();
}
}
20 changes: 20 additions & 0 deletions TransactionMobile.Maui.BusinessLogic/Models/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace TransactionMobile.Maui.BusinessLogic.Models;

public class Configuration
{
public String ClientId { get; set; }

public String ClientSecret { get; set; }

public String SecurityServiceUrl { get; set; }

public String TransactionProcessorAclUrl { get; set; }

public String EstateManagementUrl { get; set; }

public String EstateReportingUrl { get; set; }

public LogLevel LogLevel { get; set; }

public Boolean EnableAutoUpdates { get; set; }
}
16 changes: 16 additions & 0 deletions TransactionMobile.Maui.BusinessLogic/Models/LogLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TransactionMobile.Maui.BusinessLogic.Models;

public enum LogLevel
{
Fatal,

Error,

Warn,

Info,

Debug,

Trace
}
23 changes: 23 additions & 0 deletions TransactionMobile.Maui.BusinessLogic/Models/LogMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TransactionMobile.Maui.BusinessLogic.Models
{
public class LogMessage
{
#region Properties

public DateTime EntryDateTime { get; set; }

public Int32 Id { get; set; }

public String LogLevel { get; set; }

public String Message { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
namespace TransactionMobile.Maui.BusinessLogic.RequestHandlers
{
using MediatR;
using Models;
using Requests;
using Services;

public class LoginRequestHandler : IRequestHandler<LoginRequest, String>
public class LoginRequestHandler : IRequestHandler<LoginRequest, String>,
IRequestHandler<GetConfigurationRequest, Configuration>
{
private readonly IConfigurationService ConfigurationService;

#region Constructors
public LoginRequestHandler(IAuthenticationService authenticationService)
public LoginRequestHandler(IAuthenticationService authenticationService,
IConfigurationService configurationService)
{

this.ConfigurationService = configurationService;

this.AuthenticationService = authenticationService;
}

Expand All @@ -30,9 +36,13 @@ public async Task<String> Handle(LoginRequest request,

return token;
}

public async Task<Configuration> Handle(GetConfigurationRequest request,
CancellationToken cancellationToken)
{
return await this.ConfigurationService.GetConfiguration(request.DeviceIdentifier, cancellationToken);
}

#endregion


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace TransactionMobile.Maui.BusinessLogic.Requests;

using MediatR;
using Models;

public class GetConfigurationRequest : IRequest<Configuration>
{
public String DeviceIdentifier { get; private set; }

private GetConfigurationRequest(String deviceIdentifier)
{
this.DeviceIdentifier = deviceIdentifier;
}

public static GetConfigurationRequest Create(String deviceIdentifier)
{
return new GetConfigurationRequest(deviceIdentifier);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TransactionMobile.Maui.BusinessLogic.Services;
namespace TransactionMobile.Maui.BusinessLogic.Services.DummyServices;

public class DummyAuthenticationService : IAuthenticationService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace TransactionMobile.Maui.BusinessLogic.Services.DummyServices
{
using Models;

public class DummyConfigurationService : IConfigurationService
{
#region Methods

public async Task<Configuration> GetConfiguration(String deviceIdentifier,
CancellationToken cancellationToken)
{
return new Configuration
{
ClientId = "dummyClientId",
ClientSecret = "dummyClientSecret",
EnableAutoUpdates = false,
EstateManagementUrl = "http://localhost:5000",
EstateReportingUrl = "http://localhost:5006",
LogLevel = LogLevel.Debug,
SecurityServiceUrl = "http://localhost:5001",
TransactionProcessorAclUrl = "http://localhost:5003"
};
}

public async Task PostDiagnosticLogs(String deviceIdentifier,
List<LogMessage> logMessages,
CancellationToken cancellationToken)
{
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TransactionMobile.Maui.BusinessLogic.Services;
namespace TransactionMobile.Maui.BusinessLogic.Services.DummyServices;

using Models;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace TransactionMobile.Maui.BusinessLogic.Services.DummyServices;

using Models;

public class DummyTransactionService : ITransactionService
{
#region Methods

public async Task<Boolean> PerformLogon(PerformLogonRequestModel model,
CancellationToken cancellationToken)
{
return true;
}

public async Task<Boolean> PerformMobileTopup(PerformMobileTopupRequestModel model,
CancellationToken cancellationToken)
{
if (model.TopupAmount == 100)
{
return false;
}

return true;
}

public async Task<Boolean> PerformReconciliation(CancellationToken cancellationToken)
{
return true;
}

public async Task<Boolean> PerformVoucherIssue(PerformVoucherIssueRequestModel model,
CancellationToken cancellationToken)
{
if (model.VoucherAmount == 100)
{
return false;
}

return true;
}

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TransactionMobile.Maui.BusinessLogic.Services;

using Models;

public interface IConfigurationService
{
/// <summary>
/// Gets the configuration.
/// </summary>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<Configuration> GetConfiguration(String deviceIdentifier,
CancellationToken cancellationToken);

/// <summary>
/// Posts the diagnostic logs.
/// </summary>
/// <param name="deviceIdentifier">The device identifier.</param>
/// <param name="logMessages">The log messages.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task PostDiagnosticLogs(String deviceIdentifier,
List<LogMessage> logMessages,
CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,4 @@ public interface ITransactionService

#endregion
}

public class DummyTransactionService : ITransactionService
{
public async Task<Boolean> PerformLogon(PerformLogonRequestModel model, CancellationToken cancellationToken)
{
return true;
}

public async Task<Boolean> PerformMobileTopup(PerformMobileTopupRequestModel model, CancellationToken cancellationToken)
{
if (model.TopupAmount == 100)
{
return false;
}

return true;
}

public async Task<Boolean> PerformReconciliation(CancellationToken cancellationToken)
{
return true;
}

public async Task<Boolean> PerformVoucherIssue(PerformVoucherIssueRequestModel model, CancellationToken cancellationToken)
{
if (model.VoucherAmount == 100)
{
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public LoginPageViewModel(IMediator mediator, INavigationService navigationServi
private async Task LoginCommandExecute()
{
// TODO: this method needs refactored
GetConfigurationRequest getConfigurationRequest = GetConfigurationRequest.Create("");
Configuration configuration = await this.Mediator.Send(getConfigurationRequest);
// TODO: Cache the config object somewhere

LoginRequest loginRequest = LoginRequest.Create("", "");

String token = await this.Mediator.Send(loginRequest);

//if (token == null)
Expand Down
6 changes: 6 additions & 0 deletions TransactionMobile.Maui/Extensions/MauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BusinessLogic.RequestHandlers;
using BusinessLogic.Requests;
using BusinessLogic.Services;
using BusinessLogic.Services.DummyServices;
using BusinessLogic.ViewModels;
using BusinessLogic.ViewModels.Support;
using BusinessLogic.ViewModels.Transactions;
Expand All @@ -19,6 +20,7 @@ public static MauiAppBuilder ConfigureAppServices(this MauiAppBuilder builder)
builder.Services.AddSingleton<IAuthenticationService, DummyAuthenticationService>();
builder.Services.AddSingleton<IMerchantService, DummyMerchantService>();
builder.Services.AddSingleton<ITransactionService, DummyTransactionService>();
builder.Services.AddSingleton<IConfigurationService, DummyConfigurationService>();

return builder;
}
Expand All @@ -33,12 +35,16 @@ public static MauiAppBuilder ConfigureUIServices(this MauiAppBuilder builder)
public static MauiAppBuilder ConfigureRequestHandlers(this MauiAppBuilder builder)
{
builder.Services.AddSingleton<IMediator, Mediator>();
builder.Services.AddSingleton<IRequestHandler<GetConfigurationRequest, Configuration>, LoginRequestHandler>();
builder.Services.AddSingleton<IRequestHandler<LoginRequest, String>, LoginRequestHandler>();

builder.Services.AddSingleton<IRequestHandler<GetContractProductsRequest, List<ContractProductModel>>, MerchantRequestHandler>();
builder.Services.AddSingleton<IRequestHandler<GetMerchantBalanceRequest, Decimal>, MerchantRequestHandler>();

builder.Services.AddSingleton<IRequestHandler<PerformMobileTopupRequest, Boolean>, TransactionRequestHandler>();
builder.Services.AddSingleton<IRequestHandler<LogonTransactionRequest, Boolean>, TransactionRequestHandler>();
builder.Services.AddSingleton<IRequestHandler<PerformVoucherIssueRequest, Boolean>, TransactionRequestHandler>();

builder.Services.AddSingleton<ServiceFactory>(ctx => { return t => ctx.GetService(t); });

return builder;
Expand Down