Skip to content

Commit 66fdec1

Browse files
Merge pull request #133 from TransactionProcessing/deepsource-autofix-e0c9e98b
refactor: use file scoped namespaces
2 parents bf53c53 + 3be3395 commit 66fdec1

6 files changed

Lines changed: 189 additions & 195 deletions

File tree

CallbackHander.Testing/TestData.cs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,49 @@
22
using CallbackHandlers.Models;
33
using Xunit;
44

5-
namespace CallbackHander.Testing
6-
{
7-
using CallbackHandler.BusinessLogic.Requests;
8-
using CallbackHandler.CallbackMessageAggregate;
5+
namespace CallbackHander.Testing;
96

10-
public class TestData
11-
{
12-
public static Guid CallbackId = Guid.Parse("E82DF060-5717-4F79-B99B-E14C702C8F0E");
7+
using CallbackHandler.BusinessLogic.Requests;
8+
using CallbackHandler.CallbackMessageAggregate;
139

14-
public static Int32 MessageFormat = 1;
10+
public class TestData
11+
{
12+
public static Guid CallbackId = Guid.Parse("E82DF060-5717-4F79-B99B-E14C702C8F0E");
1513

16-
public static String TypeString = "TestTypeString";
14+
public static Int32 MessageFormat = 1;
1715

18-
public static String CallbackMessage = "Callback message";
16+
public static String TypeString = "TestTypeString";
1917

20-
public static String[] Destinations = new[] {"A", "B"};
18+
public static String CallbackMessage = "Callback message";
2119

22-
public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29";
23-
public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C");
24-
public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29");
20+
public static String[] Destinations = {"A", "B"};
2521

26-
public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest =>
27-
new CallbackCommands.RecordCallbackRequest(TestData.CallbackId,
28-
TestData.CallbackMessage,
29-
TestData.Destinations,
30-
(MessageFormat)TestData.MessageFormat,
31-
TestData.TypeString,
32-
TestData.Reference);
22+
public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29";
23+
public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C");
24+
public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29");
3325

34-
public static CallbackQueries.GetCallbackQuery GetCallbackQuery =>
35-
new CallbackQueries.GetCallbackQuery(TestData.CallbackId);
26+
public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest =>
27+
new CallbackCommands.RecordCallbackRequest(TestData.CallbackId,
28+
TestData.CallbackMessage,
29+
TestData.Destinations,
30+
(MessageFormat)TestData.MessageFormat,
31+
TestData.TypeString,
32+
TestData.Reference);
3633

37-
public static CallbackMessageAggregate EmptyCallbackMessageAggregate()
38-
{
39-
return new CallbackMessageAggregate();
40-
}
34+
public static CallbackQueries.GetCallbackQuery GetCallbackQuery =>
35+
new CallbackQueries.GetCallbackQuery(TestData.CallbackId);
4136

42-
public static CallbackMessageAggregate RecordedCallbackMessageAggregate()
43-
{
44-
CallbackMessageAggregate aggregate = new();
45-
aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat,
46-
TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference);
37+
public static CallbackMessageAggregate EmptyCallbackMessageAggregate()
38+
{
39+
return new CallbackMessageAggregate();
40+
}
41+
42+
public static CallbackMessageAggregate RecordedCallbackMessageAggregate()
43+
{
44+
CallbackMessageAggregate aggregate = new();
45+
aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat,
46+
TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference);
4747

48-
return aggregate;
49-
}
48+
return aggregate;
5049
}
5150
}
Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
1-
namespace CallbackHandler.BusinessLogic.Common
1+
namespace CallbackHandler.BusinessLogic.Common;
2+
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics.CodeAnalysis;
6+
using System.Linq;
7+
using Shared.DomainDrivenDesign.EventSourcing;
8+
9+
[ExcludeFromCodeCoverage]
10+
public class DomainEventTypesToSilentlyHandle : IDomainEventTypesToSilentlyHandle
211
{
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Diagnostics.CodeAnalysis;
6-
using System.Linq;
7-
using Shared.DomainDrivenDesign.EventSourcing;
8-
9-
[ExcludeFromCodeCoverage]
10-
public class DomainEventTypesToSilentlyHandle : IDomainEventTypesToSilentlyHandle
11-
{
12-
#region Fields
12+
#region Fields
1313

14-
/// <summary>
15-
/// The handler event types to silently handle
16-
/// </summary>
17-
private readonly Dictionary<String, String[]> HandlerEventTypesToSilentlyHandle;
14+
/// <summary>
15+
/// The handler event types to silently handle
16+
/// </summary>
17+
private readonly Dictionary<String, String[]> HandlerEventTypesToSilentlyHandle;
1818

19-
#endregion
19+
#endregion
2020

21-
#region Constructors
21+
#region Constructors
2222

23-
/// <summary>
24-
/// Initializes a new instance of the <see cref="DomainEventTypesToSilentlyHandle" /> class.
25-
/// </summary>
26-
/// <param name="handlerEventTypesToSilentlyHandle">The handler event types to silently handle.</param>
27-
public DomainEventTypesToSilentlyHandle(Dictionary<String, String[]> handlerEventTypesToSilentlyHandle)
28-
{
29-
this.HandlerEventTypesToSilentlyHandle = handlerEventTypesToSilentlyHandle;
30-
}
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="DomainEventTypesToSilentlyHandle" /> class.
25+
/// </summary>
26+
/// <param name="handlerEventTypesToSilentlyHandle">The handler event types to silently handle.</param>
27+
public DomainEventTypesToSilentlyHandle(Dictionary<String, String[]> handlerEventTypesToSilentlyHandle)
28+
{
29+
this.HandlerEventTypesToSilentlyHandle = handlerEventTypesToSilentlyHandle;
30+
}
3131

32-
#endregion
32+
#endregion
3333

34-
#region Methods
34+
#region Methods
3535

36-
/// <summary>
37-
/// Handles the silently.
38-
/// </summary>
39-
/// <param name="handlerName">Name of the handler.</param>
40-
/// <param name="domainEvent">The domain event.</param>
41-
/// <returns></returns>
42-
public Boolean HandleSilently(String handlerName,
43-
DomainEvent domainEvent)
36+
/// <summary>
37+
/// Handles the silently.
38+
/// </summary>
39+
/// <param name="handlerName">Name of the handler.</param>
40+
/// <param name="domainEvent">The domain event.</param>
41+
/// <returns></returns>
42+
public Boolean HandleSilently(String handlerName,
43+
DomainEvent domainEvent)
44+
{
45+
if (this.HandlerEventTypesToSilentlyHandle.TryGetValue(handlerName, out var eventTypes)
46+
&& eventTypes.Contains(domainEvent.GetType().FullName))
4447
{
45-
if (this.HandlerEventTypesToSilentlyHandle.TryGetValue(handlerName, out var eventTypes)
46-
&& eventTypes.Contains(domainEvent.GetType().FullName))
47-
{
48-
return true;
49-
}
48+
return true;
49+
}
5050

51-
return false;
51+
return false;
5252
}
5353

5454
#endregion
55-
}
5655
}
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
namespace CallbackHandler.BusinessLogic.Common
2-
{
3-
using System;
4-
using Shared.DomainDrivenDesign.EventSourcing;
1+
namespace CallbackHandler.BusinessLogic.Common;
2+
3+
using System;
4+
using Shared.DomainDrivenDesign.EventSourcing;
55

6-
public interface IDomainEventTypesToSilentlyHandle
7-
{
8-
#region Methods
6+
public interface IDomainEventTypesToSilentlyHandle
7+
{
8+
#region Methods
99

10-
/// <summary>
11-
/// Handles the silently.
12-
/// </summary>
13-
/// <param name="handlerName">Name of the handler.</param>
14-
/// <param name="domainEvent">The domain event.</param>
15-
/// <returns></returns>
16-
Boolean HandleSilently(String handlerName,
17-
DomainEvent domainEvent);
10+
/// <summary>
11+
/// Handles the silently.
12+
/// </summary>
13+
/// <param name="handlerName">Name of the handler.</param>
14+
/// <param name="domainEvent">The domain event.</param>
15+
/// <returns></returns>
16+
Boolean HandleSilently(String handlerName,
17+
DomainEvent domainEvent);
1818

19-
#endregion
20-
}
19+
#endregion
2120
}
Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,49 @@
11
using Shared.Results;
22
using SimpleResults;
33

4-
namespace CallbackHandler.BusinessLogic.RequestHandler
4+
namespace CallbackHandler.BusinessLogic.RequestHandler;
5+
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using CallbackHandler.BusinessLogic.Services;
9+
using CallbackMessageAggregate;
10+
using MediatR;
11+
using Requests;
12+
using Shared.DomainDrivenDesign.EventSourcing;
13+
using Shared.EventStore.Aggregate;
14+
15+
public class CallbackHandlerRequestHandler : IRequestHandler<CallbackCommands.RecordCallbackRequest, Result>,
16+
IRequestHandler<CallbackQueries.GetCallbackQuery, Result<CallbackHandlers.Models.CallbackMessage>>
517
{
6-
using System.Threading;
7-
using System.Threading.Tasks;
8-
using CallbackHandler.BusinessLogic.Services;
9-
using CallbackMessageAggregate;
10-
using MediatR;
11-
using Requests;
12-
using Shared.DomainDrivenDesign.EventSourcing;
13-
using Shared.EventStore.Aggregate;
14-
15-
public class CallbackHandlerRequestHandler : IRequestHandler<CallbackCommands.RecordCallbackRequest, Result>,
16-
IRequestHandler<CallbackQueries.GetCallbackQuery, Result<CallbackHandlers.Models.CallbackMessage>>
18+
private readonly ICallbackDomainService CallbackDomainService;
19+
private readonly IAggregateRepository<CallbackMessageAggregate, DomainEvent> CallbackAggregateRepository;
20+
21+
public CallbackHandlerRequestHandler(ICallbackDomainService callbackDomainService,
22+
IAggregateRepository<CallbackMessageAggregate, DomainEvent> callbackAggregateRepository)
23+
{
24+
this.CallbackDomainService = callbackDomainService;
25+
CallbackAggregateRepository = callbackAggregateRepository;
26+
}
27+
28+
public async Task<Result> Handle(CallbackCommands.RecordCallbackRequest request,
29+
CancellationToken cancellationToken) {
30+
31+
return await this.CallbackDomainService.RecordCallback(request.CallbackId,
32+
request.TypeString,
33+
request.MessageFormat,
34+
request.CallbackMessage,
35+
request.Reference,
36+
request.Destinations,
37+
cancellationToken);
38+
}
39+
40+
public async Task<Result<CallbackHandlers.Models.CallbackMessage>> Handle(CallbackQueries.GetCallbackQuery request, CancellationToken cancellationToken)
1741
{
18-
private readonly ICallbackDomainService CallbackDomainService;
19-
private readonly IAggregateRepository<CallbackMessageAggregate, DomainEvent> CallbackAggregateRepository;
20-
21-
public CallbackHandlerRequestHandler(ICallbackDomainService callbackDomainService,
22-
IAggregateRepository<CallbackMessageAggregate, DomainEvent> callbackAggregateRepository)
23-
{
24-
this.CallbackDomainService = callbackDomainService;
25-
CallbackAggregateRepository = callbackAggregateRepository;
26-
}
27-
28-
public async Task<Result> Handle(CallbackCommands.RecordCallbackRequest request,
29-
CancellationToken cancellationToken) {
30-
31-
return await this.CallbackDomainService.RecordCallback(request.CallbackId,
32-
request.TypeString,
33-
request.MessageFormat,
34-
request.CallbackMessage,
35-
request.Reference,
36-
request.Destinations,
37-
cancellationToken);
38-
}
39-
40-
public async Task<Result<CallbackHandlers.Models.CallbackMessage>> Handle(CallbackQueries.GetCallbackQuery request, CancellationToken cancellationToken)
41-
{
42-
Result<CallbackMessageAggregate> callbackAggregate =
43-
await this.CallbackAggregateRepository.GetLatestVersion(request.CallbackId, cancellationToken);
44-
if (callbackAggregate.IsFailed)
45-
return ResultHelpers.CreateFailure(callbackAggregate);
46-
47-
return Result.Success(callbackAggregate.Data.GetCallbackMessage());
48-
}
42+
Result<CallbackMessageAggregate> callbackAggregate =
43+
await this.CallbackAggregateRepository.GetLatestVersion(request.CallbackId, cancellationToken);
44+
if (callbackAggregate.IsFailed)
45+
return ResultHelpers.CreateFailure(callbackAggregate);
46+
47+
return Result.Success(callbackAggregate.Data.GetCallbackMessage());
4948
}
5049
}

CallbackHandler.BusinessLogic/Services/ICallbackDomainService.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
using System.Threading.Tasks;
1010
using SimpleResults;
1111

12-
namespace CallbackHandler.BusinessLogic.Services
12+
namespace CallbackHandler.BusinessLogic.Services;
13+
14+
public interface ICallbackDomainService
1315
{
14-
public interface ICallbackDomainService
15-
{
16-
Task<Result> RecordCallback(Guid callbackId,
17-
String typeString,
18-
MessageFormat messageFormat,
19-
String callbackMessage,
20-
String reference,
21-
String[] destinations,
22-
CancellationToken cancellationToken);
23-
}
16+
Task<Result> RecordCallback(Guid callbackId,
17+
String typeString,
18+
MessageFormat messageFormat,
19+
String callbackMessage,
20+
String reference,
21+
String[] destinations,
22+
CancellationToken cancellationToken);
2423
}

0 commit comments

Comments
 (0)