Skip to content

Commit 4939929

Browse files
Merge pull request #40 from StuartFerguson/task/#27_usemediatr
Switch to using Mediatr
2 parents a0a4a87 + 6de70a9 commit 4939929

13 files changed

Lines changed: 157 additions & 285 deletions

File tree

TransactionProcessor.BusinessLogic.Tests/CommandHandler/CommandRouterTests.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

TransactionProcessor.BusinessLogic.Tests/Commands/CommandTests.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

TransactionProcessor.BusinessLogic.Tests/CommandHandler/TransactionCommandHandlerTests.cs renamed to TransactionProcessor.BusinessLogic.Tests/RequestHandler/TransactionRequestHandlerTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
namespace TransactionProcessor.BusinessLogic.Tests.CommandHandler
22
{
33
using System.Threading;
4-
using BusinessLogic.Commands;
54
using BusinessLogic.Services;
6-
using CommandHandlers;
75
using Commands;
6+
using MediatR;
87
using Moq;
8+
using RequestHandlers;
9+
using Requests;
910
using Services;
1011
using Shared.DomainDrivenDesign.CommandHandling;
1112
using Shouldly;
1213
using Testing;
1314
using Xunit;
1415

15-
public class TransactionCommandHandlerTests
16+
public class TransactionRequestHandlerTests
1617
{
1718
[Fact]
18-
public void EstateCommandHandler_CreateEstateCommand_IsHandled()
19+
public void TransactionRequestHandler_ProcessLogonTransactionRequest_IsHandled()
1920
{
2021
Mock<ITransactionDomainService> transactionDomainService = new Mock<ITransactionDomainService>();
21-
ICommandHandler handler = new TransactionCommandHandler(transactionDomainService.Object);
22+
TransactionRequestHandler handler = new TransactionRequestHandler(transactionDomainService.Object);
2223

23-
ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand;
24+
ProcessLogonTransactionRequest command = TestData.ProcessLogonTransactionRequest;
2425

2526
Should.NotThrow(async () =>
2627
{
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TransactionProcessor.BusinessLogic.Tests.Commands
6+
{
7+
using Requests;
8+
using Shouldly;
9+
using Testing;
10+
using Xunit;
11+
12+
public class RequestTests
13+
{
14+
[Fact]
15+
public void ProcessLogonTransactionRequest_CanBeCreated_IsCreated()
16+
{
17+
ProcessLogonTransactionRequest processLogonTransactionRequest = ProcessLogonTransactionRequest.Create(TestData.TransactionId, TestData.EstateId, TestData.MerchantId, TestData.DeviceIdentifier,TestData.TransactionType, TestData.TransactionDateTime,
18+
TestData.TransactionNumber);
19+
20+
processLogonTransactionRequest.ShouldNotBeNull();
21+
processLogonTransactionRequest.EstateId.ShouldBe(TestData.EstateId);
22+
processLogonTransactionRequest.MerchantId.ShouldBe(TestData.MerchantId);
23+
processLogonTransactionRequest.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier);
24+
processLogonTransactionRequest.TransactionType.ShouldBe(TestData.TransactionType);
25+
processLogonTransactionRequest.TransactionDateTime.ShouldBe(TestData.TransactionDateTime);
26+
processLogonTransactionRequest.TransactionNumber.ShouldBe(TestData.TransactionNumber);
27+
}
28+
}
29+
}

TransactionProcessor.BusinessLogic/CommandHandlers/CommandRouter.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

TransactionProcessor.BusinessLogic/CommandHandlers/TransactionCommandHandler.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
namespace TransactionProcessor.BusinessLogic.RequestHandlers
2+
{
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using MediatR;
6+
using Models;
7+
using Requests;
8+
using Services;
9+
10+
/// <summary>
11+
///
12+
/// </summary>
13+
/// <seealso cref="MediatR.IRequestHandler{TransactionProcessor.BusinessLogic.Requests.ProcessLogonTransactionRequest, TransactionProcessor.Models.ProcessLogonTransactionResponse}" />
14+
/// <seealso cref="" />
15+
public class TransactionRequestHandler : IRequestHandler<ProcessLogonTransactionRequest, ProcessLogonTransactionResponse>
16+
{
17+
#region Fields
18+
19+
/// <summary>
20+
/// The transaction domain service
21+
/// </summary>
22+
private readonly ITransactionDomainService TransactionDomainService;
23+
24+
#endregion
25+
26+
#region Constructors
27+
28+
public TransactionRequestHandler(ITransactionDomainService transactionDomainService)
29+
{
30+
this.TransactionDomainService = transactionDomainService;
31+
}
32+
33+
#endregion
34+
35+
#region Methods
36+
37+
public async Task<ProcessLogonTransactionResponse> Handle(ProcessLogonTransactionRequest request,
38+
CancellationToken cancellationToken)
39+
{
40+
ProcessLogonTransactionResponse logonResponse =
41+
await this.TransactionDomainService.ProcessLogonTransaction(request.TransactionId,
42+
request.EstateId,
43+
request.MerchantId,
44+
request.TransactionDateTime,
45+
request.TransactionNumber,
46+
request.DeviceIdentifier,
47+
cancellationToken);
48+
49+
return logonResponse;
50+
}
51+
52+
#endregion
53+
}
54+
}

0 commit comments

Comments
 (0)