Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Maruszak <[email protected]>
  • Loading branch information
zarusz committed Jan 23, 2025
1 parent c653493 commit 7374839
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 75 deletions.
3 changes: 3 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
dotnet_diagnostic.xUnit1045.severity = silent

[*.{cs,vb}]
#### Naming styles ####
Expand Down Expand Up @@ -186,6 +188,7 @@ dotnet_style_qualification_for_event = false:suggestion
dotnet_diagnostic.VSTHRD200.severity = none
# not supported by .netstandard2.0
dotnet_diagnostic.CA1510.severity = none
dotnet_diagnostic.CA1512.severity = none

[*.{csproj,xml}]
indent_style = space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class OutboxLockRenewalTimerFactory<TOutboxMessage, TOutboxMessageKey>(IS
private bool _isDisposed = false;

public IOutboxLockRenewalTimer CreateRenewalTimer(TimeSpan lockDuration, TimeSpan interval, Action<Exception> lockLost, CancellationToken cancellationToken)
=> (OutboxLockRenewalTimer<TOutboxMessage, TOutboxMessageKey>)ActivatorUtilities.CreateInstance(_scope.ServiceProvider, typeof(OutboxLockRenewalTimer<TOutboxMessage, TOutboxMessageKey>), lockDuration, interval, lockLost, cancellationToken);
=> ActivatorUtilities.CreateInstance<OutboxLockRenewalTimer<TOutboxMessage, TOutboxMessageKey>>(_scope.ServiceProvider);

public async ValueTask DisposeAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public MessageHandler(
catch (Exception ex)
{
attempts++;
var handleErrorResult = await DoHandleError(message, messageType, messageScope, consumerContext, ex, attempts, cancellationToken).ConfigureAwait(false);
var handleErrorResult = await DoHandleError(message, messageType, messageScope, consumerContext, ex, attempts).ConfigureAwait(false);
if (handleErrorResult is ProcessResult.RetryState)
{
continue;
Expand Down Expand Up @@ -144,7 +144,7 @@ private async Task<object> DoHandleInternal(object message, IMessageTypeConsumer
return await ExecuteConsumer(message, consumerContext, consumerInvoker, responseType).ConfigureAwait(false);
}

private async Task<ProcessResult> DoHandleError(object message, Type messageType, IMessageScope messageScope, IConsumerContext consumerContext, Exception ex, int attempts, CancellationToken cancellationToken)
private async Task<ProcessResult> DoHandleError(object message, Type messageType, IMessageScope messageScope, IConsumerContext consumerContext, Exception ex, int attempts)
{
var errorHandlerResult = ProcessResult.Failure;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ private Exception OnResponseArrived(TTransportMessage transportMessage, string p
if (requestState == null)
{
LogResponseWillBeDiscarded(path, requestId);
// ToDo: add and API hook to these kind of situation
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Given_MessageType_When_Configured_Then_MessageType_ProperlySet_And_C
// assert
subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.Consumer);
subject.ConsumerSettings.ConsumerType.Should().BeNull();
subject.ConsumerSettings.MessageType.Should().Be(typeof(SomeMessage));
subject.ConsumerSettings.MessageType.Should().Be<SomeMessage>();
}

[Theory]
Expand Down Expand Up @@ -95,36 +95,36 @@ public void Given_BaseMessageType_And_ItsHierarchy_When_WithConsumer_ForTheBaseT
subject.ConsumerSettings.ResponseType.Should().BeNull();

subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.Consumer);
subject.ConsumerSettings.ConsumerType.Should().Be(typeof(BaseMessageConsumer));
subject.ConsumerSettings.ConsumerType.Should().Be<BaseMessageConsumer>();
Func<Task> call = () => subject.ConsumerSettings.ConsumerMethod(new BaseMessageConsumer(), new BaseMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(BaseMessage));

subject.ConsumerSettings.Invokers.Count.Should().Be(4);

var consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(BaseMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(BaseMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(BaseMessageConsumer));
consumerInvokerSettings.MessageType.Should().Be<BaseMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<BaseMessageConsumer>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new BaseMessageConsumer(), new BaseMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(BaseMessage));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(DerivedAMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(DerivedAMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(DerivedAMessageConsumer));
consumerInvokerSettings.MessageType.Should().Be<DerivedAMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<DerivedAMessageConsumer>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new DerivedAMessageConsumer(), new DerivedAMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(DerivedAMessage));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(DerivedBMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(DerivedBMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(DerivedBMessageConsumer));
consumerInvokerSettings.MessageType.Should().Be<DerivedBMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<DerivedBMessageConsumer>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new DerivedBMessageConsumer(), new DerivedBMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(DerivedBMessage));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(Derived2AMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(Derived2AMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(Derived2AMessageConsumer));
consumerInvokerSettings.MessageType.Should().Be<Derived2AMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<Derived2AMessageConsumer>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new Derived2AMessageConsumer(), new Derived2AMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(Derived2AMessage));
Expand All @@ -149,36 +149,36 @@ public void Given_BaseMessageType_And_ItsHierarchy_And_ConsumerOfContext_When_Wi
subject.ConsumerSettings.ResponseType.Should().BeNull();

subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.Consumer);
subject.ConsumerSettings.ConsumerType.Should().Be(typeof(BaseMessageConsumerOfContext));
subject.ConsumerSettings.ConsumerType.Should().Be<BaseMessageConsumerOfContext>();
Func<Task> call = () => subject.ConsumerSettings.ConsumerMethod(new BaseMessageConsumerOfContext(), new BaseMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(BaseMessage));

subject.ConsumerSettings.Invokers.Count.Should().Be(4);

var consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(BaseMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(BaseMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(BaseMessageConsumerOfContext));
consumerInvokerSettings.MessageType.Should().Be<BaseMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<BaseMessageConsumerOfContext>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new BaseMessageConsumerOfContext(), new BaseMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(BaseMessage));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(DerivedAMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(DerivedAMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(DerivedAMessageConsumerOfContext));
consumerInvokerSettings.MessageType.Should().Be<DerivedAMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<DerivedAMessageConsumerOfContext>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new DerivedAMessageConsumerOfContext(), new DerivedAMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(DerivedAMessage));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(DerivedBMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(DerivedBMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(DerivedBMessageConsumerOfContext));
consumerInvokerSettings.MessageType.Should().Be<DerivedBMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<DerivedBMessageConsumerOfContext>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new DerivedBMessageConsumerOfContext(), new DerivedBMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(DerivedBMessage));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(Derived2AMessage));
consumerInvokerSettings.MessageType.Should().Be(typeof(Derived2AMessage));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(Derived2AMessageConsumerOfContext));
consumerInvokerSettings.MessageType.Should().Be<Derived2AMessage>();
consumerInvokerSettings.ConsumerType.Should().Be<Derived2AMessageConsumerOfContext>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new Derived2AMessageConsumerOfContext(), new Derived2AMessage(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(Derived2AMessage));
Expand All @@ -198,25 +198,25 @@ public void Given_BaseRequestType_And_ItsHierarchy_When_WithConsumer_ForTheBaseT
.WithConsumer<DerivedRequestConsumer, DerivedRequest>();

// assert
subject.ConsumerSettings.ResponseType.Should().Be(typeof(BaseResponse));
subject.ConsumerSettings.ResponseType.Should().Be<BaseResponse>();

subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.Consumer);
subject.ConsumerSettings.ConsumerType.Should().Be(typeof(BaseRequestConsumer));
subject.ConsumerSettings.ConsumerType.Should().Be<BaseRequestConsumer>();
Func<Task> call = () => subject.ConsumerSettings.ConsumerMethod(new BaseRequestConsumer(), new BaseRequest(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(BaseRequest));

subject.ConsumerSettings.Invokers.Count.Should().Be(2);

var consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(BaseRequest));
consumerInvokerSettings.MessageType.Should().Be(typeof(BaseRequest));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(BaseRequestConsumer));
consumerInvokerSettings.MessageType.Should().Be<BaseRequest>();
consumerInvokerSettings.ConsumerType.Should().Be<BaseRequestConsumer>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new BaseRequestConsumer(), new BaseRequest(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(BaseRequest));

consumerInvokerSettings = subject.ConsumerSettings.Invokers.Single(x => x.MessageType == typeof(DerivedRequest));
consumerInvokerSettings.MessageType.Should().Be(typeof(DerivedRequest));
consumerInvokerSettings.ConsumerType.Should().Be(typeof(DerivedRequestConsumer));
consumerInvokerSettings.MessageType.Should().Be<DerivedRequest>();
consumerInvokerSettings.ConsumerType.Should().Be<DerivedRequestConsumer>();
consumerInvokerSettings.ParentSettings.Should().BeSameAs(subject.ConsumerSettings);
call = () => consumerInvokerSettings.ConsumerMethod(new DerivedRequestConsumer(), new DerivedRequest(), consumerContextMock.Object, consumerContextMock.Object.CancellationToken);
call.Should().ThrowAsync<NotImplementedException>().WithMessage(nameof(DerivedRequest));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void When_Created_Given_RequestAndResposeType_Then_MessageType_And_Respon
var subject = new HandlerBuilder<SomeRequest, SomeResponse>(_messageBusSettings);

// assert
subject.ConsumerSettings.MessageType.Should().Be(typeof(SomeRequest));
subject.ConsumerSettings.ResponseType.Should().Be(typeof(SomeResponse));
subject.ConsumerSettings.MessageType.Should().Be<SomeRequest>();
subject.ConsumerSettings.ResponseType.Should().Be<SomeResponse>();
subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.RequestResponse);
subject.ConsumerSettings.ConsumerType.Should().BeNull();
subject.ConsumerSettings.Invokers.Should().BeEmpty();
Expand All @@ -34,7 +34,7 @@ public void When_Created_Given_RequestWithoutResposeType_Then_MessageType_And_De
var subject = new HandlerBuilder<SomeRequestWithoutResponse>(_messageBusSettings);

// assert
subject.ConsumerSettings.MessageType.Should().Be(typeof(SomeRequestWithoutResponse));
subject.ConsumerSettings.MessageType.Should().Be<SomeRequestWithoutResponse>();
subject.ConsumerSettings.ResponseType.Should().BeNull();
subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.RequestResponse);
subject.ConsumerSettings.ConsumerType.Should().BeNull();
Expand Down Expand Up @@ -101,14 +101,14 @@ public void When_Configured_Given_RequestResponse_Then_ProperSettings(bool ofCon
}

// assert
subject.ConsumerSettings.MessageType.Should().Be(typeof(SomeRequest));
subject.ConsumerSettings.MessageType.Should().Be<SomeRequest>();
subject.ConsumerSettings.Path.Should().Be(_path);
subject.ConsumerSettings.Instances.Should().Be(3);

subject.ConsumerSettings.ConsumerType.Should().Be(consumerType);
subject.ConsumerSettings.ConsumerMode.Should().Be(ConsumerMode.RequestResponse);

subject.ConsumerSettings.ResponseType.Should().Be(typeof(SomeResponse));
subject.ConsumerSettings.ResponseType.Should().Be<SomeResponse>();

subject.ConsumerSettings.Invokers.Count.Should().Be(2);

Expand Down Expand Up @@ -153,7 +153,7 @@ public void When_Configured_Given_RequestWithoutResponse_And_HandlersWithDerived
}

// assert
subject.ConsumerSettings.MessageType.Should().Be(typeof(SomeRequestWithoutResponse));
subject.ConsumerSettings.MessageType.Should().Be<SomeRequestWithoutResponse>();
subject.ConsumerSettings.Path.Should().Be(_path);
subject.ConsumerSettings.Instances.Should().Be(3);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void Add_Should_AddTypeToCollection_IfAssignableToGeneric()
var collection = new TypeCollection<ISampleInterface>();

// Act
collection.Add(typeof(SampleClass));
collection.Add<SampleClass>();

// Assert
collection.Count.Should().Be(1);
Expand Down Expand Up @@ -37,7 +37,7 @@ public void Add_Should_ThrowException_WhenTypeIsAssignableToGenericButAlreadyExi
collection.Add<SampleClass>();

// Act
Action act = () => collection.Add(typeof(SampleClass));
Action act = () => collection.Add<SampleClass>();

// Assert
act.Should().Throw<ArgumentException>().WithMessage("Type already exists in the collection. (Parameter 'type')");
Expand Down Expand Up @@ -169,7 +169,7 @@ public void Remove_Should_RemoveTypeFromCollection_WhenSuppliedAsType()
collection.Add<SampleClass>();

// Act
var removed = collection.Remove(typeof(SampleClass));
var removed = collection.Remove<SampleClass>();

// Assert
removed.Should().BeTrue();
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/SlimMessageBus.Host.Integration.Test/HybridTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public async Task When_PublishToMemoryBus_Given_InsideConsumerWithMessageScope_T
// all the internal messages should be processed by Memory bus
store
.Where(x => x.Name == nameof(InternalMessageConsumer) || x.Name == nameof(InternalMessageConsumerInterceptor) || x.Name == nameof(InternalMessageProducerInterceptor) || x.Name == nameof(InternalMessagePublishInterceptor))
.Should().AllSatisfy(x => x.ContextMessageBusType.Should().Be(typeof(MemoryMessageBus)));
.Should().AllSatisfy(x => x.ContextMessageBusType.Should().Be<MemoryMessageBus>());

// all the external messages should be processed by Azure Service Bus
store
.Where(x => x.Name == nameof(ExternalMessageConsumer) || x.Name == nameof(ExternalMessageConsumerInterceptor))
.Should().AllSatisfy(x => x.ContextMessageBusType.Should().Be(typeof(ServiceBusMessageBus)));
.Should().AllSatisfy(x => x.ContextMessageBusType.Should().Be<ServiceBusMessageBus>());

// in this order
var eventsThatHappenedWhenExternalWasPublished = grouping.Values.SingleOrDefault(x => x.Count == 2);
Expand Down
Loading

0 comments on commit 7374839

Please sign in to comment.