Skip to content

Enhance masking logic#1327

Open
maheshbakali wants to merge 1 commit intoSciSharp:masterfrom
maheshbakali:refactor/settingservice-improvement
Open

Enhance masking logic#1327
maheshbakali wants to merge 1 commit intoSciSharp:masterfrom
maheshbakali:refactor/settingservice-improvement

Conversation

@maheshbakali
Copy link
Copy Markdown

  • Introduced a new project for unit tests: BotSharp.Core.UnitTests.
  • Added tests for SettingService, verifying masking functionality.

- Introduced a new project for unit tests: BotSharp.Core.UnitTests.
- Added tests for SettingService, verifying masking functionality.
@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

Add unit tests and fix SettingService masking logic

🧪 Tests ✨ Enhancement

Grey Divider

Walkthroughs

Description
• Added comprehensive unit tests for SettingService.Mask method
• Fixed masking logic to correctly preserve string length
• Created new BotSharp.Core.UnitTests project with xUnit framework
• Updated solution file to include new test project
Diagram
flowchart LR
  A["SettingService.Mask<br/>Original Logic"] -->|"Bug: Incorrect<br/>Length Calculation"| B["Fixed Logic<br/>keepLength = Length-1/2"]
  C["New Test Project<br/>BotSharp.Core.UnitTests"] -->|"Validates"| B
  C -->|"Tests Edge Cases"| D["Null/Empty<br/>Short/Long Strings<br/>API Keys"]
  B -->|"Preserves Length<br/>Masks Suffix"| E["Correct Masking<br/>Behavior"]
Loading

Grey Divider

File Changes

1. BotSharp.Core.UnitTests/Infrastructures/SettingServiceTests.cs 🧪 Tests +87/-0

Comprehensive unit tests for Mask method

• Added 7 test methods covering SettingService.Mask functionality
• Tests include null/empty inputs, short/medium/long strings, and edge cases
• Validates masking preserves original string length and replaces suffix with asterisks
• Tests specific scenarios like API keys and very long strings (1000 chars)

BotSharp.Core.UnitTests/Infrastructures/SettingServiceTests.cs


2. src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs 🐞 Bug fix +3/-3

Fix masking logic for correct length preservation

• Fixed masking algorithm to correctly calculate keepLength as (value.Length - 1) / 2
• Changed asterisk count calculation to value.Length - keepLength for proper length preservation
• Simplified return statement by removing intermediate variable assignment

src/Infrastructure/BotSharp.Core/Infrastructures/SettingService.cs


3. BotSharp.Core.UnitTests/BotSharp.Core.UnitTests.csproj ⚙️ Configuration changes +28/-0

New unit test project configuration

• Created new test project file with xUnit and test SDK dependencies
• Configured project with implicit usings and nullable reference types enabled
• Added reference to BotSharp.Core project for testing
• Included test runners and code coverage tools (coverlet)

BotSharp.Core.UnitTests/BotSharp.Core.UnitTests.csproj


View more (1)
4. BotSharp.sln ⚙️ Configuration changes +11/-0

Register new test project in solution

• Added BotSharp.Core.UnitTests project to solution with GUID 53E53E98-3C14-4AED-AC40-BD88170C5FE5
• Added build configurations for Debug and Release across multiple platforms
• Assigned test project to solution folder hierarchy

BotSharp.sln


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Apr 19, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@maheshbakali maheshbakali changed the title Add unit tests for SettingService and enhance masking logic Enhance masking logic Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant