diff --git a/.editorconfig b/.editorconfig index 8b78fab4360..e86e1aff714 100644 --- a/.editorconfig +++ b/.editorconfig @@ -187,6 +187,8 @@ dotnet_diagnostic.CA1805.severity = warning dotnet_diagnostic.RCS1129.severity = none # Use StringBuilder.Append(char) for single character strings. dotnet_diagnostic.CA1834.severity = warning +# Prefer IsEmpty over Count when available. +dotnet_diagnostic.CA1836.severity = warning # Use 'string.Method(char)' instead of 'string.Method(string)' for string with single char. dotnet_diagnostic.CA1866.severity = warning # Simplify name. diff --git a/src/HotChocolate/Core/src/Types/Utilities/Subscriptions/ObservableSourceStreamAdapter.cs b/src/HotChocolate/Core/src/Types/Utilities/Subscriptions/ObservableSourceStreamAdapter.cs index f47f4585656..1223916daef 100644 --- a/src/HotChocolate/Core/src/Types/Utilities/Subscriptions/ObservableSourceStreamAdapter.cs +++ b/src/HotChocolate/Core/src/Types/Utilities/Subscriptions/ObservableSourceStreamAdapter.cs @@ -42,7 +42,7 @@ public async IAsyncEnumerator GetAsyncEnumerator( { _wait = new TaskCompletionSource(); } - else if (_queue.Count == 0) + else if (_queue.IsEmpty) { await _wait.Task.ConfigureAwait(false); } diff --git a/src/Mocha/test/Mocha.Tests/Inbox/InboxIntegrationTests.cs b/src/Mocha/test/Mocha.Tests/Inbox/InboxIntegrationTests.cs index b67cfad4925..5d815534c5d 100644 --- a/src/Mocha/test/Mocha.Tests/Inbox/InboxIntegrationTests.cs +++ b/src/Mocha/test/Mocha.Tests/Inbox/InboxIntegrationTests.cs @@ -31,7 +31,7 @@ public async Task Inbox_Should_RecordMessage_When_EventReceived() // assert - handler received the message and inbox recorded it Assert.True(await recorder.WaitAsync(s_timeout), "Handler did not receive the event within timeout"); - await WaitUntilAsync(() => inbox.RecordedEnvelopes.Count >= 1, s_timeout); + await WaitUntilAsync(() => !inbox.RecordedEnvelopes.IsEmpty, s_timeout); Assert.Single(inbox.RecordedEnvelopes); } diff --git a/src/Mocha/test/Mocha.Tests/Outbox/OutboxIntegrationTests.cs b/src/Mocha/test/Mocha.Tests/Outbox/OutboxIntegrationTests.cs index 9a242578fcd..2a430751870 100644 --- a/src/Mocha/test/Mocha.Tests/Outbox/OutboxIntegrationTests.cs +++ b/src/Mocha/test/Mocha.Tests/Outbox/OutboxIntegrationTests.cs @@ -28,7 +28,7 @@ public async Task Outbox_Should_CaptureMessage_When_EventPublished() await bus.PublishAsync(new OutboxTestEvent { Payload = "capture-me" }, CancellationToken.None); // assert - message captured by outbox, not delivered to transport - await WaitUntilAsync(() => outbox.Envelopes.Count >= 1, s_timeout); + await WaitUntilAsync(() => !outbox.Envelopes.IsEmpty, s_timeout); Assert.Single(outbox.Envelopes); } @@ -91,7 +91,7 @@ await bus.PublishAsync( // assert - only one message captured (the one without skip), the skipped one // was delivered to handler Assert.True(await recorder.WaitAsync(s_timeout), "Skipped message should have been delivered to handler"); - await WaitUntilAsync(() => outbox.Envelopes.Count >= 1, s_timeout); + await WaitUntilAsync(() => !outbox.Envelopes.IsEmpty, s_timeout); Assert.Single(outbox.Envelopes); Assert.Single(recorder.Messages); diff --git a/src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/InboxTests.cs b/src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/InboxTests.cs index d83d80dca17..6e282483ab9 100644 --- a/src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/InboxTests.cs +++ b/src/Mocha/test/Mocha.Transport.InMemory.Tests/Behaviors/InboxTests.cs @@ -45,7 +45,7 @@ public async Task Inbox_Should_DeduplicateMessage_When_SameMessageIdPublishedTwi // act - publish the first message; handler should process it await bus.PublishAsync(new InboxEvent { Payload = "first" }, CancellationToken.None); Assert.True(await recorder.WaitAsync(s_timeout), "Handler did not receive the first event"); - await WaitUntilAsync(() => inbox.RecordedEnvelopes.Count >= 1, s_timeout); + await WaitUntilAsync(() => !inbox.RecordedEnvelopes.IsEmpty, s_timeout); // act - publish a second message with the same MessageId; handler should NOT process it await bus.PublishAsync(new InboxEvent { Payload = "second" }, CancellationToken.None); diff --git a/src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/InboxTests.cs b/src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/InboxTests.cs index ee0b8dbe324..a2f0ab6f546 100644 --- a/src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/InboxTests.cs +++ b/src/Mocha/test/Mocha.Transport.RabbitMQ.Tests/Behaviors/InboxTests.cs @@ -60,7 +60,7 @@ public async Task Inbox_Should_DeduplicateMessage_When_SameMessageIdPublishedTwi // Wait for the first message to be fully processed and recorded in the inbox Assert.True(await recorder.WaitAsync(s_timeout), "Handler did not receive the first event within timeout"); - await WaitUntilAsync(() => inbox.RecordedEnvelopes.Count >= 1, s_timeout); + await WaitUntilAsync(() => !inbox.RecordedEnvelopes.IsEmpty, s_timeout); await messageBus.PublishAsync(new InboxEvent { Payload = "second" }, CancellationToken.None); diff --git a/src/StrawberryShake/Client/src/Transport.WebSockets/Session.cs b/src/StrawberryShake/Client/src/Transport.WebSockets/Session.cs index 532e0367c23..f806e7c0823 100644 --- a/src/StrawberryShake/Client/src/Transport.WebSockets/Session.cs +++ b/src/StrawberryShake/Client/src/Transport.WebSockets/Session.cs @@ -159,7 +159,7 @@ public async ValueTask DisposeAsync() if (!_disposed) { _disposed = true; - if (_operations.Count > 0) + if (!_operations.IsEmpty) { var operations = _operations.Values.ToArray();