Skip to content

Commit

Permalink
Merge pull request #13 from alifcapital/mirolimmajidov-acm1-387
Browse files Browse the repository at this point in the history
Implement the NamingPolicy for the event of event storage
  • Loading branch information
MirolimMajidov authored Dec 13, 2024
2 parents 6dd3211 + 3cae185 commit 6edaa87
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/Configurations/BaseEventOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using EventBus.RabbitMQ.Models;
using EventStorage.Models;

namespace EventBus.RabbitMQ.Configurations;

Expand Down
27 changes: 4 additions & 23 deletions src/Configurations/RabbitMqHostSettings.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Reflection;
using System.Security.Authentication;
using System.Text.Json;
using EventBus.RabbitMQ.Models;
using EventStorage.Models;

namespace EventBus.RabbitMQ.Configurations;

Expand Down Expand Up @@ -165,32 +165,13 @@ internal string GetCorrectEventNameBasedOnNamingPolicy(string eventName)
/// <summary>
/// Gets JsonNamingPolicy to use on naming police for serializing and deserializing the name of Event
/// </summary>
internal JsonNamingPolicy GetEventNamingPolicy()
private JsonNamingPolicy GetEventNamingPolicy()
{
if (_isEventNamingPolicyInitialized)
return _eventNamingPolicy;

switch (EventNamingPolicy)
{
case NamingPolicyType.CamelCase:
_eventNamingPolicy = JsonNamingPolicy.CamelCase;
break;
case NamingPolicyType.SnakeCaseLower:
_eventNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
break;
case NamingPolicyType.SnakeCaseUpper:
_eventNamingPolicy = JsonNamingPolicy.SnakeCaseUpper;
break;
case NamingPolicyType.KebabCaseLower:
_eventNamingPolicy = JsonNamingPolicy.KebabCaseLower;
break;
case NamingPolicyType.KebabCaseUpper:
_eventNamingPolicy = JsonNamingPolicy.KebabCaseUpper;
break;
default:
_eventNamingPolicy = null;
break;
}
var eventNamingPolicyType = EventNamingPolicy ?? NamingPolicyType.PascalCase;
_eventNamingPolicy = NamingPolicyTypeNames.GetEventNamingPolicy(eventNamingPolicyType.ToString());

_isEventNamingPolicyInitialized = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Configurations/RabbitMqOptionsConstant.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Security.Authentication;
using EventBus.RabbitMQ.Models;
using EventStorage.Models;

namespace EventBus.RabbitMQ.Configurations;

Expand Down
2 changes: 1 addition & 1 deletion src/EventBus.RabbitMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AlifCapital.EventStorage" Version="9.0.4" />
<PackageReference Include="AlifCapital.EventStorage" Version="9.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.0" />
Expand Down
11 changes: 0 additions & 11 deletions src/Models/NamingPolicyType.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Subscribers/Consumers/EventConsumerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private async Task Consumer_Received(object sender, BasicDeliverEventArgs eventA
$"The RabbitMQ is configured to use the Inbox for received events, but the Inbox functionality of the EventStorage is not enabled. So, the {info.eventHandlerType.Name} event subscriber of an event will be executed immediately for the event id: {eventId};");

_ = eventReceiverManager.Received(eventId, info.eventType.Name, eventArgs.RoutingKey,
EventProviderType.MessageBroker, payload: eventPayload, headers: headersAsJson);
EventProviderType.MessageBroker, payload: eventPayload, headers: headersAsJson, namingPolicyType: info.eventSettings.PropertyNamingPolicy ?? NamingPolicyType.PascalCase);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion tests/UnitTests/Subscribers/EventSubscriberOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EventBus.RabbitMQ.Configurations;
using EventBus.RabbitMQ.Models;
using EventBus.RabbitMQ.Subscribers.Options;
using EventStorage.Models;
using FluentAssertions;

namespace EventBus.RabbitMQ.Tests.UnitTests.Subscribers;
Expand Down

0 comments on commit 6edaa87

Please sign in to comment.