Skip to content

feat(SocketLogging): add SocketLogging unit test#564

Merged
ArgoZhang merged 10 commits intomasterfrom
refactor-socket
Aug 31, 2025
Merged

feat(SocketLogging): add SocketLogging unit test#564
ArgoZhang merged 10 commits intomasterfrom
refactor-socket

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Aug 31, 2025

Link issues

fixes #563

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Expand SocketLogging API and add comprehensive unit tests for logging and byte conversion, improve DataConverter error logging, and refine DataByteConverter behavior

New Features:

  • Add LogWarning, LogInformation, and LogDebug methods to SocketLogging
  • Support byte property conversion in DataConverter via DataPropertyConverter attribute

Enhancements:

  • Simplify SocketLogging.LogError with null-propagation expression
  • Log informational messages on conversion failures in DataConverter
  • Return byte.MinValue for empty input in DataByteConverter

Tests:

  • Add unit tests for SocketLogging methods in SocketLoggingTest and TcpSocketFactoryTest
  • Add tests for DataByteConverter and byte conversion in TcpSocketPropertyConverterTest

Copilot AI review requested due to automatic review settings August 31, 2025 04:09
@bb-auto bb-auto Bot added the enhancement New feature or request label Aug 31, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Aug 31, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 31, 2025

Reviewer's Guide

This PR refactors SocketLogging into concise expression-bodied methods, adds new logging levels, broadens unit test coverage for logging and byte conversion, and enhances data converter error handling.

Class diagram for updated SocketLogging methods

classDiagram
    class SocketLogging {
        <<static>>
        +Init(logger)
        +LogError(ex, message)
        +LogWarning(message)
        +LogInformation(message)
        +LogDebug(message)
    }
    class ILogger
    SocketLogging --|> ILogger : uses
Loading

Class diagram for DataConverter Parse method error handling

classDiagram
    class DataConverter {
        +Parse(data, entity)
    }
    class SocketLogging {
        +LogInformation(message)
    }
    DataConverter --> SocketLogging : logs conversion errors
Loading

Class diagram for DataByteConverter Convert method update

classDiagram
    class DataByteConverter {
        +Convert(data)
    }
    DataByteConverter : Convert returns byte.MinValue if data is empty
Loading

File-Level Changes

Change Details Files
Refactor and extend SocketLogging methods
  • Convert LogError to expression-bodied form
  • Add LogWarning, LogInformation, and LogDebug methods
src/extensions/BootstrapBlazor.Socket/Logging/SocketLogging.cs
Add unit tests for SocketLogging methods
  • Import SocketLogging namespace in tests
  • Invoke LogWarning, LogDebug, and LogInformation in TcpSocketFactoryTest
  • Add method calls in SocketLoggingTest
test/UnitTestTcpSocket/TcpSocketFactoryTest.cs
test/UnitTestTcpSocket/SocketLoggingTest.cs
Introduce ByteConverter unit test
  • Add ByteConverter_Ok test for valid and empty inputs
test/UnitTestTcpSocket/TcpSocketPropertyConverterTest.cs
Log conversion failures in DataConverter
  • Remove unnecessary null type check
  • Add else branch logging informational message on conversion mismatch
src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs
Use byte.MinValue as DataByteConverter default
  • Change default return for empty data from literal zero to byte.MinValue
src/extensions/BootstrapBlazor.Socket/PropertyConverter/DataByteConverter.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#563 Add a unit test for SocketLogging.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive unit tests for the SocketLogging component and enhances logging functionality with additional log level methods. The changes improve test coverage and provide a more complete logging API.

  • Adds new unit tests for SocketLogging component with warning, information, and debug methods
  • Expands SocketLogging class with LogWarning, LogInformation, and LogDebug methods
  • Adds ByteConverter unit test and improves data conversion error handling

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/UnitTestTcpSocket/SocketLoggingTest.cs Adds unit tests for new logging methods
test/UnitTestTcpSocket/TcpSocketFactoryTest.cs Integrates SocketLogging calls and adds byte converter test
test/UnitTestTcpSocket/TcpSocketPropertyConverterTest.cs Adds ByteConverter unit test
src/extensions/BootstrapBlazor.Socket/Logging/SocketLogging.cs Implements new logging methods and refactors existing code
src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs Adds error logging for type conversion failures
src/extensions/BootstrapBlazor.Socket/PropertyConverter/DataByteConverter.cs Uses byte.MinValue instead of hardcoded 0x0
src/extensions/BootstrapBlazor.Socket/BootstrapBlazor.Socket.csproj Updates version to 9.0.11

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs Outdated
@ArgoZhang ArgoZhang added test and removed enhancement New feature or request labels Aug 31, 2025
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The SocketLogging methods use the literal template "{message}", which will log the braces literally; consider using the passed-in message directly or a structured template like "{Message}" to avoid confusing output.
  • In DataConverter.Parse, you removed the null check on the converted value but still call IsAssignableFrom on a potentially null type—add an explicit null check on value before invoking valueType or IsAssignableFrom to prevent errors.
  • The new SocketLogging unit tests only invoke the methods without asserting behavior; consider using a mock ILogger to verify that each Log* call is actually forwarded with the expected parameters.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The SocketLogging methods use the literal template "{message}", which will log the braces literally; consider using the passed-in message directly or a structured template like "{Message}" to avoid confusing output.
- In DataConverter.Parse, you removed the null check on the converted value but still call IsAssignableFrom on a potentially null type—add an explicit null check on `value` before invoking `valueType` or `IsAssignableFrom` to prevent errors.
- The new SocketLogging unit tests only invoke the methods without asserting behavior; consider using a mock ILogger to verify that each Log* call is actually forwarded with the expected parameters.

## Individual Comments

### Comment 1
<location> `src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs:75` </location>
<code_context>
                 {
                     var value = attr.ConvertTo(data);
                     var valueType = value?.GetType();
-                    if (valueType != null && p.PropertyType.IsAssignableFrom(valueType))
+                    if (p.PropertyType.IsAssignableFrom(valueType))
                     {
                         p.SetValue(entity, value);
</code_context>

<issue_to_address>
Potential null reference if valueType is null.

Restoring the null check for valueType will prevent IsAssignableFrom from throwing a runtime exception if attr.ConvertTo(data) returns null.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang merged commit d7b4231 into master Aug 31, 2025
1 check passed
@ArgoZhang ArgoZhang deleted the refactor-socket branch August 31, 2025 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(SocketLogging): add SocketLogging unit test

2 participants