From 4303da8e9d1cbda6969c7275afa15f0d04951a78 Mon Sep 17 00:00:00 2001 From: sanych-sun Date: Wed, 24 Jan 2024 20:49:11 -0800 Subject: [PATCH] Add .editorconfig + code style fixes --- .editorconfig | 132 ++++++++++++++++++ .../Program.cs | 6 +- .../DummyDto.cs | 4 +- .../Program.cs | 4 +- .../Program.cs | 6 +- .../Program.cs | 9 +- .../Program.cs | 6 +- src/.editorconfig | 3 + .../Channels/IPayload.cs | 3 +- .../ConnectionBuilderExtensions.cs | 4 +- .../IConnectionBuilder.cs | 4 +- src/RabbitMQ.Next.Abstractions/ReplyCode.cs | 4 +- .../ConsumerBuilderExtensions.cs | 4 +- .../ConsumerExtensions.cs | 4 +- .../IConsumerBuilder.cs | 3 +- .../StreamOffset.cs | 2 +- src/RabbitMQ.Next.Consumer/ConsumerBuilder.cs | 3 +- .../DeliverMessageHandler.cs | 6 +- .../PublisherBuilderExtensions.cs | 3 +- .../ConfirmMessageHandler.cs | 3 +- src/RabbitMQ.Next.Publisher/Publisher.cs | 20 +-- .../PublisherChannel.cs | 6 +- .../SerializationBuilderExtensions.cs | 4 +- .../RabbitMQ.Next.Serialization.csproj | 12 -- .../StreamQueueDeclarationExtensions.cs | 6 +- .../Commands/ExchangeExistsCommand.cs | 4 +- .../Commands/QueueExistsCommand.cs | 4 +- src/RabbitMQ.Next/Buffers/MemorySegment.cs | 4 +- .../Buffers/PooledMemoryAccessor.cs | 4 +- src/RabbitMQ.Next/Buffers/SharedMemory.cs | 6 +- src/RabbitMQ.Next/Channels/Channel.cs | 7 +- .../Channels/MethodWithContentFrameHandler.cs | 4 +- src/RabbitMQ.Next/Connection.cs | 43 +++--- src/RabbitMQ.Next/ConnectionBuilder.cs | 4 +- src/RabbitMQ.Next/Sockets/EndpointResolver.cs | 10 +- src/RabbitMQ.Next/Tasks/TaskExtensions.cs | 13 +- .../Transport/Framing.ContentHeader.cs | 8 +- src/RabbitMQ.Next/Transport/MessageBuilder.cs | 21 ++- .../Methods/Connection/SecureMethodParser.cs | 3 +- .../Consumer/ConsumerBenchmarks.cs | 24 ++-- tests/RabbitMQ.Next.Benchmarks/Helper.cs | 4 +- tests/RabbitMQ.Next.Benchmarks/Program.cs | 8 +- .../Publisher/PublishNoConfirmBenchmarks.cs | 10 +- .../Publisher/PublisherBenchmarks.cs | 10 +- .../Auth/PlainAuthMechanismTests.cs | 15 +- .../ConnectionBuilderExtensionsTests.cs | 6 +- .../Abstractions/ExceptionsTests.cs | 12 +- .../Buffers/MemoryBlockExtensionsTests.cs | 12 +- .../Channels/ChannelPoolTests.cs | 53 ++++++- .../Consumer/ConsumerBuilderTests.cs | 16 +-- .../Consumer/QueueConsumerBuilderTests.cs | 4 +- tests/RabbitMQ.Next.Tests/EndpointTests.cs | 13 +- tests/RabbitMQ.Next.Tests/Mocks/Helpers.cs | 4 +- .../Attributes/AttributeTransformerTests.cs | 34 ++++- .../Converters/StringConverterTests.cs | 4 +- .../PlainText/PlainTextSerializerTests.cs | 8 +- .../PlainText/SequenceEnumeratorTests.cs | 10 +- .../Transport/BinaryReadExtensionsTests.cs | 6 +- .../Transport/BinaryWriteExtensionsTests.cs | 10 +- .../Transport/FramingTests.ContentHeader.cs | 36 ++--- .../Transport/LazyMessagePropertiesTests.cs | 36 ++--- .../Transport/Methods/Basic/ModelTests.cs | 93 ++++++------ .../Methods/Basic/SerializationTests.cs | 6 +- .../Methods/Connection/ModelTests.cs | 34 ++--- .../Methods/Connection/SerializationTests.cs | 13 +- .../Transport/Methods/Exchange/ModelTests.cs | 29 ++-- .../Transport/Methods/Queue/ModelTests.cs | 44 +++--- 67 files changed, 569 insertions(+), 381 deletions(-) create mode 100644 .editorconfig create mode 100644 src/.editorconfig delete mode 100644 src/RabbitMQ.Next.Serialization/RabbitMQ.Next.Serialization.csproj diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..1b49ce35 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,132 @@ +[*] +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = false +insert_final_newline = false +indent_style = space +indent_size = 4 + +[{*.yml,*.yaml}] +indent_size = 2 + +[*.json] +indent_size = 2 + +[{*.sh,*.ps1}] +indent_size = 2 + +# XML project files +[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}] +indent_size = 2 + +# XML config files +[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}] +indent_size = 2 + +# Code files +[*.{cs,csx,vb,vbx}] +insert_final_newline = true +############################### +# .NET Coding Conventions # +############################### +[*.{cs,vb}] +# Organize usings +dotnet_sort_system_directives_first = true +# this. preferences +dotnet_style_qualification_for_field = true:warning +dotnet_style_qualification_for_property = true:warning +dotnet_style_qualification_for_method = true:warning +dotnet_style_qualification_for_event = true:warning +# Language keywords vs BCL types preferences +dotnet_style_predefined_type_for_locals_parameters_members = true:silent +dotnet_style_predefined_type_for_member_access = true:silent +# Parentheses preferences +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion +# Modifier preferences +dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning +dotnet_style_readonly_field = true:suggestion +# Expression-level preferences +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:silent +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +############################### +# Naming Conventions # +############################### +# Style Definitions +dotnet_naming_style.pascal_case_style.capitalization = pascal_case +# Use PascalCase for constant fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields.required_modifiers = const +############################### +# C# Coding Conventions # +############################### +[*.cs] +# var preferences +csharp_style_var_for_built_in_types = true:silent +csharp_style_var_when_type_is_apparent = true:silent +csharp_style_var_elsewhere = true:silent +# Expression-bodied members +csharp_style_expression_bodied_methods = false:silent +csharp_style_expression_bodied_constructors = false:silent +csharp_style_expression_bodied_operators = false:silent +csharp_style_expression_bodied_properties = true:silent +csharp_style_expression_bodied_indexers = true:silent +csharp_style_expression_bodied_accessors = true:silent +# Pattern matching preferences +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +# Null-checking preferences +csharp_style_throw_expression = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion +# Modifier preferences +csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion +# Expression-level preferences +csharp_prefer_braces = true:silent +csharp_style_deconstructed_variable_declaration = true:suggestion +csharp_prefer_simple_default_expression = true:suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion +csharp_style_inlined_variable_declaration = true:suggestion +############################### +# C# Formatting Rules # +############################### +# New line preferences +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true +# Indentation preferences +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left +# Space preferences +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +# Wrapping preferences +csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true diff --git a/docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/Program.cs b/docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/Program.cs index 712bb32c..2e8772ef 100644 --- a/docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/Program.cs +++ b/docs/examples/RabbitMQ.Next.Examples.DemoSaslAuthMechanism/Program.cs @@ -3,9 +3,9 @@ namespace RabbitMQ.Next.Examples.DemoSaslAuthMechanism; -class Program +internal static class Program { - static async Task Main() + private static async Task Main() { Console.WriteLine("Hello World! Will try to connect RabbitMQ server with RABBIT-CR-DEMO auth mechanism."); @@ -21,4 +21,4 @@ static async Task Main() Console.ReadKey(); } -} \ No newline at end of file +} diff --git a/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/DummyDto.cs b/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/DummyDto.cs index 30f62c0d..bade71d4 100644 --- a/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/DummyDto.cs +++ b/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/DummyDto.cs @@ -2,5 +2,5 @@ public class DummyDto { - public string SomeProperty { get; set; } -} \ No newline at end of file + public string SomeProperty { get; init; } +} diff --git a/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/Program.cs b/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/Program.cs index 9852bc3f..fe993fe4 100644 --- a/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/Program.cs +++ b/docs/examples/RabbitMQ.Next.Examples.DynamicSerializer/Program.cs @@ -9,9 +9,9 @@ namespace RabbitMQ.Next.Examples.DynamicSerializer; -class Program +internal static class Program { - static async Task Main() + private static async Task Main() { await using var connection = ConnectionBuilder.Default .Endpoint("amqp://test2:test2@localhost:5672/") diff --git a/docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs b/docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs index 8af3b682..a8d102b3 100644 --- a/docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs +++ b/docs/examples/RabbitMQ.Next.Examples.SimpleConsumer/Program.cs @@ -6,9 +6,9 @@ namespace RabbitMQ.Next.Examples.SimpleConsumer; -class Program +internal static class Program { - static async Task Main() + private static async Task Main() { Console.WriteLine("Hello World! This is consumer based on RabbitMQ.Next library."); @@ -30,7 +30,7 @@ static async Task Main() MonitorKeypressAsync(cancellation); - await consumer.ConsumeAsync(async (message, content) => + await consumer.ConsumeAsync((message, content) => { Console.WriteLine($"[{DateTimeOffset.Now.TimeOfDay}] Message received via '{message.Exchange}' exchange: {content.Get()}"); } ,cancellation.Token); diff --git a/docs/examples/RabbitMQ.Next.Examples.SimplePublisher/Program.cs b/docs/examples/RabbitMQ.Next.Examples.SimplePublisher/Program.cs index ef85d274..25ba60ea 100644 --- a/docs/examples/RabbitMQ.Next.Examples.SimplePublisher/Program.cs +++ b/docs/examples/RabbitMQ.Next.Examples.SimplePublisher/Program.cs @@ -7,9 +7,9 @@ namespace RabbitMQ.Next.Examples.SimplePublisher; -class Program +internal static class Program { - static async Task Main() + private static async Task Main() { Console.WriteLine("Hello World! This is publisher based on RabbitMQ.Next library."); @@ -33,10 +33,9 @@ static async Task Main() Console.WriteLine("Publisher created. Type any text to send it to the 'amq.fanout' exchange. Enter empty string to exit"); - string input; while(true) { - input = Console.ReadLine(); + var input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; @@ -53,4 +52,4 @@ static async Task Main() } } } -} \ No newline at end of file +} diff --git a/docs/examples/RabbitMQ.Next.Examples.TopologyBuilder/Program.cs b/docs/examples/RabbitMQ.Next.Examples.TopologyBuilder/Program.cs index 87987c3c..fa2f34fe 100644 --- a/docs/examples/RabbitMQ.Next.Examples.TopologyBuilder/Program.cs +++ b/docs/examples/RabbitMQ.Next.Examples.TopologyBuilder/Program.cs @@ -5,9 +5,9 @@ namespace RabbitMQ.Next.Examples.TopologyBuilder; -class Program +internal static class Program { - static async Task Main() + private static async Task Main() { try { @@ -56,4 +56,4 @@ await topology.Queue.DeclareClassicAsync("my-advanced-queue", throw; } } -} \ No newline at end of file +} diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 00000000..7a482767 --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,3 @@ +[*.{cs,vb}] +# Rider specific settings +configure_await_analysis_mode = library \ No newline at end of file diff --git a/src/RabbitMQ.Next.Abstractions/Channels/IPayload.cs b/src/RabbitMQ.Next.Abstractions/Channels/IPayload.cs index 3e260d97..386550d1 100644 --- a/src/RabbitMQ.Next.Abstractions/Channels/IPayload.cs +++ b/src/RabbitMQ.Next.Abstractions/Channels/IPayload.cs @@ -1,9 +1,8 @@ using System; using RabbitMQ.Next.Messaging; -using RabbitMQ.Next.Serialization; namespace RabbitMQ.Next.Channels; public interface IPayload: IMessageProperties, IContentAccessor, IDisposable { -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Abstractions/ConnectionBuilderExtensions.cs b/src/RabbitMQ.Next.Abstractions/ConnectionBuilderExtensions.cs index c84e88c8..8cd38d18 100644 --- a/src/RabbitMQ.Next.Abstractions/ConnectionBuilderExtensions.cs +++ b/src/RabbitMQ.Next.Abstractions/ConnectionBuilderExtensions.cs @@ -48,7 +48,7 @@ private static (string host, int port, bool ssl, string vhost, IAuthMechanism au if (!string.Equals(endpoint.Scheme, DefaultSchemaName, StringComparison.OrdinalIgnoreCase) && !string.Equals(endpoint.Scheme, SslSchemaName, StringComparison.OrdinalIgnoreCase)) { - throw new ArgumentException(@"Endpoint scheme '{endpoint.Scheme}' does not supported.", nameof(endpoint)); + throw new ArgumentException("Endpoint scheme '{endpoint.Scheme}' does not supported.", nameof(endpoint)); } var ssl = endpoint.Scheme == SslSchemaName; @@ -87,4 +87,4 @@ private static (string host, int port, bool ssl, string vhost, IAuthMechanism au return (endpoint.Host, port, ssl, vhost, authMechanism); } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Abstractions/IConnectionBuilder.cs b/src/RabbitMQ.Next.Abstractions/IConnectionBuilder.cs index d61f346f..2db66512 100644 --- a/src/RabbitMQ.Next.Abstractions/IConnectionBuilder.cs +++ b/src/RabbitMQ.Next.Abstractions/IConnectionBuilder.cs @@ -1,5 +1,3 @@ -using System.Threading; -using System.Threading.Tasks; using RabbitMQ.Next.Serialization; namespace RabbitMQ.Next; @@ -19,4 +17,4 @@ public interface IConnectionBuilder: ISerializationBuilder IConnectionBuilder MaxFrameSize(int sizeBytes); IConnection Build(); -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Abstractions/ReplyCode.cs b/src/RabbitMQ.Next.Abstractions/ReplyCode.cs index 06f0f7bd..95ac5655 100644 --- a/src/RabbitMQ.Next.Abstractions/ReplyCode.cs +++ b/src/RabbitMQ.Next.Abstractions/ReplyCode.cs @@ -20,5 +20,5 @@ public enum ReplyCode : ushort ResourceError = 506, NotAllowed = 530, NotImplemented = 540, - InternalError = 541 -} \ No newline at end of file + InternalError = 541, +} diff --git a/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerBuilderExtensions.cs b/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerBuilderExtensions.cs index 19f78028..dec6654c 100644 --- a/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerBuilderExtensions.cs +++ b/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerBuilderExtensions.cs @@ -32,7 +32,7 @@ public static IConsumerBuilder BindToStream(this IConsumerBuilder consumer, stri OffsetType.Hour => $"{offset.Argument}h", OffsetType.Minute => $"{offset.Argument}m", OffsetType.Second => $"{offset.Argument}s", - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException(), }; consumer.BindToQueue(stream, s => @@ -65,4 +65,4 @@ public static IConsumerBuilder UseConsumerMiddleware(this IConsumerBuilder build return builder; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerExtensions.cs b/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerExtensions.cs index 2e0ae836..de5ce68b 100644 --- a/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerExtensions.cs +++ b/src/RabbitMQ.Next.Consumer.Abstractions/ConsumerExtensions.cs @@ -11,6 +11,6 @@ public static Task ConsumeAsync(this IConsumer consumer, Action consumer.ConsumeAsync((m, c) => { handler(m, c); - return default; + return Task.CompletedTask; }, cancellation); -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Consumer.Abstractions/IConsumerBuilder.cs b/src/RabbitMQ.Next.Consumer.Abstractions/IConsumerBuilder.cs index 04144139..c262ab6c 100644 --- a/src/RabbitMQ.Next.Consumer.Abstractions/IConsumerBuilder.cs +++ b/src/RabbitMQ.Next.Consumer.Abstractions/IConsumerBuilder.cs @@ -1,5 +1,4 @@ using System; -using System.Threading; using System.Threading.Tasks; using RabbitMQ.Next.Channels; using RabbitMQ.Next.Messaging; @@ -21,4 +20,4 @@ public interface IConsumerBuilder IConsumerBuilder OnPoisonMessage(PoisonMessageMode mode); IConsumerBuilder UseConsumerMiddleware(Func,Task> middleware); -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Consumer.Abstractions/StreamOffset.cs b/src/RabbitMQ.Next.Consumer.Abstractions/StreamOffset.cs index ced7500d..e13b7590 100644 --- a/src/RabbitMQ.Next.Consumer.Abstractions/StreamOffset.cs +++ b/src/RabbitMQ.Next.Consumer.Abstractions/StreamOffset.cs @@ -41,5 +41,5 @@ public enum OffsetType Day, Hour, Minute, - Second + Second, } diff --git a/src/RabbitMQ.Next.Consumer/ConsumerBuilder.cs b/src/RabbitMQ.Next.Consumer/ConsumerBuilder.cs index 71632468..a31c9196 100644 --- a/src/RabbitMQ.Next.Consumer/ConsumerBuilder.cs +++ b/src/RabbitMQ.Next.Consumer/ConsumerBuilder.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Threading; using System.Threading.Tasks; using RabbitMQ.Next.Channels; using RabbitMQ.Next.Messaging; @@ -89,4 +88,4 @@ public IConsumerBuilder UseConsumerMiddleware(Func this.deliverChannel.Writer.TryWrite(new (method, payload)); + => this.deliverChannel.Writer.TryWrite(new DeliveredMessage(method, payload)); public void Release(Exception ex = null) @@ -59,7 +59,7 @@ private async Task ProcessDeliveredMessagesAsync() await this.messageHandler(message, message).ConfigureAwait(false); await this.acknowledgement.AckAsync(message.DeliveryTag).ConfigureAwait(false); } - catch (Exception) + catch (Exception ex) { await this.acknowledgement.NackAsync(message.DeliveryTag, this.onPoisonMessage == PoisonMessageMode.Requeue).ConfigureAwait(false); } @@ -70,4 +70,4 @@ private async Task ProcessDeliveredMessagesAsync() } } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Publisher.Abstractions/PublisherBuilderExtensions.cs b/src/RabbitMQ.Next.Publisher.Abstractions/PublisherBuilderExtensions.cs index 7fe945f9..9a77cadf 100644 --- a/src/RabbitMQ.Next.Publisher.Abstractions/PublisherBuilderExtensions.cs +++ b/src/RabbitMQ.Next.Publisher.Abstractions/PublisherBuilderExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Threading; using System.Threading.Tasks; using RabbitMQ.Next.Messaging; @@ -29,4 +28,4 @@ public static IPublisherBuilder UsePublishMiddleware(this IPublisherBuilder buil return builder; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Publisher/ConfirmMessageHandler.cs b/src/RabbitMQ.Next.Publisher/ConfirmMessageHandler.cs index 277f7460..e54bf46f 100644 --- a/src/RabbitMQ.Next.Publisher/ConfirmMessageHandler.cs +++ b/src/RabbitMQ.Next.Publisher/ConfirmMessageHandler.cs @@ -5,7 +5,6 @@ using System.Threading; using System.Threading.Tasks; using RabbitMQ.Next.Channels; -using RabbitMQ.Next.Messaging; using RabbitMQ.Next.Tasks; using RabbitMQ.Next.Transport.Methods.Basic; @@ -100,4 +99,4 @@ private void AckMultiple(ulong deliveryTag, bool isPositive) this.pendingConfirms.TryRemove(key, out _); } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Publisher/Publisher.cs b/src/RabbitMQ.Next.Publisher/Publisher.cs index 6ff68cb7..b4f67bec 100644 --- a/src/RabbitMQ.Next.Publisher/Publisher.cs +++ b/src/RabbitMQ.Next.Publisher/Publisher.cs @@ -83,10 +83,11 @@ private async Task PublishAsyncImpl(TContent content, MessageBuilder m try { this.CheckDisposed(); - message.SetClrType(typeof(TContent)); if (this.publishMiddlewares?.Count > 0) { + message.SetClrType(typeof(TContent)); + var pipeline = (IMessageBuilder m, IContentAccessor c) => this.InternalPublishAsync(m, c.Get()); for (var i = this.publishMiddlewares.Count - 1; i >= 0; i--) { @@ -114,10 +115,11 @@ private async Task PublishAsyncImpl(TContent content, MessageBuilder m private async Task InternalPublishAsync(IMessageBuilder message, TContent content) { var flags = ComposePublishFlags(message); - var ch = await this.GetChannelAsync(); - - var deliveryTag = await ch.PublishAsync(this.exchange, message.RoutingKey, content, message, flags); - + var ch = await this.GetChannelAsync().ConfigureAwait(false); + + var deliveryTag = await ch.PublishAsync(this.exchange, message.RoutingKey, content, message, flags) + .ConfigureAwait(false); + var confirmed = await this.confirms.WaitForConfirmAsync(deliveryTag, default).ConfigureAwait(false); if (!confirmed) { @@ -125,8 +127,8 @@ private async Task InternalPublishAsync(IMessageBuilder message, TCont throw new DeliveryFailedException(); } } - - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] private void CheckDisposed() @@ -162,7 +164,7 @@ private async ValueTask InitializeChannelAsync() ch = await this.connection.OpenChannelAsync().ConfigureAwait(false); // validate if exchange exists - await ch.SendAsync(new DeclareMethod(this.exchange)); + await ch.SendAsync(new DeclareMethod(this.exchange)).ConfigureAwait(false); if (this.confirms != null) { @@ -207,4 +209,4 @@ private static PublishFlags ComposePublishFlags(IMessageBuilder message) return flags; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Publisher/PublisherChannel.cs b/src/RabbitMQ.Next.Publisher/PublisherChannel.cs index 81fcd707..95a60997 100644 --- a/src/RabbitMQ.Next.Publisher/PublisherChannel.cs +++ b/src/RabbitMQ.Next.Publisher/PublisherChannel.cs @@ -36,11 +36,11 @@ public async ValueTask GetChannelAsync(CancellationToken cancellation) { if (this.channel == null) { - var ch = await this.connection.OpenChannelAsync(cancellation); + var ch = await this.connection.OpenChannelAsync(cancellation).ConfigureAwait(false); for (var i = 0; i < this.initializers.Count; i++) { - await this.initializers[i].Invoke(ch); + await this.initializers[i].Invoke(ch).ConfigureAwait(false); } this.channel = ch; @@ -57,4 +57,4 @@ public async ValueTask GetChannelAsync(CancellationToken cancellation) } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Serialization.PlainText/SerializationBuilderExtensions.cs b/src/RabbitMQ.Next.Serialization.PlainText/SerializationBuilderExtensions.cs index f4b2c8ed..64bd29b8 100644 --- a/src/RabbitMQ.Next.Serialization.PlainText/SerializationBuilderExtensions.cs +++ b/src/RabbitMQ.Next.Serialization.PlainText/SerializationBuilderExtensions.cs @@ -8,7 +8,7 @@ public static class SerializationBuilderExtensions public static TBuilder UsePlainTextSerializer(this TBuilder builder, Action serializerBuilder = null) where TBuilder : ISerializationBuilder { - serializerBuilder ??= (b) => b.UseDefaultConverters(); + serializerBuilder ??= b => b.UseDefaultConverters(); var plainTextSerializerBuilder = new PlainTextSerializerBuilder(); serializerBuilder.Invoke(plainTextSerializerBuilder); @@ -17,4 +17,4 @@ public static TBuilder UsePlainTextSerializer(this TBuilder builder, A return builder; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.Serialization/RabbitMQ.Next.Serialization.csproj b/src/RabbitMQ.Next.Serialization/RabbitMQ.Next.Serialization.csproj deleted file mode 100644 index a5e915b6..00000000 --- a/src/RabbitMQ.Next.Serialization/RabbitMQ.Next.Serialization.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - net6.0 - RabbitMQ.Next.Serialization - - - - - - - diff --git a/src/RabbitMQ.Next.TopologyBuilder.Abstractions/StreamQueueDeclarationExtensions.cs b/src/RabbitMQ.Next.TopologyBuilder.Abstractions/StreamQueueDeclarationExtensions.cs index d452dc5d..1be8ea21 100644 --- a/src/RabbitMQ.Next.TopologyBuilder.Abstractions/StreamQueueDeclarationExtensions.cs +++ b/src/RabbitMQ.Next.TopologyBuilder.Abstractions/StreamQueueDeclarationExtensions.cs @@ -30,7 +30,7 @@ public static IStreamQueueDeclaration MaxAge(this IStreamQueueDeclaration declar AgeUnit.Hour => "h", AgeUnit.Minute => "m", AgeUnit.Second => "s", - _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, null) + _ => throw new ArgumentOutOfRangeException(nameof(unit), unit, null), }; declaration.Argument("max-age", string.Concat(duration.ToString(), unitSuffix)); @@ -58,5 +58,5 @@ public enum AgeUnit Day, Hour, Minute, - Second -} \ No newline at end of file + Second, +} diff --git a/src/RabbitMQ.Next.TopologyBuilder/Commands/ExchangeExistsCommand.cs b/src/RabbitMQ.Next.TopologyBuilder/Commands/ExchangeExistsCommand.cs index 5f23e801..16e5048c 100644 --- a/src/RabbitMQ.Next.TopologyBuilder/Commands/ExchangeExistsCommand.cs +++ b/src/RabbitMQ.Next.TopologyBuilder/Commands/ExchangeExistsCommand.cs @@ -25,7 +25,7 @@ public async Task ExecuteAsync(IChannel channel, CancellationToken cancell { try { - await channel.SendAsync(new DeclareMethod(this.exchange), cancellation); + await channel.SendAsync(new DeclareMethod(this.exchange), cancellation).ConfigureAwait(false); return true; } catch(ChannelException ex) when (ex.FailedMethodId == MethodId.ExchangeDeclare) @@ -33,4 +33,4 @@ public async Task ExecuteAsync(IChannel channel, CancellationToken cancell return false; } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next.TopologyBuilder/Commands/QueueExistsCommand.cs b/src/RabbitMQ.Next.TopologyBuilder/Commands/QueueExistsCommand.cs index 0e7bd3a2..9654ce38 100644 --- a/src/RabbitMQ.Next.TopologyBuilder/Commands/QueueExistsCommand.cs +++ b/src/RabbitMQ.Next.TopologyBuilder/Commands/QueueExistsCommand.cs @@ -25,7 +25,7 @@ public async Task ExecuteAsync(IChannel channel, CancellationToken cancell { try { - await channel.SendAsync(new DeclareMethod(this.queue), cancellation); + await channel.SendAsync(new DeclareMethod(this.queue), cancellation).ConfigureAwait(false); return true; } catch(ChannelException ex) when (ex.FailedMethodId == MethodId.QueueDeclare) @@ -33,4 +33,4 @@ public async Task ExecuteAsync(IChannel channel, CancellationToken cancell return false; } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Buffers/MemorySegment.cs b/src/RabbitMQ.Next/Buffers/MemorySegment.cs index e533d093..d635757d 100644 --- a/src/RabbitMQ.Next/Buffers/MemorySegment.cs +++ b/src/RabbitMQ.Next/Buffers/MemorySegment.cs @@ -20,11 +20,11 @@ public MemorySegment Append(ReadOnlyMemory segment) var chunk = new MemorySegment(segment) { - RunningIndex = this.RunningIndex + this.Memory.Length + RunningIndex = this.RunningIndex + this.Memory.Length, }; this.Next = chunk; return chunk; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Buffers/PooledMemoryAccessor.cs b/src/RabbitMQ.Next/Buffers/PooledMemoryAccessor.cs index 0bfa81b4..dfc53942 100644 --- a/src/RabbitMQ.Next/Buffers/PooledMemoryAccessor.cs +++ b/src/RabbitMQ.Next/Buffers/PooledMemoryAccessor.cs @@ -56,7 +56,7 @@ public ReadOnlyMemory Memory get { this.CheckDisposed(); - return new(this.memory, this.offset, this.Size); + return new ReadOnlyMemory(this.memory, this.offset, this.Size); } } @@ -89,4 +89,4 @@ private void CheckDisposed() throw new ObjectDisposedException(nameof(PooledMemoryAccessor)); } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Buffers/SharedMemory.cs b/src/RabbitMQ.Next/Buffers/SharedMemory.cs index 9fe0f510..e300cf1c 100644 --- a/src/RabbitMQ.Next/Buffers/SharedMemory.cs +++ b/src/RabbitMQ.Next/Buffers/SharedMemory.cs @@ -81,7 +81,7 @@ public MemoryAccessor(SharedMemory owner, int offset, int size) this.owner = owner; this.offset = offset; this.Size = size; - this.Span = new (this.owner.memory, offset, size); + this.Span = new ReadOnlySpan(this.owner.memory, offset, size); } public int Size { get; } @@ -134,7 +134,7 @@ public ReadOnlyMemory Memory get { this.CheckDisposed(); - return new(this.owner.memory, this.offset, this.Size); + return new ReadOnlyMemory(this.owner.memory, this.offset, this.Size); } } @@ -168,4 +168,4 @@ private void CheckDisposed() } } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Channels/Channel.cs b/src/RabbitMQ.Next/Channels/Channel.cs index 1779e0a6..ac964626 100644 --- a/src/RabbitMQ.Next/Channels/Channel.cs +++ b/src/RabbitMQ.Next/Channels/Channel.cs @@ -113,10 +113,7 @@ public async ValueTask PublishAsync( try { messageBuilder.WriteMethodFrame(publishMethod); - messageBuilder.WriteContentFrame( - (properties, content, this.serializer), - properties, - (st, buffer) => st.serializer.Serialize(st.properties, st.content, buffer)); + messageBuilder.WriteContentFrame(properties, content, this.serializer); memory = messageBuilder.Complete(); } finally @@ -236,4 +233,4 @@ public void PushFrame(FrameType type, SharedMemory.MemoryAccessor payload) this.currentFrameHandler = null; } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Channels/MethodWithContentFrameHandler.cs b/src/RabbitMQ.Next/Channels/MethodWithContentFrameHandler.cs index 7caab41e..5af58aab 100644 --- a/src/RabbitMQ.Next/Channels/MethodWithContentFrameHandler.cs +++ b/src/RabbitMQ.Next/Channels/MethodWithContentFrameHandler.cs @@ -103,6 +103,6 @@ private FrameType ParseContentBodyFrame(SharedMemory.MemoryAccessor payload) } this.pendingContentSize -= payload.Size; - return (this.pendingContentSize > 0) ? FrameType.ContentBody : FrameType.None; + return this.pendingContentSize > 0 ? FrameType.ContentBody : FrameType.None; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Connection.cs b/src/RabbitMQ.Next/Connection.cs index bc809d60..53ae4f13 100644 --- a/src/RabbitMQ.Next/Connection.cs +++ b/src/RabbitMQ.Next/Connection.cs @@ -59,7 +59,7 @@ public async Task OpenChannelAsync(CancellationToken cancellation = de await this.EnsureConnectionOpenAsync(cancellation).ConfigureAwait(false); var channel = this.channelPool.Create(); - await channel.SendAsync(new Transport.Methods.Channel.OpenMethod(), cancellation); + await channel.SendAsync(new Transport.Methods.Channel.OpenMethod(), cancellation).ConfigureAwait(false); return channel; } @@ -71,7 +71,7 @@ public async ValueTask DisposeAsync() return; } - await this.connectionChannel.SendAsync(new CloseMethod((ushort)ReplyCode.Success, "Goodbye", 0)); + await this.connectionChannel.SendAsync(new CloseMethod((ushort)ReplyCode.Success, "Goodbye", 0)).ConfigureAwait(false); this.ConnectionClose(null); } @@ -80,7 +80,7 @@ public async Task OpenConnectionAsync(CancellationToken cancellation) { // todo: validate state here - this.socket = await EndpointResolver.OpenSocketAsync(this.connectionDetails.Settings.Endpoints, cancellation); + this.socket = await EndpointResolver.OpenSocketAsync(this.connectionDetails.Settings.Endpoints, cancellation).ConfigureAwait(false); this.socketIoCancellation = new CancellationTokenSource(); Task.Factory.StartNew(() => this.ReceiveLoop(this.socketIoCancellation.Token), TaskCreationOptions.LongRunning); @@ -108,9 +108,9 @@ public async Task OpenConnectionAsync(CancellationToken cancellation) var negotiateTask = NegotiateConnectionAsync(this.connectionChannel, this.connectionDetails.Settings, cancellation); var amqpHeaderMemory = new MemoryAccessor(ProtocolConstants.AmqpHeader); - await this.socketSender.Writer.WriteAsync(amqpHeaderMemory, cancellation); + await this.socketSender.Writer.WriteAsync(amqpHeaderMemory, cancellation).ConfigureAwait(false); - this.connectionDetails.Negotiated = await negotiateTask; + this.connectionDetails.Negotiated = await negotiateTask.ConfigureAwait(false); // start heartbeat Task.Factory.StartNew(() => this.HeartbeatLoop(this.connectionDetails.Negotiated.HeartbeatInterval, this.socketIoCancellation.Token), TaskCreationOptions.LongRunning); @@ -133,15 +133,15 @@ private async Task HeartbeatLoop(TimeSpan interval, CancellationToken cancellati var heartbeatMemory = new MemoryAccessor(ProtocolConstants.HeartbeatFrame); while (!cancellation.IsCancellationRequested) { - await Task.Delay(interval, cancellation); - await this.socketSender.Writer.WriteAsync(heartbeatMemory, cancellation); + await Task.Delay(interval, cancellation).ConfigureAwait(false); + await this.socketSender.Writer.WriteAsync(heartbeatMemory, cancellation).ConfigureAwait(false); } } - private async Task SendLoop() + private void SendLoop() { var socketChannel = this.socketSender.Reader; - while (await socketChannel.WaitToReadAsync()) + while (socketChannel.WaitToReadAsync().Wait()) { while (socketChannel.TryRead(out var memory)) { @@ -180,7 +180,7 @@ private void ReceiveLoop(CancellationToken cancellationToken) currentAccessor = currentAccessor.Slice(ProtocolConstants.FrameHeaderSize); // 2.2. Lookup for the target channel to push the frame - var targetChannel = (channel == ProtocolConstants.ConnectionChannel) ? this.connectionChannel : this.channelPool.Get(channel); + var targetChannel = channel == ProtocolConstants.ConnectionChannel ? this.connectionChannel : this.channelPool.Get(channel); // 2.3. Slice frame bytes SharedMemory.MemoryAccessor frameBytes; @@ -251,6 +251,7 @@ SharedMemory ReceiveNext(int expectedBytes, SharedMemory.MemoryAccessor previous { previousChunk.Span.CopyTo(buffer); bufferOffset = previousChunk.Size; + expectedBytes -= bufferOffset; } // Read data from the socket at least of requested size @@ -302,47 +303,47 @@ private static async Task NegotiateConnectionAsync(IChannel // connection should be forcibly closed if negotiation phase take more then 10s. cancellation = new CancellationTokenSource(TimeSpan.FromSeconds(10)).Token.Combine(cancellation); - var startMethod = await channel.WaitAsync(cancellation); + var startMethod = await channel.WaitAsync(cancellation).ConfigureAwait(false); if (!startMethod.Mechanisms.Contains(settings.Auth.Type)) { throw new NotSupportedException("Provided auth mechanism does not supported by the server"); } - var saslStartBytes = await settings.Auth.StartAsync(); + var saslStartBytes = await settings.Auth.StartAsync().ConfigureAwait(false); var tuneMethodTask = channel.WaitAsync(cancellation); var secureMethodTask = channel.WaitAsync(cancellation); - await channel.SendAsync(new StartOkMethod(settings.Auth.Type, saslStartBytes, settings.Locale, settings.ClientProperties), cancellation); + await channel.SendAsync(new StartOkMethod(settings.Auth.Type, saslStartBytes, settings.Locale, settings.ClientProperties), cancellation).ConfigureAwait(false); do { - await Task.WhenAny(tuneMethodTask, secureMethodTask); + await Task.WhenAny(tuneMethodTask, secureMethodTask).ConfigureAwait(false); if (secureMethodTask.IsCompleted) { - var secureRequest = await secureMethodTask; - var secureResponse = await settings.Auth.HandleChallengeAsync(secureRequest.Challenge.Span); + var secureRequest = await secureMethodTask.ConfigureAwait(false); + var secureResponse = await settings.Auth.HandleChallengeAsync(secureRequest.Challenge.Span).ConfigureAwait(false); // wait for another secure round-trip just in case secureMethodTask = channel.WaitAsync(cancellation); - await channel.SendAsync(new SecureOkMethod(secureResponse), cancellation); + await channel.SendAsync(new SecureOkMethod(secureResponse), cancellation).ConfigureAwait(false); } } while (!tuneMethodTask.IsCompleted); - var tuneMethod = await tuneMethodTask; + var tuneMethod = await tuneMethodTask.ConfigureAwait(false); var negotiationResult = new NegotiationResults( settings.Auth.Type, tuneMethod.ChannelMax, Math.Min(settings.MaxFrameSize, (int)tuneMethod.MaxFrameSize), TimeSpan.FromSeconds(tuneMethod.HeartbeatInterval)); - await channel.SendAsync(new TuneOkMethod(tuneMethod.ChannelMax, (uint)negotiationResult.FrameMaxSize, tuneMethod.HeartbeatInterval), cancellation); + await channel.SendAsync(new TuneOkMethod(tuneMethod.ChannelMax, (uint)negotiationResult.FrameMaxSize, tuneMethod.HeartbeatInterval), cancellation).ConfigureAwait(false); // todo: handle wrong vhost name - await channel.SendAsync(new OpenMethod(settings.Vhost), cancellation); + await channel.SendAsync(new OpenMethod(settings.Vhost), cancellation).ConfigureAwait(false); return negotiationResult; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/ConnectionBuilder.cs b/src/RabbitMQ.Next/ConnectionBuilder.cs index 97fc1f41..53f95aa9 100644 --- a/src/RabbitMQ.Next/ConnectionBuilder.cs +++ b/src/RabbitMQ.Next/ConnectionBuilder.cs @@ -18,7 +18,7 @@ public class ConnectionBuilder : IConnectionBuilder private string virtualhost = ProtocolConstants.DefaultVHost; private string clientLocale = DefaultLocale; private int maxFrameSize = DefaultMaxFrameSize; - private ISerializer serializer = null; // TODO: Implement noop serializer as default one + private ISerializer serializer; private ConnectionBuilder() : this(s => new Connection(s)) @@ -109,4 +109,4 @@ public IConnection Build() return this.factory(settings); } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Sockets/EndpointResolver.cs b/src/RabbitMQ.Next/Sockets/EndpointResolver.cs index 740d46c0..2e810702 100644 --- a/src/RabbitMQ.Next/Sockets/EndpointResolver.cs +++ b/src/RabbitMQ.Next/Sockets/EndpointResolver.cs @@ -39,20 +39,20 @@ private static async Task OpenSocketAsync(Endpoint endpoint, Cancellati IPAddress FindAddress(IReadOnlyList address, AddressFamily family) => address.FirstOrDefault(a => a.AddressFamily == family); - var addresses = await Dns.GetHostAddressesAsync(endpoint.Host, cancellation); + var addresses = await Dns.GetHostAddressesAsync(endpoint.Host, cancellation).ConfigureAwait(false); // 1. Try IP v6 var ipV6Address = FindAddress(addresses, AddressFamily.InterNetworkV6); if (ipV6Address != null) { - return await ConnectAsync(ipV6Address, endpoint, cancellation); + return await ConnectAsync(ipV6Address, endpoint, cancellation).ConfigureAwait(false); } // 2. Try IP v4 var ipV4Address = FindAddress(addresses, AddressFamily.InterNetwork); if (ipV4Address != null) { - return await ConnectAsync(ipV4Address, endpoint, cancellation); + return await ConnectAsync(ipV4Address, endpoint, cancellation).ConfigureAwait(false); } throw new NotSupportedException("Cannot connect to the endpoint: no supported protocols is available"); @@ -62,7 +62,7 @@ private static async Task ConnectAsync(IPAddress address, Endpoint endp { var ipEndPoint = new IPEndPoint(address, endpoint.Port); var socket = new Socket(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); - await socket.ConnectAsync(ipEndPoint, cancellation); + await socket.ConnectAsync(ipEndPoint, cancellation).ConfigureAwait(false); var stream = ConfigureStream(socket, endpoint); return new SocketWrapper(socket, stream); } @@ -85,4 +85,4 @@ private static Stream ConfigureStream(Socket socket, Endpoint endpoint) return stream; } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Tasks/TaskExtensions.cs b/src/RabbitMQ.Next/Tasks/TaskExtensions.cs index 5b1e699c..141c1cf6 100644 --- a/src/RabbitMQ.Next/Tasks/TaskExtensions.cs +++ b/src/RabbitMQ.Next/Tasks/TaskExtensions.cs @@ -17,6 +17,17 @@ public static Task AsTask(this CancellationToken cancellation) return tcs.Task; } + public static T Wait(this ValueTask valueTask) + { + if (valueTask.IsCompleted) + { + return valueTask.Result; + } + + var task = valueTask.AsTask(); + return task.GetAwaiter().GetResult(); + } + public static Task WithCancellation(this Task task, CancellationToken cancellation) { if (task.IsCompleted) @@ -71,4 +82,4 @@ private static async Task WrapTask(this Task task, Ca return await task.ConfigureAwait(false); } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Transport/Framing.ContentHeader.cs b/src/RabbitMQ.Next/Transport/Framing.ContentHeader.cs index cf1249e3..820d9974 100644 --- a/src/RabbitMQ.Next/Transport/Framing.ContentHeader.cs +++ b/src/RabbitMQ.Next/Transport/Framing.ContentHeader.cs @@ -11,7 +11,7 @@ public static Span WriteContentProperties(this Span buffer, IMessage { var flagsBuffer = buffer[..sizeof(ushort)]; buffer = buffer[sizeof(ushort)..]; - + var flags = MessageFlags.None; if (!string.IsNullOrEmpty(properties.ContentType)) { @@ -94,8 +94,8 @@ public static Span WriteContentProperties(this Span buffer, IMessage flagsBuffer.Write((ushort)flags); return buffer; } - - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ReadOnlyMemory SplitStringProperty(this ReadOnlyMemory source, out ReadOnlyMemory value, MessageFlags flags, MessageFlags flag) { @@ -138,4 +138,4 @@ internal static ReadOnlyMemory SplitFixedProperty(this ReadOnlyMemory memoryPool, ushort channel, int maxFrameSize) { this.Channel = channel; - this.maxFrameSize = maxFrameSize; + this.MaxFrameSize = maxFrameSize; this.writer = new InnerBufferWriter(memoryPool, channel, maxFrameSize); } public ushort Channel { get; } - public int MaxFrameSize => this.maxFrameSize; + public int MaxFrameSize { get; } public void WriteMethodFrame(TMethod method) where TMethod : struct, IOutgoingMethod @@ -38,7 +38,7 @@ public void WriteMethodFrame(TMethod method) private const uint ContentHeaderPrefix = (ushort)ClassId.Basic << 16; - public void WriteContentFrame(TState state, IMessageProperties properties, Action> contentBuilder) + public void WriteContentFrame(IMessageProperties properties, TContent content, ISerializer serializer) { this.writer.BeginFrame(FrameType.ContentHeader); var headerStartBuffer = this.writer.GetSpan(); @@ -55,7 +55,7 @@ public void WriteContentFrame(TState state, IMessageProperties propertie var beforeContentSize = this.writer.TotalPayloadBytes; this.writer.BeginFrame(FrameType.ContentBody); - contentBuilder.Invoke(state, this.writer); + serializer.Serialize(properties, content, this.writer); this.writer.EndFrame(); var contentSize = this.writer.TotalPayloadBytes - beforeContentSize; @@ -82,7 +82,6 @@ private class InnerBufferWriter : IBufferWriter private int bufferOffset; private FrameType frameType; private int frameHeaderOffset; - private long totalPayloadSize; public InnerBufferWriter(ObjectPool memoryPool, ushort channel, int frameMaxSize) { @@ -91,8 +90,8 @@ public InnerBufferWriter(ObjectPool memoryPool, ushort channel, int fram this.frameMaxSize = frameMaxSize; } - public long TotalPayloadBytes => this.totalPayloadSize; - + public long TotalPayloadBytes { get; private set; } + public void BeginFrame(FrameType type) { if(this.frameType != FrameType.None) @@ -126,7 +125,7 @@ public void Reset() this.bufferOffset = 0; this.frameType = FrameType.None; this.frameHeaderOffset = 0; - this.totalPayloadSize = 0; + this.TotalPayloadBytes = 0; } public void EndFrame() @@ -157,7 +156,7 @@ public void EndFrame() endBuffer.WriteFrameEnd(); this.bufferOffset += ProtocolConstants.FrameEndSize; - this.totalPayloadSize += frameSize; + this.TotalPayloadBytes += frameSize; this.frameType = FrameType.None; } @@ -229,4 +228,4 @@ private void FinalizeBuffer() } } } -} \ No newline at end of file +} diff --git a/src/RabbitMQ.Next/Transport/Methods/Connection/SecureMethodParser.cs b/src/RabbitMQ.Next/Transport/Methods/Connection/SecureMethodParser.cs index ee867820..fbcedb72 100644 --- a/src/RabbitMQ.Next/Transport/Methods/Connection/SecureMethodParser.cs +++ b/src/RabbitMQ.Next/Transport/Methods/Connection/SecureMethodParser.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace RabbitMQ.Next.Transport.Methods.Connection; @@ -11,4 +10,4 @@ public SecureMethod Parse(ReadOnlySpan payload) return new SecureMethod(challenge); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Benchmarks/Consumer/ConsumerBenchmarks.cs b/tests/RabbitMQ.Next.Benchmarks/Consumer/ConsumerBenchmarks.cs index 4aa562dd..0c029cd0 100644 --- a/tests/RabbitMQ.Next.Benchmarks/Consumer/ConsumerBenchmarks.cs +++ b/tests/RabbitMQ.Next.Benchmarks/Consumer/ConsumerBenchmarks.cs @@ -14,8 +14,8 @@ namespace RabbitMQ.Next.Benchmarks.Consumer; public class ConsumerBenchmarks { - private readonly int messagesCount = 10_000; - private readonly string queueName = "test-queue"; + private const int MessagesCount = 10_000; + private const string QueueName = "test-queue"; private IConnection connection; private RabbitMQ.Client.IConnection theirConnection; @@ -30,7 +30,7 @@ public async Task Setup() .UsePlainTextSerializer() .Build(); - ConnectionFactory factory = new ConnectionFactory() + ConnectionFactory factory = new ConnectionFactory { Uri = Helper.RabbitMqConnection, DispatchConsumersAsync = true, @@ -39,16 +39,16 @@ public async Task Setup() await this.connection.ConfigureAsync(async topology => { - await topology.Queue.DeclareClassicAsync(this.queueName); - await topology.Queue.BindAsync(this.queueName, "amq.fanout"); - await topology.Queue.PurgeAsync(this.queueName); + await topology.Queue.DeclareClassicAsync(QueueName); + await topology.Queue.BindAsync(QueueName, "amq.fanout"); + await topology.Queue.PurgeAsync(QueueName); }); var publisher = this.connection.Publisher("amq.fanout"); var payload = Helper.BuildDummyText(this.PayloadSize); - for (int i = 0; i < this.messagesCount * 20; i++) // 15 runs for benchmark + for (int i = 0; i < MessagesCount * 20; i++) // 15 runs for benchmark { await publisher.PublishAsync(payload, message => message @@ -81,7 +81,7 @@ public void ConsumeBaseLibrary() num++; model.BasicAck(ea.DeliveryTag, false); - if (num >= this.messagesCount) + if (num >= MessagesCount) { manualResetEvent.Set(); } @@ -92,7 +92,7 @@ public void ConsumeBaseLibrary() model.BasicQos(0, 10, false); var tag = model.BasicConsume( - queue: this.queueName, + queue: QueueName, autoAck: false, consumer: consumer, consumerTag: string.Empty, @@ -114,7 +114,7 @@ public async Task ConsumeAsync() var cs = new CancellationTokenSource(); var consumer = this.connection.Consumer( b => b - .BindToQueue(this.queueName) + .BindToQueue(QueueName) .PrefetchCount(10)); var consumeTask = consumer.ConsumeAsync((m,c) => @@ -122,7 +122,7 @@ public async Task ConsumeAsync() var data = c.Get(); var messageId = m.MessageId; num++; - if (num >= this.messagesCount) + if (num >= MessagesCount) { cs.Cancel(); } @@ -163,4 +163,4 @@ public async Task ConsumeAsync() // // Console.WriteLine($"Consumed: {num}"); // } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Benchmarks/Helper.cs b/tests/RabbitMQ.Next.Benchmarks/Helper.cs index 93240f5a..4380cc1f 100644 --- a/tests/RabbitMQ.Next.Benchmarks/Helper.cs +++ b/tests/RabbitMQ.Next.Benchmarks/Helper.cs @@ -20,5 +20,5 @@ public static string BuildDummyText(int length) } // TODO: find a proper way to store the connection in config - public static Uri RabbitMqConnection { get; } = new Uri("amqp://guest:guest@localhost:5672/"); -} \ No newline at end of file + public static Uri RabbitMqConnection { get; } = new ("amqp://guest:guest@localhost:5672/"); +} diff --git a/tests/RabbitMQ.Next.Benchmarks/Program.cs b/tests/RabbitMQ.Next.Benchmarks/Program.cs index b53a6937..507a8464 100644 --- a/tests/RabbitMQ.Next.Benchmarks/Program.cs +++ b/tests/RabbitMQ.Next.Benchmarks/Program.cs @@ -10,9 +10,9 @@ namespace RabbitMQ.Next.Benchmarks; -class Program +internal static class Program { - static void Main(string[] args) + private static void Main(string[] args) { BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, DefaultConfig.Instance @@ -22,10 +22,10 @@ static void Main(string[] args) Run = { RunStrategy = RunStrategy.Monitoring, IterationCount = 10, WarmupCount = 5, - } + }, }) .WithSummaryStyle(new SummaryStyle(CultureInfo.InvariantCulture, true, SizeUnit.KB, TimeUnit.Millisecond, false, true)) .AddLogicalGroupRules(BenchmarkLogicalGroupRule.ByCategory) ); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Benchmarks/Publisher/PublishNoConfirmBenchmarks.cs b/tests/RabbitMQ.Next.Benchmarks/Publisher/PublishNoConfirmBenchmarks.cs index 4f942b16..8f47ab1e 100644 --- a/tests/RabbitMQ.Next.Benchmarks/Publisher/PublishNoConfirmBenchmarks.cs +++ b/tests/RabbitMQ.Next.Benchmarks/Publisher/PublishNoConfirmBenchmarks.cs @@ -22,8 +22,10 @@ public PublishNoConfirmBenchmarks() .UsePlainTextSerializer() .Build(); - ConnectionFactory factory = new ConnectionFactory(); - factory.Uri = Helper.RabbitMqConnection; + ConnectionFactory factory = new ConnectionFactory + { + Uri = Helper.RabbitMqConnection, + }; this.theirConnection = factory.CreateConnection(); } @@ -56,7 +58,7 @@ await Task.WhenAll(Enumerable.Range(0, 10) { await Task.Yield(); - for (int i = num; i < parameters.Messages.Count; i = i + 10) + for (int i = num; i < parameters.Messages.Count; i += 10) { var data = parameters.Messages[i]; await publisher.PublishAsync(data, data.Payload, @@ -121,4 +123,4 @@ public TestCaseParameters(string name, IReadOnlyList<(string Payload, string Cor public override string ToString() => this.Name; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Benchmarks/Publisher/PublisherBenchmarks.cs b/tests/RabbitMQ.Next.Benchmarks/Publisher/PublisherBenchmarks.cs index 8b8ae163..c95882ca 100644 --- a/tests/RabbitMQ.Next.Benchmarks/Publisher/PublisherBenchmarks.cs +++ b/tests/RabbitMQ.Next.Benchmarks/Publisher/PublisherBenchmarks.cs @@ -17,8 +17,10 @@ public class PublisherBenchmarks public PublisherBenchmarks() { - ConnectionFactory factory = new ConnectionFactory(); - factory.Uri = Helper.RabbitMqConnection; + ConnectionFactory factory = new ConnectionFactory + { + Uri = Helper.RabbitMqConnection, + }; this.theirConnection = factory.CreateConnection(); this.connection = ConnectionBuilder.Default @@ -87,7 +89,7 @@ await publisher.PublishAsync(data, data.Payload, await publisher.DisposeAsync().ConfigureAwait(false); } - [GlobalCleanup()] + [GlobalCleanup] public async ValueTask CleanUpOfficialLibrary() { this.theirConnection.Close(); @@ -129,4 +131,4 @@ public TestCaseParameters(string name, IReadOnlyList<(string Payload, string Cor public override string ToString() => this.Name; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Abstractions/Auth/PlainAuthMechanismTests.cs b/tests/RabbitMQ.Next.Tests/Abstractions/Auth/PlainAuthMechanismTests.cs index 0f2897ad..f29028de 100644 --- a/tests/RabbitMQ.Next.Tests/Abstractions/Auth/PlainAuthMechanismTests.cs +++ b/tests/RabbitMQ.Next.Tests/Abstractions/Auth/PlainAuthMechanismTests.cs @@ -1,5 +1,4 @@ using System; -using System.Text; using System.Threading.Tasks; using NSubstitute; using RabbitMQ.Next.Auth; @@ -12,8 +11,8 @@ public class PlainAuthMechanismTests [Fact] public void CtorTests() { - var user = "test"; - var password = "pwd"; + const string user = "test"; + const string password = "pwd"; var auth = new PlainAuthMechanism(user, password); @@ -25,8 +24,8 @@ public void CtorTests() [Fact] public async Task StartAsyncTests() { - var user = "test"; - var password = "pwd"; + const string user = "test"; + const string password = "pwd"; var expected = "\0test\0pwd"u8.ToArray(); var auth = new PlainAuthMechanism(user, password); @@ -46,8 +45,8 @@ public async Task HandleChallengeAsyncThrows() [Fact] public void ExtensionTests() { - var user = "test2"; - var password = "pwd2"; + const string user = "test2"; + const string password = "pwd2"; var builder = Substitute.For(); builder.PlainAuth(user, password); @@ -55,4 +54,4 @@ public void ExtensionTests() builder.Received().Auth(Arg.Is(a => ((PlainAuthMechanism)a).UserName == user && ((PlainAuthMechanism)a).Password == password) ); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Abstractions/ConnectionBuilderExtensionsTests.cs b/tests/RabbitMQ.Next.Tests/Abstractions/ConnectionBuilderExtensionsTests.cs index 22486b6e..10236fcd 100644 --- a/tests/RabbitMQ.Next.Tests/Abstractions/ConnectionBuilderExtensionsTests.cs +++ b/tests/RabbitMQ.Next.Tests/Abstractions/ConnectionBuilderExtensionsTests.cs @@ -11,8 +11,8 @@ public class ConnectionBuilderExtensionsTests [Fact] public void AuthPlain() { - var user = "test1"; - var password = "pwd"; + const string user = "test1"; + const string password = "pwd"; var builder = Substitute.For(); builder.PlainAuth(user, password); @@ -93,4 +93,4 @@ public static IEnumerable AddEndpointTestCases() yield return new object[] {"amqps://[::1]", true, "[::1]", 5671, "/", null, null}; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Abstractions/ExceptionsTests.cs b/tests/RabbitMQ.Next.Tests/Abstractions/ExceptionsTests.cs index f4d22742..96c8adb2 100644 --- a/tests/RabbitMQ.Next.Tests/Abstractions/ExceptionsTests.cs +++ b/tests/RabbitMQ.Next.Tests/Abstractions/ExceptionsTests.cs @@ -10,9 +10,9 @@ public class ExceptionsTests [Fact] public void ChannelException() { - var errorCode = (ushort) 404; - var description = "not found"; - var failedMethodId = MethodId.BasicDeliver; + const ushort errorCode = 404; + const string description = "not found"; + const MethodId failedMethodId = MethodId.BasicDeliver; var ex = new ChannelException(errorCode, description, failedMethodId); @@ -25,8 +25,8 @@ public void ChannelException() [Fact] public void ConnectionException() { - var errorCode = (ushort) 404; - var description = "not found"; + const ushort errorCode = 404; + const string description = "not found"; var ex = new ConnectionException(errorCode, description); @@ -45,4 +45,4 @@ public void EndPointResolutionException() Assert.True(ex.InnerExceptions.ContainsKey(endpoint)); Assert.Equal(inner, ex.InnerExceptions[endpoint]); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Buffers/MemoryBlockExtensionsTests.cs b/tests/RabbitMQ.Next.Tests/Buffers/MemoryBlockExtensionsTests.cs index e56f42c6..88b63338 100644 --- a/tests/RabbitMQ.Next.Tests/Buffers/MemoryBlockExtensionsTests.cs +++ b/tests/RabbitMQ.Next.Tests/Buffers/MemoryBlockExtensionsTests.cs @@ -32,31 +32,31 @@ public static IEnumerable ToSequenceTestCases() yield return new object[] { Array.Empty(), - null + null, }; yield return new object[] { Array.Empty(), - new[] { Array.Empty()} + new[] { Array.Empty()}, }; yield return new object[] { new byte[] { 0x01 }, - new[] { new byte[] { 0x01 }} + new[] { new byte[] { 0x01 }}, }; yield return new object[] { new byte[] { 0x01, 0x02, 0x03 }, - new[] { new byte[] { 0x01 }, new byte[] { 0x02, 0x03 } } + new[] { new byte[] { 0x01 }, new byte[] { 0x02, 0x03 } }, }; yield return new object[] { new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }, - new[] { new byte[] { 0x01 }, new byte[] { 0x02, 0x03 }, new byte[] { 0x04, 0x05 } } + new[] { new byte[] { 0x01 }, new byte[] { 0x02, 0x03 }, new byte[] { 0x04, 0x05 } }, }; } @@ -96,4 +96,4 @@ private static IMemoryAccessor SubstituteMemoryAccessor(byte[] memory) return subject; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Channels/ChannelPoolTests.cs b/tests/RabbitMQ.Next.Tests/Channels/ChannelPoolTests.cs index eea638cc..219353c2 100644 --- a/tests/RabbitMQ.Next.Tests/Channels/ChannelPoolTests.cs +++ b/tests/RabbitMQ.Next.Tests/Channels/ChannelPoolTests.cs @@ -13,7 +13,14 @@ public class ChannelPoolTests [Fact] public void PoolStartsWithOne() { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory); pool.Create(); @@ -26,7 +33,14 @@ public void PoolStartsWithOne() [InlineData(5, 22)] public void CanResize(int initialSize, int num) { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory, initialSize); @@ -46,7 +60,14 @@ public void CanResize(int initialSize, int num) [InlineData(100, 10)] public async Task CreateTests(int number, int concurrencyLevel) { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory); var createTasks = Enumerable.Range(0, number) @@ -74,7 +95,14 @@ public async Task CreateTests(int number, int concurrencyLevel) [InlineData(10)] public void CanGet(int num) { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory); var channels = new Dictionary(); @@ -98,7 +126,14 @@ public void CanGet(int num) [InlineData(10, 100)] public void GetThrowsOnUnknownChannel(int channels, ushort ch) { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory); for (var i = 0; i < channels; i++) @@ -115,7 +150,14 @@ public void GetThrowsOnUnknownChannel(int channels, ushort ch) [InlineData(10, 5, 2)] public async Task CanReuseChannelAfterCompletion(int channels, params int[] chToComplete) { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory); for (var i = 0; i < channels; i++) @@ -146,7 +188,14 @@ public async Task CanReuseChannelAfterCompletion(int channels, params int[] chTo [Fact] public async Task CanReleaseAll() { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var factory = this.MockFactory(); +After: + var factory = ChannelPoolTests.MockFactory(); +*/ + var factory = MockFactory(); var pool = new ChannelPool(factory); for (var i = 0; i < 10; i++) @@ -163,7 +212,7 @@ public async Task CanReleaseAll() factory.Received(1)(Arg.Is(u => u > 0 && u <= 10)); } - private Func MockFactory() + private static Func MockFactory() { var factory = Substitute.For>(); factory(Arg.Any()).Returns(args => @@ -188,4 +237,4 @@ private Func MockFactory() }); return factory; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Consumer/ConsumerBuilderTests.cs b/tests/RabbitMQ.Next.Tests/Consumer/ConsumerBuilderTests.cs index 1439a144..e437e143 100644 --- a/tests/RabbitMQ.Next.Tests/Consumer/ConsumerBuilderTests.cs +++ b/tests/RabbitMQ.Next.Tests/Consumer/ConsumerBuilderTests.cs @@ -12,7 +12,7 @@ public class ConsumerBuilderTests public void PrefetchSize() { var consumerBuilder = new ConsumerBuilder(); - uint size = 12345; + const uint size = 12345; ((IConsumerBuilder) consumerBuilder).PrefetchSize(size); @@ -23,7 +23,7 @@ public void PrefetchSize() public void PrefetchCount() { var consumerBuilder = new ConsumerBuilder(); - ushort count = 42; + const ushort count = 42; ((IConsumerBuilder) consumerBuilder).PrefetchCount(count); @@ -34,7 +34,7 @@ public void PrefetchCount() public void ConcurrencyLevel() { var consumerBuilder = new ConsumerBuilder(); - byte level = 7; + const byte level = 7; ((IConsumerBuilder) consumerBuilder).ConcurrencyLevel(level); @@ -45,7 +45,7 @@ public void ConcurrencyLevel() public void ThrowsOnIncorrectConcurrencyLevel() { var consumerBuilder = new ConsumerBuilder(); - byte level = 0; + const byte level = 0; Assert.Throws(() => ((IConsumerBuilder) consumerBuilder).ConcurrencyLevel(level)); } @@ -73,7 +73,7 @@ public void SetAcknowledgerThrowsOnNull() public void OnPoisonMessage() { var consumerBuilder = new ConsumerBuilder(); - var val = PoisonMessageMode.Drop; + const PoisonMessageMode val = PoisonMessageMode.Drop; ((IConsumerBuilder) consumerBuilder).OnPoisonMessage(val); @@ -83,7 +83,7 @@ public void OnPoisonMessage() [Fact] public void DefaultBindToQueue() { - var queueName = "q1"; + const string queueName = "q1"; var builder = new ConsumerBuilder(); ((IConsumerBuilder)builder).BindToQueue(queueName); @@ -94,7 +94,7 @@ public void DefaultBindToQueue() [Fact] public void CanBindToQueue() { - var queueName = "q1"; + const string queueName = "q1"; var consumerBuilder = Substitute.For>(); var builder = new ConsumerBuilder(); @@ -103,4 +103,4 @@ public void CanBindToQueue() consumerBuilder.Received(); Assert.Contains(builder.Queues, x => x.Queue == queueName); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Consumer/QueueConsumerBuilderTests.cs b/tests/RabbitMQ.Next.Tests/Consumer/QueueConsumerBuilderTests.cs index 1acb1448..d9ef9f48 100644 --- a/tests/RabbitMQ.Next.Tests/Consumer/QueueConsumerBuilderTests.cs +++ b/tests/RabbitMQ.Next.Tests/Consumer/QueueConsumerBuilderTests.cs @@ -8,7 +8,7 @@ public class QueueConsumerBuilderTests [Fact] public void QueueName() { - var name = "queue1"; + const string name = "queue1"; var builder = new QueueConsumerBuilder(name); @@ -78,4 +78,4 @@ public void DefaultArguments() var builder = new QueueConsumerBuilder("test"); Assert.Null(builder.Arguments); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/EndpointTests.cs b/tests/RabbitMQ.Next.Tests/EndpointTests.cs index ad256648..43c83347 100644 --- a/tests/RabbitMQ.Next.Tests/EndpointTests.cs +++ b/tests/RabbitMQ.Next.Tests/EndpointTests.cs @@ -1,21 +1,20 @@ using Xunit; -namespace RabbitMQ.Next.Tests.Transport; +namespace RabbitMQ.Next.Tests; public class EndpointTests { [Fact] public void EndpointCtor() { - var host = "testhost"; - var port = 12345; - var ssl = true; + const string host = "testhost"; + const int port = 12345; - var endpoint = new Endpoint(host, port, ssl); + var endpoint = new Endpoint(host, port, true); Assert.Equal(host, endpoint.Host); Assert.Equal(port, endpoint.Port); - Assert.Equal(ssl, endpoint.UseSsl); + Assert.True(endpoint.UseSsl); } [Theory] @@ -28,4 +27,4 @@ public void ToUri(string expectedUri, bool ssl, string host, int port) Assert.Equal(expectedUri, uri.ToString()); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Mocks/Helpers.cs b/tests/RabbitMQ.Next.Tests/Mocks/Helpers.cs index 148c55d8..fbf32add 100644 --- a/tests/RabbitMQ.Next.Tests/Mocks/Helpers.cs +++ b/tests/RabbitMQ.Next.Tests/Mocks/Helpers.cs @@ -11,7 +11,7 @@ namespace RabbitMQ.Next.Tests.Mocks; internal static class Helpers { - private static IReadOnlyList<(string Charset, string Text, ReadOnlyMemory Bytes)> Texts = new [] + private static readonly IReadOnlyList<(string Charset, string Text, ReadOnlyMemory Bytes)> Texts = new [] { MakeText("Latin", "Lorem ipsu"), MakeText("Latin", "Lorem ipsum dolor sit amet, ne putent ornatus expetendis vix. Ea sed suas accusamus. Possim prodesset maiestatis sea te, graeci "), @@ -133,4 +133,4 @@ public static IReadOnlyDictionary ToArgsDictionary(this string[] return result; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Publisher/Attributes/AttributeTransformerTests.cs b/tests/RabbitMQ.Next.Tests/Publisher/Attributes/AttributeTransformerTests.cs index 6c00a57f..1cb179f5 100644 --- a/tests/RabbitMQ.Next.Tests/Publisher/Attributes/AttributeTransformerTests.cs +++ b/tests/RabbitMQ.Next.Tests/Publisher/Attributes/AttributeTransformerTests.cs @@ -1,5 +1,3 @@ -using System.Threading; -using System.Threading.Tasks; using NSubstitute; using RabbitMQ.Next.Publisher; using RabbitMQ.Next.Publisher.Attributes; @@ -14,7 +12,14 @@ public class AttributeTransformerTests [Fact] public void TestAssemblyAttributes() { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var message = this.CreateSubjectFor(); +After: + var message = AttributeTransformerTests.CreateSubjectFor(); +*/ + var message = CreateSubjectFor(); PublisherAttributes.Apply(message); @@ -24,7 +29,14 @@ public void TestAssemblyAttributes() [Fact] public void TestRoutingKeyAttribute() { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var message = this.CreateSubjectFor(); +After: + var message = AttributeTransformerTests.CreateSubjectFor(); +*/ + var message = CreateSubjectFor(); PublisherAttributes.Apply(message); @@ -35,7 +47,14 @@ public void TestRoutingKeyAttribute() [Fact] public void TestHeaderAttribute() { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var message = this.CreateSubjectFor(); +After: + var message = AttributeTransformerTests.CreateSubjectFor(); +*/ + var message = CreateSubjectFor(); PublisherAttributes.Apply(message); @@ -47,7 +66,14 @@ public void TestHeaderAttribute() [Fact] public void TestMultipleAttributes() { + +/* Unmerged change from project 'RabbitMQ.Next.Tests' +Before: var message = this.CreateSubjectFor(); +After: + var message = AttributeTransformerTests.CreateSubjectFor(); +*/ + var message = CreateSubjectFor(); PublisherAttributes.Apply(message); @@ -56,7 +82,7 @@ public void TestMultipleAttributes() message.Received().SetPriority(7); } - private IMessageBuilder CreateSubjectFor() + private static IMessageBuilder CreateSubjectFor() { var message = Substitute.For(); message.ClrType.Returns(typeof(TContentType)); @@ -84,4 +110,4 @@ private class HeaderAttributeData private class MultipleAttributesData { } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Serialization/PlainText/Converters/StringConverterTests.cs b/tests/RabbitMQ.Next.Tests/Serialization/PlainText/Converters/StringConverterTests.cs index c56c73fb..db20a4b0 100644 --- a/tests/RabbitMQ.Next.Tests/Serialization/PlainText/Converters/StringConverterTests.cs +++ b/tests/RabbitMQ.Next.Tests/Serialization/PlainText/Converters/StringConverterTests.cs @@ -47,7 +47,7 @@ public static IEnumerable FormatTestCases() public static IEnumerable ParseTestCases() { - yield return new object[] { string.Empty, new byte[0] }; + yield return new object[] { string.Empty, Array.Empty() }; var texts = Helpers.GetDummyTexts(0, 128); @@ -60,4 +60,4 @@ public static IEnumerable ParseTestCases() } } } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Serialization/PlainText/PlainTextSerializerTests.cs b/tests/RabbitMQ.Next.Tests/Serialization/PlainText/PlainTextSerializerTests.cs index 47e9ebf7..4848f04f 100644 --- a/tests/RabbitMQ.Next.Tests/Serialization/PlainText/PlainTextSerializerTests.cs +++ b/tests/RabbitMQ.Next.Tests/Serialization/PlainText/PlainTextSerializerTests.cs @@ -22,7 +22,7 @@ public void ThrowsOnMissConfiguredConverters() { var converters = new Dictionary { - [typeof(string)] = Substitute.For>() + [typeof(string)] = Substitute.For>(), }; Assert.Throws(() => new PlainTextSerializer(converters)); @@ -34,7 +34,7 @@ public void SerializeThrowsOnNotSupportedTypes() var message = Substitute.For(); var converters = new Dictionary { - [typeof(string)] = Substitute.For>() + [typeof(string)] = Substitute.For>(), }; var serializer = new PlainTextSerializer(converters); @@ -47,7 +47,7 @@ public void DeserializeThrowsOnNotSupportedTypes() var message = Substitute.For(); var converters = new Dictionary { - [typeof(string)] = Substitute.For>() + [typeof(string)] = Substitute.For>(), }; var serializer = new PlainTextSerializer(converters); @@ -59,4 +59,4 @@ public static IEnumerable EmptyConvertersTestCases() yield return new object[] { null }; yield return new object[] { new Dictionary() }; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Serialization/PlainText/SequenceEnumeratorTests.cs b/tests/RabbitMQ.Next.Tests/Serialization/PlainText/SequenceEnumeratorTests.cs index a051a5f9..96ae86c4 100644 --- a/tests/RabbitMQ.Next.Tests/Serialization/PlainText/SequenceEnumeratorTests.cs +++ b/tests/RabbitMQ.Next.Tests/Serialization/PlainText/SequenceEnumeratorTests.cs @@ -120,22 +120,22 @@ public static IEnumerable EnumerationTestCases() { yield return new object[] { - new byte[0][] + Array.Empty(), }; yield return new object[] { - new [] { new byte[] { 1, 2, 3} } + new [] { new byte[] { 1, 2, 3} }, }; yield return new object[] { - new [] { new byte[] { 1, 2, 3}, new byte[] { 4, 5, 6} } + new [] { new byte[] { 1, 2, 3}, new byte[] { 4, 5, 6} }, }; yield return new object[] { - new [] { new byte[] { 1, 2, 3}, new byte[] { 4, 5, 6}, new byte[] { 7, 8, 9, 10} } + new [] { new byte[] { 1, 2, 3}, new byte[] { 4, 5, 6}, new byte[] { 7, 8, 9, 10} }, }; } @@ -156,4 +156,4 @@ private static ReadOnlySequence BuildSequence(params T[][] chunks) return new ReadOnlySequence(first, 0, last, last.Memory.Length); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/BinaryReadExtensionsTests.cs b/tests/RabbitMQ.Next.Tests/Transport/BinaryReadExtensionsTests.cs index 8380890f..9eeddd40 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/BinaryReadExtensionsTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/BinaryReadExtensionsTests.cs @@ -290,8 +290,8 @@ public static IEnumerable ReadFieldTestCases() yield return new object[] {new byte[] {83, 0, 0, 0, 5, 72, 101, 108, 108, 111, 1}, "Hello", new byte[] {1}}; yield return new object[] {new byte[] {65, 0, 0, 0, 17, 66, 42, 102, 195, 245, 72, 64, 83, 0, 0, 0, 5, 72, 101, 108, 108, 111}, new object[] {(byte) 42, (float) 3.14, "Hello"}, new byte[] { }}; yield return new object[] {new byte[] {65, 0, 0, 0, 17, 66, 42, 102, 195, 245, 72, 64, 83, 0, 0, 0, 5, 72, 101, 108, 108, 111, 1}, new object[] {(byte) 42, (float) 3.14, "Hello"}, new byte[] {1}}; - yield return new object[] {new byte[] {70, 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101}, new Dictionary() {["key"] = "value"}, new byte[] { }}; - yield return new object[] {new byte[] {70, 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101, 1}, new Dictionary() {["key"] = "value"}, new byte[] {1}}; + yield return new object[] {new byte[] {70, 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101}, new Dictionary {["key"] = "value"}, new byte[] { }}; + yield return new object[] {new byte[] {70, 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101, 1}, new Dictionary {["key"] = "value"}, new byte[] {1}}; yield return new object[] {new byte[] {120, 0, 0, 0, 5, 0, 1, 2, 3, 4}, new byte[] {0, 1, 2, 3, 4}, new byte[] { }}; yield return new object[] {new byte[] {120, 0, 0, 0, 5, 0, 1, 2, 3, 4, 1}, new byte[] {0, 1, 2, 3, 4}, new byte[] {1}}; yield return new object[] {new byte[] {86}, null, new byte[] { }}; @@ -313,4 +313,4 @@ public static IEnumerable ReadArrayTestCases() yield return new object[] { new byte[] { 0, 0, 0, 17, 66, 42, 102, 195, 245, 72, 64, 83, 0, 0, 0, 5, 72, 101, 108, 108, 111 }, new object[] {(byte)42, (float)3.14, "Hello"}, new byte[] { }}; yield return new object[] { new byte[] { 0, 0, 0, 17, 66, 42, 102, 195, 245, 72, 64, 83, 0, 0, 0, 5, 72, 101, 108, 108, 111, 1 }, new object[] {(byte)42, (float)3.14, "Hello"}, new byte[] {1}}; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/BinaryWriteExtensionsTests.cs b/tests/RabbitMQ.Next.Tests/Transport/BinaryWriteExtensionsTests.cs index 2213f073..88187f88 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/BinaryWriteExtensionsTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/BinaryWriteExtensionsTests.cs @@ -241,7 +241,7 @@ public void WriteThrowOnTooLongString(string text) Assert.Throws(() => { Span buffer = stackalloc byte[1000]; - buffer.Write(text, false); + buffer.Write(text); }); } @@ -280,7 +280,7 @@ public static IEnumerable WriteFieldTestCases() yield return new object[] { new DateTimeOffset(1983, 09,28, 0, 0, 0, TimeSpan.Zero), new byte[] { 84, 0, 0, 0, 0, 25, 215, 135, 0 }}; yield return new object[] { "Hello", new byte[] { 83, 0, 0, 0, 5, 72, 101, 108, 108, 111 } }; yield return new object[] { new object[] {(byte)42, (float)3.14, "Hello"}, new byte[] { 65, 0, 0, 0, 17, 66, 42, 102, 195, 245, 72, 64, 83, 0, 0, 0, 5, 72, 101, 108, 108, 111 }}; - yield return new object[] { new Dictionary() { ["key"] = "value" }, new byte[] { 70, 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101 } }; + yield return new object[] { new Dictionary { ["key"] = "value" }, new byte[] { 70, 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101 } }; yield return new object[] { new byte[] { 0, 1, 2, 3, 4}, new byte[] { 120, 0, 0, 0, 5, 0, 1, 2, 3, 4 } }; yield return new object[] { null, new byte[] { 86 }}; } @@ -289,13 +289,13 @@ public static IEnumerable WriteDictionaryTestCases() { yield return new object[] { null, new byte[] { 0, 0, 0, 0 }}; yield return new object[] { new Dictionary(), new byte[] { 0, 0, 0, 0 }}; - yield return new object[] { new Dictionary() { ["key"] = "value" }, new byte[] { 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101 }}; + yield return new object[] { new Dictionary { ["key"] = "value" }, new byte[] { 0, 0, 0, 14, 3, 107, 101, 121, 83, 0, 0, 0, 5, 118, 97, 108, 117, 101 }}; } public static IEnumerable WriteArrayTestCases() { yield return new object[] { null, new byte[] { 0, 0, 0, 0 }}; - yield return new object[] { new object[0], new byte[] { 0, 0, 0, 0 }}; + yield return new object[] { Array.Empty(), new byte[] { 0, 0, 0, 0 }}; yield return new object[] { new object[] {(byte)42, (float)3.14, "Hello"}, new byte[] { 0, 0, 0, 17, 66, 42, 102, 195, 245, 72, 64, 83, 0, 0, 0, 5, 72, 101, 108, 108, 111 }}; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/FramingTests.ContentHeader.cs b/tests/RabbitMQ.Next.Tests/Transport/FramingTests.ContentHeader.cs index c9badbf2..d7abe367 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/FramingTests.ContentHeader.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/FramingTests.ContentHeader.cs @@ -27,85 +27,85 @@ public static IEnumerable MessagePropertiesTestCases() yield return new object[] { new byte[] { 0b_00000000, 0b_00000000 }, - new MessageProperties() + new MessageProperties(), }; yield return new object[] { new byte[] { 0b_10000000, 0b_00000000, 0x04, 0x6A, 0x73, 0x6F, 0x6E }, - new MessageProperties { ContentType = "json" } + new MessageProperties { ContentType = "json" }, }; yield return new object[] { new byte[] { 0b_01000000, 0b_00000000, 0x04, 0x75, 0x74, 0x66, 0x38 }, - new MessageProperties { ContentEncoding = "utf8" } + new MessageProperties { ContentEncoding = "utf8" }, }; yield return new object[] { new byte[] { 0b_00100000, 0b_00000000, 0x00, 0x00, 0x00, 0x0E, 0x03, 0x6B, 0x65, 0x79, 0x53, 0x00, 0x00, 0x00, 0x05, 0x76, 0x61, 0x6C, 0x75, 0x65 }, - new MessageProperties { Headers = new Dictionary { ["key"] = "value" } } + new MessageProperties { Headers = new Dictionary { ["key"] = "value" } }, }; yield return new object[] { new byte[] { 0b_00010000, 0b_00000000, 0x02 }, - new MessageProperties { DeliveryMode = DeliveryMode.Persistent } + new MessageProperties { DeliveryMode = DeliveryMode.Persistent }, }; yield return new object[] { new byte[] { 0b_00001000, 0b_00000000, 0x05 }, - new MessageProperties { Priority = 5 } + new MessageProperties { Priority = 5 }, }; yield return new object[] { new byte[] { 0b_00000100, 0b_00000000, 0x0D, 0x63, 0x6F, 0x72, 0x72, 0x65, 0x6C, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x49, 0x64 }, - new MessageProperties { CorrelationId = "correlationId" } + new MessageProperties { CorrelationId = "correlationId" }, }; yield return new object[] { new byte[] { 0b_00000010, 0b_00000000, 0x07, 0x72, 0x65, 0x70, 0x6C, 0x79, 0x54, 0x6F }, - new MessageProperties { ReplyTo = "replyTo" } + new MessageProperties { ReplyTo = "replyTo" }, }; yield return new object[] { new byte[] { 0b_00000001, 0b_00000000, 0x0A, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E }, - new MessageProperties { Expiration = "expiration" } + new MessageProperties { Expiration = "expiration" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_10000000, 0x09, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x64 }, - new MessageProperties { MessageId = "messageId" } + new MessageProperties { MessageId = "messageId" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_01000000, 0x00, 0x00, 0x00, 0x00, 0x19, 0xD7, 0x87, 0x00 }, - new MessageProperties { Timestamp = new DateTimeOffset(1983, 09, 28, 0, 0, 0, TimeSpan.Zero) } + new MessageProperties { Timestamp = new DateTimeOffset(1983, 09, 28, 0, 0, 0, TimeSpan.Zero) }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_00100000, 0x04, 0x74, 0x79, 0x70, 0x65 }, - new MessageProperties { Type = "type" } + new MessageProperties { Type = "type" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_00010000, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64 }, - new MessageProperties { UserId = "userId" } + new MessageProperties { UserId = "userId" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_00001000, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64 }, - new MessageProperties { ApplicationId = "appId" } + new MessageProperties { ApplicationId = "appId" }, }; yield return new object[] @@ -125,7 +125,7 @@ public static IEnumerable MessagePropertiesTestCases() 0x00, 0x00, 0x00, 0x00, 0x19, 0xD7, 0x87, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, - 0x05, 0x61, 0x70, 0x70, 0x49, 0x64 + 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, }, new MessageProperties { @@ -141,8 +141,8 @@ public static IEnumerable MessagePropertiesTestCases() Timestamp = new DateTimeOffset(1983, 09, 28, 0, 0, 0, TimeSpan.Zero), Type = "type", UserId = "userId", - ApplicationId = "appId" - } + ApplicationId = "appId", + }, }; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/LazyMessagePropertiesTests.cs b/tests/RabbitMQ.Next.Tests/Transport/LazyMessagePropertiesTests.cs index bee38d94..cc60d797 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/LazyMessagePropertiesTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/LazyMessagePropertiesTests.cs @@ -23,85 +23,85 @@ public static IEnumerable MessagePropertiesTestCases() yield return new object[] { new byte[] { 0b_00000000, 0b_00000000 }, - new MessageProperties() + new MessageProperties(), }; yield return new object[] { new byte[] { 0b_10000000, 0b_00000000, 0x04, 0x6A, 0x73, 0x6F, 0x6E }, - new MessageProperties { ContentType = "json" } + new MessageProperties { ContentType = "json" }, }; yield return new object[] { new byte[] { 0b_01000000, 0b_00000000, 0x04, 0x75, 0x74, 0x66, 0x38 }, - new MessageProperties { ContentEncoding = "utf8" } + new MessageProperties { ContentEncoding = "utf8" }, }; yield return new object[] { new byte[] { 0b_00100000, 0b_00000000, 0x00, 0x00, 0x00, 0x0E, 0x03, 0x6B, 0x65, 0x79, 0x53, 0x00, 0x00, 0x00, 0x05, 0x76, 0x61, 0x6C, 0x75, 0x65 }, - new MessageProperties { Headers = new Dictionary { ["key"] = "value"}} + new MessageProperties { Headers = new Dictionary { ["key"] = "value"}}, }; yield return new object[] { new byte[] { 0b_00010000, 0b_00000000, 0x02 }, - new MessageProperties { DeliveryMode = DeliveryMode.Persistent } + new MessageProperties { DeliveryMode = DeliveryMode.Persistent }, }; yield return new object[] { new byte[] { 0b_00001000, 0b_00000000, 0x05 }, - new MessageProperties { Priority = 5 } + new MessageProperties { Priority = 5 }, }; yield return new object[] { new byte[] { 0b_00000100, 0b_00000000, 0x0D, 0x63, 0x6F, 0x72, 0x72, 0x65, 0x6C, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x49, 0x64 }, - new MessageProperties { CorrelationId = "correlationId" } + new MessageProperties { CorrelationId = "correlationId" }, }; yield return new object[] { new byte[] { 0b_00000010, 0b_00000000, 0x07, 0x72, 0x65, 0x70, 0x6C, 0x79, 0x54, 0x6F }, - new MessageProperties { ReplyTo = "replyTo" } + new MessageProperties { ReplyTo = "replyTo" }, }; yield return new object[] { new byte[] { 0b_00000001, 0b_00000000, 0x0A, 0x65, 0x78, 0x70, 0x69, 0x72, 0x61, 0x74, 0x69, 0x6F, 0x6E }, - new MessageProperties { Expiration = "expiration" } + new MessageProperties { Expiration = "expiration" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_10000000, 0x09, 0x6D, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x49, 0x64 }, - new MessageProperties { MessageId = "messageId" } + new MessageProperties { MessageId = "messageId" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_01000000, 0x00, 0x00, 0x00, 0x00, 0x19, 0xD7, 0x87, 0x00 }, - new MessageProperties { Timestamp = new DateTimeOffset(1983, 09,28, 0, 0, 0, TimeSpan.Zero) } + new MessageProperties { Timestamp = new DateTimeOffset(1983, 09,28, 0, 0, 0, TimeSpan.Zero) }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_00100000, 0x04, 0x74, 0x79, 0x70, 0x65 }, - new MessageProperties { Type = "type" } + new MessageProperties { Type = "type" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_00010000, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64 }, - new MessageProperties { UserId = "userId" } + new MessageProperties { UserId = "userId" }, }; yield return new object[] { new byte[] { 0b_00000000, 0b_00001000, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64 }, - new MessageProperties { ApplicationId = "appId" } + new MessageProperties { ApplicationId = "appId" }, }; yield return new object[] @@ -121,7 +121,7 @@ public static IEnumerable MessagePropertiesTestCases() 0x00, 0x00, 0x00, 0x00, 0x19, 0xD7, 0x87, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, - 0x05, 0x61, 0x70, 0x70, 0x49, 0x64 + 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, }, new MessageProperties { @@ -137,8 +137,8 @@ public static IEnumerable MessagePropertiesTestCases() Timestamp = new DateTimeOffset(1983, 09, 28, 0, 0, 0, TimeSpan.Zero), Type = "type", UserId = "userId", - ApplicationId = "appId" - } + ApplicationId = "appId", + }, }; } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/ModelTests.cs b/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/ModelTests.cs index b748fb2f..f3134b43 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/ModelTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/ModelTests.cs @@ -9,16 +9,15 @@ public class ModelTests [Fact] public void QosMethod() { - var prefetchSize = (uint)12345; - var prefetchCount = (ushort)321; - var global = true; + const uint prefetchSize = 12345; + const ushort prefetchCount = 321; - var method = new QosMethod(prefetchSize, prefetchCount, global); + var method = new QosMethod(prefetchSize, prefetchCount, true); Assert.Equal(MethodId.BasicQos, method.MethodId); Assert.Equal(prefetchSize, method.PrefetchSize); Assert.Equal(prefetchCount, method.PrefetchCount); - Assert.Equal(global, method.Global); + Assert.True(method.Global); } [Fact] @@ -32,9 +31,9 @@ public void QosOkMethod() [Fact] public void ConsumeMethod() { - var queue = "my-queue"; - var consumerTag = "tag"; - var flags = (byte)0; + const string queue = "my-queue"; + const string consumerTag = "tag"; + const byte flags = 0; var args = new Dictionary(); var method = new ConsumeMethod(queue, consumerTag, flags, args); @@ -62,7 +61,7 @@ public void ConsumeMethodFlags(byte expected, bool noLocal, bool noAck, bool exc [Fact] public void ConsumeOkMethod() { - var consumerTag = "tag"; + const string consumerTag = "tag"; var method = new ConsumeOkMethod(consumerTag); @@ -73,7 +72,7 @@ public void ConsumeOkMethod() [Fact] public void CancelMethod() { - var consumerTag = "tag"; + const string consumerTag = "tag"; var method = new CancelMethod(consumerTag); @@ -84,7 +83,7 @@ public void CancelMethod() [Fact] public void CancelOkMethod() { - var consumerTag = "tag"; + const string consumerTag = "tag"; var method = new CancelOkMethod(consumerTag); @@ -95,9 +94,9 @@ public void CancelOkMethod() [Fact] public void PublishMethod() { - var exchange = "exchange"; - var routingKey = "routing"; - var flags = (byte)0b_00000001; + const string exchange = "exchange"; + const string routingKey = "routing"; + const byte flags = 0b_00000001; var method = new PublishMethod(exchange, routingKey, flags); @@ -122,10 +121,10 @@ public void PublishMethodFlags(byte expected, bool mandatory, bool immediate) [Fact] public void ReturnMethod() { - var exchange = "exchange"; - var routingKey = "routing"; - var replyCode = (ushort)400; - var replyText = "some error"; + const string exchange = "exchange"; + const string routingKey = "routing"; + const ushort replyCode = 400; + const string replyText = "some error"; var method = new ReturnMethod(exchange, routingKey, replyCode, replyText); @@ -139,51 +138,48 @@ public void ReturnMethod() [Fact] public void DeliverMethod() { - var exchange = "exchange"; - var routingKey = "routing"; - var consumerTag = "tag"; - var deliveryTag = (ulong)42; - var redelivered = true; + const string exchange = "exchange"; + const string routingKey = "routing"; + const string consumerTag = "tag"; + const ulong deliveryTag = 42; - var method = new DeliverMethod(exchange, routingKey, consumerTag, deliveryTag, redelivered); + var method = new DeliverMethod(exchange, routingKey, consumerTag, deliveryTag, true); Assert.Equal(MethodId.BasicDeliver, method.MethodId); Assert.Equal(exchange, method.Exchange); Assert.Equal(routingKey, method.RoutingKey); Assert.Equal(consumerTag, method.ConsumerTag); Assert.Equal(deliveryTag, method.DeliveryTag); - Assert.Equal(redelivered, method.Redelivered); + Assert.True(method.Redelivered); } [Fact] public void GetMethod() { - var queue = "queue"; - var noAck = true; + const string queue = "queue"; - var method = new GetMethod(queue, noAck); + var method = new GetMethod(queue, true); Assert.Equal(MethodId.BasicGet, method.MethodId); Assert.Equal(queue, method.Queue); - Assert.Equal(noAck, method.NoAck); + Assert.True(method.NoAck); } [Fact] public void GetOkMethod() { - var exchange = "exchange"; - var routingKey = "routing"; - var deliveryTag = (ulong)42; - var redelivered = true; - var messageCount = (uint)35; + const string exchange = "exchange"; + const string routingKey = "routing"; + const ulong deliveryTag = 42; + const uint messageCount = 35; - var method = new GetOkMethod(exchange, routingKey, deliveryTag, redelivered, messageCount); + var method = new GetOkMethod(exchange, routingKey, deliveryTag, true, messageCount); Assert.Equal(MethodId.BasicGetOk, method.MethodId); Assert.Equal(exchange, method.Exchange); Assert.Equal(routingKey, method.RoutingKey); Assert.Equal(deliveryTag, method.DeliveryTag); - Assert.Equal(redelivered, method.Redelivered); + Assert.True(method.Redelivered); Assert.Equal(messageCount, method.MessageCount); } @@ -198,25 +194,22 @@ public void GetEmptyMethod() [Fact] public void AckMethod() { - var deliveryTag = (ulong)42; - var multiple = true; + const ulong deliveryTag = 42; - var method = new AckMethod(deliveryTag, multiple); + var method = new AckMethod(deliveryTag, true); Assert.Equal(MethodId.BasicAck, method.MethodId); Assert.Equal(deliveryTag, method.DeliveryTag); - Assert.Equal(multiple, method.Multiple); + Assert.True(method.Multiple); } [Fact] public void RecoverMethod() { - var requeue = true; - - var method = new RecoverMethod(requeue); + var method = new RecoverMethod(true); Assert.Equal(MethodId.BasicRecover, method.MethodId); - Assert.Equal(requeue, method.Requeue); + Assert.True(method.Requeue); } [Fact] @@ -230,15 +223,13 @@ public void RecoverOkMethod() [Fact] public void NackMethod() { - var deliveryTag = (ulong)42; - var multiple = false; - var requeue = true; + const ulong deliveryTag = 42; - var method = new NackMethod(deliveryTag, multiple, requeue); + var method = new NackMethod(deliveryTag, true, false); Assert.Equal(MethodId.BasicNack, method.MethodId); Assert.Equal(deliveryTag, method.DeliveryTag); - Assert.Equal(multiple, method.Multiple); - Assert.Equal(requeue, method.Requeue); + Assert.True(method.Multiple); + Assert.False(method.Requeue); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/SerializationTests.cs b/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/SerializationTests.cs index 2792a259..af983c93 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/SerializationTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/Methods/Basic/SerializationTests.cs @@ -16,9 +16,9 @@ public void QosOkMethodParser() [Fact] public void ConsumeMethodFormatter() - => this.TestFormatter(new ConsumeMethod("my-queue", "ctag", 0, new Dictionary() + => this.TestFormatter(new ConsumeMethod("my-queue", "ctag", 0, new Dictionary { - ["x-priority"] = 2 + ["x-priority"] = 2, })); [Fact] @@ -81,4 +81,4 @@ public void NackMethodFormatter() [Fact] public void NackMethodParser() => this.TestParser(new NackMethod(24, true, true)); -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/ModelTests.cs b/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/ModelTests.cs index 29346b51..b4a4e969 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/ModelTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/ModelTests.cs @@ -9,10 +9,10 @@ public class ModelTests [Fact] public void StartMethod() { - var versionMajor = (byte)0; - var versionMinor = (byte)9; - var mechanisms = "test"; - var locales = "en_US"; + const byte versionMajor = (byte)0; + const byte versionMinor = (byte)9; + const string mechanisms = "test"; + const string locales = "en_US"; var props = new Dictionary { ["key"] = "value", @@ -31,12 +31,12 @@ public void StartMethod() [Fact] public void StartOkMethod() { - var mechanism = "PLAIN"; + const string mechanism = "PLAIN"; var response = "ab"u8.ToArray(); - var locale = "en_US"; - var clientProperties = new Dictionary() + const string locale = "en_US"; + var clientProperties = new Dictionary { - ["exchange_exchange_bindings"] = true + ["exchange_exchange_bindings"] = true, }; var startOkMethod = new StartOkMethod(mechanism, response, locale, clientProperties); @@ -73,9 +73,9 @@ public void SecureOkMethod() [Fact] public void TuneMethod() { - ushort channelMax = 256; - uint maxFrameSize = 4096; - ushort heartbeatInterval = 120; + const ushort channelMax = 256; + const uint maxFrameSize = 4096; + const ushort heartbeatInterval = 120; var tuneMethod = new TuneMethod(channelMax, maxFrameSize, heartbeatInterval); @@ -88,9 +88,9 @@ public void TuneMethod() [Fact] public void TuneOkMethod() { - ushort channelMax = 256; - uint maxFrameSize = 4096; - ushort heartbeatInterval = 120; + const ushort channelMax = 256; + const uint maxFrameSize = 4096; + const ushort heartbeatInterval = 120; var tuneMethod = new TuneOkMethod(channelMax, maxFrameSize, heartbeatInterval); @@ -103,7 +103,7 @@ public void TuneOkMethod() [Fact] public void OpenMethod() { - var vHost = "/"; + const string vHost = "/"; var openMethod = new OpenMethod(vHost); @@ -141,7 +141,7 @@ public void CloseOkMethod() [Fact] public void BlockedMethod() { - var reason = "just because"; + const string reason = "just because"; var method = new BlockedMethod(reason); Assert.Equal(MethodId.ConnectionBlocked, method.MethodId); @@ -155,4 +155,4 @@ public void UnblockedMethod() Assert.Equal(MethodId.ConnectionUnblocked, method.MethodId); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/SerializationTests.cs b/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/SerializationTests.cs index 51f6f2ff..23f26938 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/SerializationTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/Methods/Connection/SerializationTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using RabbitMQ.Next.Tests.Mocks; using RabbitMQ.Next.Transport.Methods.Connection; @@ -32,7 +31,7 @@ public void StartMethodParser() ["information"] = "Licensed under the MPL 1.1. Website: https://rabbitmq.com", ["platform"] = "Erlang/OTP 22.2.1", ["product"] = "RabbitMQ", - ["version"] = "3.8.2" + ["version"] = "3.8.2", }); this.TestParser(method, new StartMethodComparer()); @@ -41,14 +40,14 @@ public void StartMethodParser() [Fact] public void StartOkMethodFormatter() { - var clientProperties = new Dictionary() + var clientProperties = new Dictionary { ["product"] = "RabbitMQ.Next", ["version"] = "0.1.0", - ["capabilities"] = new Dictionary() + ["capabilities"] = new Dictionary { - ["exchange_exchange_bindings"] = true - } + ["exchange_exchange_bindings"] = true, + }, }; var method = new StartOkMethod("PLAIN", "\0test1\0test1"u8.ToArray(), "en_US", clientProperties); @@ -128,4 +127,4 @@ public bool Equals(SecureMethod x, SecureMethod y) public int GetHashCode(SecureMethod obj) => obj.Challenge.GetHashCode(); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/Methods/Exchange/ModelTests.cs b/tests/RabbitMQ.Next.Tests/Transport/Methods/Exchange/ModelTests.cs index 7653d241..45528962 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/Methods/Exchange/ModelTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/Methods/Exchange/ModelTests.cs @@ -29,7 +29,7 @@ public static IEnumerable DeclareTestCases() yield return new object[] { "exchangeName", "type", false, true, false, null}; yield return new object[] { "exchangeName", "type", false, false, true, null}; yield return new object[] { "exchangeName", "type", true, true, true, null}; - yield return new object[] { "exchangeName", "type", true, true, true, new Dictionary() + yield return new object[] { "exchangeName", "type", true, true, true, new Dictionary { ["a"] = "a", }}; @@ -38,7 +38,7 @@ public static IEnumerable DeclareTestCases() [Fact] public void DeclarePassiveMethod() { - var name = "exchangeName"; + const string name = "exchangeName"; var method = new DeclareMethod(name); @@ -63,10 +63,10 @@ public void DeclareOkMethod() [Fact] public void BindMethod() { - var destination = "destination"; - var source = "source"; - var routingKey = "routingKey"; - var arguments = new Dictionary() + const string destination = "destination"; + const string source = "source"; + const string routingKey = "routingKey"; + var arguments = new Dictionary { ["a"] = "a", }; @@ -91,10 +91,10 @@ public void BindOkMethod() [Fact] public void UnbindMethod() { - var destination = "destination"; - var source = "source"; - var routingKey = "routingKey"; - var arguments = new Dictionary() + const string destination = "destination"; + const string source = "source"; + const string routingKey = "routingKey"; + var arguments = new Dictionary { ["a"] = "a", }; @@ -119,14 +119,13 @@ public void UnbindOkMethod() [Fact] public void DeleteMethod() { - var name = "exchangeName"; - var unusedOnly = true; + const string name = "exchangeName"; - var method = new DeleteMethod(name, unusedOnly); + var method = new DeleteMethod(name, true); Assert.Equal(MethodId.ExchangeDelete, method.MethodId); Assert.Equal(name, method.Exchange); - Assert.Equal(unusedOnly, method.UnusedOnly); + Assert.True(method.UnusedOnly); } [Fact] @@ -136,4 +135,4 @@ public void DeleteOkMethod() Assert.Equal(MethodId.ExchangeDeleteOk, method.MethodId); } -} \ No newline at end of file +} diff --git a/tests/RabbitMQ.Next.Tests/Transport/Methods/Queue/ModelTests.cs b/tests/RabbitMQ.Next.Tests/Transport/Methods/Queue/ModelTests.cs index 42263e83..238b4538 100644 --- a/tests/RabbitMQ.Next.Tests/Transport/Methods/Queue/ModelTests.cs +++ b/tests/RabbitMQ.Next.Tests/Transport/Methods/Queue/ModelTests.cs @@ -28,7 +28,7 @@ public static IEnumerable DeclareTestCases() yield return new object[] { "queue", false, true, false, null}; yield return new object[] { "queue", false, false, true, null}; yield return new object[] { "queue", true, true, true, null}; - yield return new object[] { "queue", true, true, true, new Dictionary() + yield return new object[] { "queue", true, true, true, new Dictionary { ["a"] = "a", }}; @@ -37,7 +37,7 @@ public static IEnumerable DeclareTestCases() [Fact] public void DeclarePassiveMethod() { - var name = "queue"; + const string name = "queue"; var method = new DeclareMethod(name); @@ -53,9 +53,9 @@ public void DeclarePassiveMethod() [Fact] public void DeclareOkMethod() { - var name = "queueName"; - uint messageCount = 10; - uint consumerCount = 20; + const string name = "queueName"; + const uint messageCount = 10; + const uint consumerCount = 20; var method = new DeclareOkMethod(name, messageCount, consumerCount); @@ -68,10 +68,10 @@ public void DeclareOkMethod() [Fact] public void BindMethod() { - var queue = "destination"; - var exchange = "source"; - var routingKey = "routingKey"; - var arguments = new Dictionary() + const string queue = "destination"; + const string exchange = "source"; + const string routingKey = "routingKey"; + var arguments = new Dictionary { ["a"] = "a", }; @@ -96,10 +96,10 @@ public void BindOkMethod() [Fact] public void UnbindMethod() { - var queue = "destination"; - var exchange = "source"; - var routingKey = "routingKey"; - var arguments = new Dictionary() + const string queue = "destination"; + const string exchange = "source"; + const string routingKey = "routingKey"; + var arguments = new Dictionary { ["a"] = "a", }; @@ -124,7 +124,7 @@ public void UnbindOkMethod() [Fact] public void PurgeMethod() { - var queue = "destination"; + const string queue = "destination"; var method = new PurgeMethod(queue); @@ -135,7 +135,7 @@ public void PurgeMethod() [Fact] public void PurgeOkMethod() { - uint messageCount = 10; + const uint messageCount = 10; var method = new PurgeOkMethod(messageCount); @@ -146,26 +146,24 @@ public void PurgeOkMethod() [Fact] public void DeleteMethod() { - var queue = "destination"; - var unusedOnly = true; - var emptyOnly = true; + const string queue = "destination"; - var method = new DeleteMethod(queue, unusedOnly, emptyOnly); + var method = new DeleteMethod(queue, true, false); Assert.Equal(MethodId.QueueDelete, method.MethodId); Assert.Equal(queue, method.Queue); - Assert.Equal(unusedOnly, method.UnusedOnly); - Assert.Equal(emptyOnly, method.EmptyOnly); + Assert.True(method.UnusedOnly); + Assert.False(method.EmptyOnly); } [Fact] public void DeleteOkMethod() { - uint messageCount = 10; + const uint messageCount = 10; var method = new DeleteOkMethod(messageCount); Assert.Equal(MethodId.QueueDeleteOk, method.MethodId); Assert.Equal(messageCount, method.MessageCount); } -} \ No newline at end of file +}