-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(ITcpSocketClient): add SendAsync extensions method #6269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideAdds a new string-based SendAsync extension on ITcpSocketClient that wraps the existing byte-array overload with encoding and cancellation support, updates unit tests to leverage the new overload, and refines sample documentation to clarify sticky-packet and fragmentation handling. Class diagram for ITcpSocketClientExtensions and SendAsync methodclassDiagram
class ITcpSocketClient {
<<interface>>
SendAsync(byte[] buffer, CancellationToken token) ValueTask<bool>
}
class ITcpSocketClientExtensions {
<<static>>
+SendAsync(client: ITcpSocketClient, content: string, encoding: Encoding = null, token: CancellationToken = default) ValueTask<bool>
}
ITcpSocketClientExtensions ..> ITcpSocketClient : extends
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- Add argument validation in the SendAsync extension (e.g. throw ArgumentNullException for null client or content) to match your XML docs contract.
- Add unit tests for the new string-overload SendAsync covering different encodings, empty-string edge cases, and null‐encoding fallback to verify correct byte conversion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add argument validation in the SendAsync extension (e.g. throw ArgumentNullException for null client or content) to match your XML docs contract.
- Add unit tests for the new string-overload SendAsync covering different encodings, empty-string edge cases, and null‐encoding fallback to verify correct byte conversion.
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Extensions/ITcpSocketClientExtensions.cs:30` </location>
<code_context>
+ /// langword="true"/> if the content was sent successfully; otherwise, <see langword="false"/>.</returns>
+ public static ValueTask<bool> SendAsync(this ITcpSocketClient client, string content, Encoding? encoding = null, CancellationToken token = default)
+ {
+ var buffer = encoding?.GetBytes(content) ?? Encoding.UTF8.GetBytes(content);
+ return client.SendAsync(buffer, token);
+ }
</code_context>
<issue_to_address>
No null or empty check for 'content' parameter.
Since the XML docs specify 'content' must not be null or empty, add a guard clause to throw an exception if this condition is violated to prevent unintended behavior.
</issue_to_address>
### Comment 2
<location> `test/UnitTest/Services/TcpSocketFactoryTest.cs:98` </location>
<code_context>
- var data = new ReadOnlyMemory<byte>([1, 2, 3, 4, 5]);
- var result = await client.SendAsync(data, cst.Token);
+ var result = await client.SendAsync("test", null, cst.Token);
Assert.False(result);
</code_context>
<issue_to_address>
Consider adding tests for edge cases in the new SendAsync extension method.
Please add tests for cases like empty string content, different encodings, very large strings, client not connected or disposed, and exception handling to ensure robustness.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6269 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 711 712 +1
Lines 31379 31383 +4
Branches 4432 4433 +1
=========================================
+ Hits 31379 31383 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6267
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Introduce a string-based SendAsync extension for ITcpSocketClient and update tests and sample docs to demonstrate and explain its usage.
New Features:
Enhancements:
Documentation:
Tests: