diff --git a/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs b/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs index 0c66513ef4b..f3faafd9e23 100644 --- a/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs +++ b/src/HotChocolate/AspNetCore/src/Transport.Http/DefaultGraphQLHttpClient.cs @@ -160,11 +160,11 @@ private static HttpRequestMessage CreateRequestMessage( else { #endif - message.Headers.Accept.Clear(); - foreach (var contentType in request.Accept) - { - message.Headers.Accept.Add(contentType); - } + message.Headers.Accept.Clear(); + foreach (var contentType in request.Accept) + { + message.Headers.Accept.Add(contentType); + } #if FUSION } #endif diff --git a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Clients/SourceSchemaHttpClient.cs b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Clients/SourceSchemaHttpClient.cs index 61496ca9665..428f70ad5ba 100644 --- a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Clients/SourceSchemaHttpClient.cs +++ b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Clients/SourceSchemaHttpClient.cs @@ -1,4 +1,3 @@ -using System.Buffers; using System.Collections.Immutable; using System.Diagnostics; using System.Runtime.CompilerServices; diff --git a/src/HotChocolate/Fusion/src/Fusion.Execution/Planning/OperationPlanner.BuildExecutionTree.cs b/src/HotChocolate/Fusion/src/Fusion.Execution/Planning/OperationPlanner.BuildExecutionTree.cs index 0c1e7685182..6f31ef48347 100644 --- a/src/HotChocolate/Fusion/src/Fusion.Execution/Planning/OperationPlanner.BuildExecutionTree.cs +++ b/src/HotChocolate/Fusion/src/Fusion.Execution/Planning/OperationPlanner.BuildExecutionTree.cs @@ -296,7 +296,7 @@ private static OperationExecutionNode CreateOperationExecutionNode( List? variableBuffer) { var requirements = operationStep.Requirements.IsEmpty - ? Array.Empty() + ? [] : operationStep.Requirements.OrderBy(t => t.Key).Select(t => t.Value).ToArray(); var forwardedVariables = Array.Empty(); diff --git a/src/Mocha/src/Demo/Demo.Billing/Commands/ProcessPaymentCommand.cs b/src/Mocha/src/Demo/Demo.Billing/Commands/ProcessPaymentCommand.cs index 183d25d9d83..4006bf7f3c4 100644 --- a/src/Mocha/src/Demo/Demo.Billing/Commands/ProcessPaymentCommand.cs +++ b/src/Mocha/src/Demo/Demo.Billing/Commands/ProcessPaymentCommand.cs @@ -20,10 +20,14 @@ public async ValueTask HandleAsync( var invoice = await db.Invoices.FirstOrDefaultAsync( i => i.Id == command.InvoiceId, cancellationToken); if (invoice is null) + { return new ProcessPaymentResult(false, Error: "Invoice not found"); + } if (invoice.Status == InvoiceStatus.Paid) + { return new ProcessPaymentResult(false, Error: "Invoice already paid"); + } var payment = new Payment { diff --git a/src/Mocha/src/Demo/Demo.Billing/Program.cs b/src/Mocha/src/Demo/Demo.Billing/Program.cs index 9b294ac7a18..a1f01fd40f2 100644 --- a/src/Mocha/src/Demo/Demo.Billing/Program.cs +++ b/src/Mocha/src/Demo/Demo.Billing/Program.cs @@ -2,7 +2,6 @@ using Demo.Billing.Data; using Demo.Billing.Handlers; using Demo.Billing.Queries; -using Demo.Contracts.Events; using Microsoft.EntityFrameworkCore; using Mocha; using Mocha.EntityFrameworkCore; diff --git a/src/Mocha/src/Demo/Demo.Catalog/Commands/InitiateReturnCommand.cs b/src/Mocha/src/Demo/Demo.Catalog/Commands/InitiateReturnCommand.cs index 86c5525630b..40ad3e1e336 100644 --- a/src/Mocha/src/Demo/Demo.Catalog/Commands/InitiateReturnCommand.cs +++ b/src/Mocha/src/Demo/Demo.Catalog/Commands/InitiateReturnCommand.cs @@ -2,7 +2,6 @@ using Demo.Catalog.Entities; using Demo.Contracts.Commands; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; using Mocha; using Mocha.Mediator; @@ -32,10 +31,14 @@ public async ValueTask HandleAsync( var order = await db.Orders.Include(o => o.Product) .FirstOrDefaultAsync(o => o.Id == command.OrderId, cancellationToken); if (order is null) + { return new InitiateReturnResult(false, Error: "Order not found"); + } if (order.Status != OrderStatus.Delivered && order.Status != OrderStatus.Shipping) + { return new InitiateReturnResult(false, Error: $"Order cannot be returned in status: {order.Status}"); + } logger.LogInformation("Creating return label for order {OrderId}", command.OrderId); @@ -56,7 +59,9 @@ public async ValueTask HandleAsync( cancellationToken); if (!labelResponse.Success) + { return new InitiateReturnResult(false, Error: $"Failed to create return label: {labelResponse.FailureReason}"); + } order.Status = OrderStatus.ReturnInitiated; order.UpdatedAt = DateTimeOffset.UtcNow; diff --git a/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceBulkOrderCommand.cs b/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceBulkOrderCommand.cs index 52165b95a60..77f132803f3 100644 --- a/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceBulkOrderCommand.cs +++ b/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceBulkOrderCommand.cs @@ -1,5 +1,4 @@ using Demo.Contracts.Events; -using Microsoft.Extensions.Logging; using Mocha; using Mocha.Mediator; diff --git a/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceOrderCommand.cs b/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceOrderCommand.cs index d4979119dca..f68823f5101 100644 --- a/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceOrderCommand.cs +++ b/src/Mocha/src/Demo/Demo.Catalog/Commands/PlaceOrderCommand.cs @@ -29,10 +29,14 @@ public async ValueTask HandleAsync( var product = await db.Products.FindAsync(command.ProductId); if (product is null) + { return new PlaceOrderResult(false, Error: "Product not found"); + } if (product.StockQuantity < command.Quantity) + { return new PlaceOrderResult(false, Error: "Insufficient stock"); + } var order = new OrderRecord { diff --git a/src/Mocha/src/Demo/Demo.Catalog/Commands/RequestQuickRefundCommand.cs b/src/Mocha/src/Demo/Demo.Catalog/Commands/RequestQuickRefundCommand.cs index 5201f30d588..ecc991215e6 100644 --- a/src/Mocha/src/Demo/Demo.Catalog/Commands/RequestQuickRefundCommand.cs +++ b/src/Mocha/src/Demo/Demo.Catalog/Commands/RequestQuickRefundCommand.cs @@ -1,7 +1,6 @@ using Demo.Catalog.Data; using Demo.Catalog.Entities; using Demo.Contracts.Saga; -using Microsoft.Extensions.Logging; using Mocha; using Mocha.Mediator; @@ -28,7 +27,9 @@ public async ValueTask HandleAsync( { var order = await db.Orders.FindAsync([command.OrderId], cancellationToken); if (order is null) + { return new RequestQuickRefundResult(false, Error: "Order not found"); + } logger.LogInformation("Initiating quick refund saga for order {OrderId}", command.OrderId); diff --git a/src/Mocha/src/Demo/Demo.Catalog/Program.cs b/src/Mocha/src/Demo/Demo.Catalog/Program.cs index 31ec7a96fd4..97b7dce75ea 100644 --- a/src/Mocha/src/Demo/Demo.Catalog/Program.cs +++ b/src/Mocha/src/Demo/Demo.Catalog/Program.cs @@ -3,9 +3,6 @@ using Demo.Catalog.Handlers; using Demo.Catalog.Queries; using Demo.Catalog.Sagas; -using Demo.Contracts.Commands; -using Demo.Contracts.Events; -using Demo.Contracts.Saga; using Microsoft.EntityFrameworkCore; using Mocha; using Mocha.EntityFrameworkCore; @@ -118,7 +115,9 @@ await sender.QueryAsync(new GetOrderByIdQuery(id)) is { } order new RequestQuickRefundCommand(request.OrderId, request.Amount, request.Reason)); if (!result.Success) + { return result.Error == "Order not found" ? Results.NotFound(result.Error) : Results.Problem(result.Error); + } return Results.Ok(result.Response); }); @@ -132,9 +131,15 @@ await sender.QueryAsync(new GetOrderByIdQuery(id)) is { } order if (!result.Success) { if (result.Error!.Contains("not found")) + { return Results.NotFound(result.Error); + } + if (result.Error.Contains("cannot be returned")) + { return Results.BadRequest(result.Error); + } + return Results.Problem(result.Error); } diff --git a/src/Mocha/src/Demo/Demo.Shipping/Commands/ReceiveReturnPackageCommand.cs b/src/Mocha/src/Demo/Demo.Shipping/Commands/ReceiveReturnPackageCommand.cs index 4f7a61d4539..348bd9a1cd7 100644 --- a/src/Mocha/src/Demo/Demo.Shipping/Commands/ReceiveReturnPackageCommand.cs +++ b/src/Mocha/src/Demo/Demo.Shipping/Commands/ReceiveReturnPackageCommand.cs @@ -2,7 +2,6 @@ using Demo.Shipping.Data; using Demo.Shipping.Entities; using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; using Mocha; using Mocha.Mediator; @@ -27,10 +26,14 @@ public async ValueTask HandleAsync( var returnShipment = await db.ReturnShipments.FirstOrDefaultAsync( r => r.Id == command.ReturnId, cancellationToken); if (returnShipment is null) + { return new ReceiveReturnPackageResult(false, Error: "Return shipment not found"); + } if (returnShipment.Status == ReturnShipmentStatus.Received) + { return new ReceiveReturnPackageResult(false, Error: "Return package already received"); + } returnShipment.Status = ReturnShipmentStatus.Received; returnShipment.ReceivedAt = DateTimeOffset.UtcNow; diff --git a/src/Mocha/src/Demo/Demo.Shipping/Commands/ShipShipmentCommand.cs b/src/Mocha/src/Demo/Demo.Shipping/Commands/ShipShipmentCommand.cs index b3125200fe7..f2095c2869c 100644 --- a/src/Mocha/src/Demo/Demo.Shipping/Commands/ShipShipmentCommand.cs +++ b/src/Mocha/src/Demo/Demo.Shipping/Commands/ShipShipmentCommand.cs @@ -21,10 +21,14 @@ public async ValueTask HandleAsync( var shipment = await db.Shipments.FirstOrDefaultAsync( s => s.Id == command.ShipmentId, cancellationToken); if (shipment is null) + { return new ShipShipmentResult(false, Error: "Shipment not found"); + } if (shipment.Status == ShipmentStatus.Shipped) + { return new ShipShipmentResult(false, Error: "Shipment already shipped"); + } shipment.Status = ShipmentStatus.Shipped; shipment.Carrier = command.Carrier; diff --git a/src/Mocha/src/Demo/Demo.Shipping/Program.cs b/src/Mocha/src/Demo/Demo.Shipping/Program.cs index aae410091c1..9cca0ac16dc 100644 --- a/src/Mocha/src/Demo/Demo.Shipping/Program.cs +++ b/src/Mocha/src/Demo/Demo.Shipping/Program.cs @@ -1,9 +1,7 @@ -using Demo.Contracts.Events; using Demo.Shipping.Commands; using Demo.Shipping.Data; using Demo.Shipping.Handlers; using Demo.Shipping.Queries; -using Microsoft.EntityFrameworkCore; using Mocha; using Mocha.EntityFrameworkCore; using Mocha.Mediator; diff --git a/src/Mocha/src/Mocha.Transport.Postgres/Configurations/PostgresTransportConfiguration.cs b/src/Mocha/src/Mocha.Transport.Postgres/Configurations/PostgresTransportConfiguration.cs index b7665d8f773..87717c0ddfa 100644 --- a/src/Mocha/src/Mocha.Transport.Postgres/Configurations/PostgresTransportConfiguration.cs +++ b/src/Mocha/src/Mocha.Transport.Postgres/Configurations/PostgresTransportConfiguration.cs @@ -18,7 +18,7 @@ public class PostgresTransportConfiguration : MessagingTransportConfiguration public PostgresTransportConfiguration() { Name = DefaultName; - base.Schema = DefaultSchema; + Schema = DefaultSchema; } /// diff --git a/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessageHeaders.cs b/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessageHeaders.cs index 39601ff18f0..a577f6d6190 100644 --- a/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessageHeaders.cs +++ b/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessageHeaders.cs @@ -1,5 +1,3 @@ -using System.Text; - namespace Mocha.Transport.Postgres; /// diff --git a/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessagingTransport.cs b/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessagingTransport.cs index 48a76ca8db3..a7d50c3346e 100644 --- a/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessagingTransport.cs +++ b/src/Mocha/src/Mocha.Transport.Postgres/PostgresMessagingTransport.cs @@ -86,7 +86,10 @@ protected override void OnAfterInitialized(IMessagingSetupContext context) var builder = new UriBuilder { - Scheme = Schema, Host = configuration.Host, Port = configuration.Port, Path = "/" + Scheme = Schema, + Host = configuration.Host, + Port = configuration.Port, + Path = "/" }; _topology = new PostgresMessagingTopology( this, @@ -225,7 +228,8 @@ public override TransportDescription Describe() "outbound", new Dictionary { - ["autoDelete"] = queue.AutoDelete, ["autoProvision"] = queue.AutoProvision + ["autoDelete"] = queue.AutoDelete, + ["autoProvision"] = queue.AutoProvision })); } @@ -352,7 +356,8 @@ protected override DispatchEndpoint CreateDispatchEndpoint() var queueName = context.Naming.GetSendEndpointName(route.MessageType.RuntimeType); configuration = new PostgresDispatchEndpointConfiguration { - QueueName = queueName, Name = "q/" + queueName + QueueName = queueName, + Name = "q/" + queueName }; } else if (route.Kind == OutboundRouteKind.Publish) @@ -360,7 +365,8 @@ protected override DispatchEndpoint CreateDispatchEndpoint() var topicName = context.Naming.GetPublishEndpointName(route.MessageType.RuntimeType); configuration = new PostgresDispatchEndpointConfiguration { - TopicName = topicName, Name = "t/" + topicName + TopicName = topicName, + Name = "t/" + topicName }; } @@ -385,7 +391,9 @@ protected override DispatchEndpoint CreateDispatchEndpoint() var instanceEndpointName = context.Naming.GetInstanceEndpoint(context.Host.InstanceId); configuration = new PostgresDispatchEndpointConfiguration { - Kind = DispatchEndpointKind.Reply, QueueName = instanceEndpointName, Name = "Replies" + Kind = DispatchEndpointKind.Reply, + QueueName = instanceEndpointName, + Name = "Replies" }; } @@ -398,7 +406,8 @@ protected override DispatchEndpoint CreateDispatchEndpoint() { configuration = new PostgresDispatchEndpointConfiguration { - TopicName = new string(topicName), Name = "t/" + new string(topicName) + TopicName = new string(topicName), + Name = "t/" + new string(topicName) }; } @@ -406,7 +415,8 @@ protected override DispatchEndpoint CreateDispatchEndpoint() { configuration = new PostgresDispatchEndpointConfiguration { - QueueName = new string(queueName), Name = "q/" + new string(queueName) + QueueName = new string(queueName), + Name = "q/" + new string(queueName) }; } } @@ -421,7 +431,8 @@ protected override DispatchEndpoint CreateDispatchEndpoint() { configuration = new PostgresDispatchEndpointConfiguration { - TopicName = new string(topicName), Name = "t/" + new string(topicName) + TopicName = new string(topicName), + Name = "t/" + new string(topicName) }; } @@ -429,7 +440,8 @@ protected override DispatchEndpoint CreateDispatchEndpoint() { configuration = new PostgresDispatchEndpointConfiguration { - QueueName = new string(queueName), Name = "q/" + new string(queueName) + QueueName = new string(queueName), + Name = "q/" + new string(queueName) }; } } diff --git a/src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/ConsumerLifecycleTests.cs b/src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/ConsumerLifecycleTests.cs index b2a971866e3..cb045f1f456 100644 --- a/src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/ConsumerLifecycleTests.cs +++ b/src/Mocha/test/Mocha.Transport.Postgres.Tests/Behaviors/ConsumerLifecycleTests.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Mocha.Transport.Postgres.Tests.Helpers; using Npgsql; diff --git a/src/Mocha/test/Mocha.Transport.Postgres.Tests/Connection/PostgresConnectionManagerTests.cs b/src/Mocha/test/Mocha.Transport.Postgres.Tests/Connection/PostgresConnectionManagerTests.cs index f0178ce2ff5..7686a73c147 100644 --- a/src/Mocha/test/Mocha.Transport.Postgres.Tests/Connection/PostgresConnectionManagerTests.cs +++ b/src/Mocha/test/Mocha.Transport.Postgres.Tests/Connection/PostgresConnectionManagerTests.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Mocha.Transport.Postgres.Tests.Helpers; -using Npgsql; namespace Mocha.Transport.Postgres.Tests.Connection; diff --git a/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchEndpointTests.cs b/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchEndpointTests.cs index 0168b499d1e..9a9e0f70320 100644 --- a/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchEndpointTests.cs +++ b/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchEndpointTests.cs @@ -1,4 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; using Mocha.Transport.Postgres.Tests.Helpers; namespace Mocha.Transport.Postgres.Tests; diff --git a/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchHeaderTests.cs b/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchHeaderTests.cs index 8a6fa368bd5..136fd97a06f 100644 --- a/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchHeaderTests.cs +++ b/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresDispatchHeaderTests.cs @@ -1,4 +1,3 @@ -using System.Buffers; using System.Collections.Immutable; using System.Text.Json; using Mocha.Middlewares; diff --git a/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresMessageEnvelopeParserTests.cs b/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresMessageEnvelopeParserTests.cs index 54375163dd3..ba8a6d57296 100644 --- a/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresMessageEnvelopeParserTests.cs +++ b/src/Mocha/test/Mocha.Transport.Postgres.Tests/PostgresMessageEnvelopeParserTests.cs @@ -338,13 +338,13 @@ private static PostgresMessageItem CreateMessageItem( DateTime? sentTime = null, int deliveryCount = 0) { - ReadOnlyMemory headersBytes = headers is not null + var headersBytes = headers is not null ? Encoding.UTF8.GetBytes(JsonSerializer.Serialize(headers)) : ReadOnlyMemory.Empty; return new PostgresMessageItem( TransportMessageId: Guid.NewGuid(), - Body: body ?? Array.Empty(), + Body: body ?? [], Headers: headersBytes, QueueId: 1, SentTime: sentTime ?? DateTime.UtcNow,