Skip to content

feat: add Check validation utility class with comprehensive unit tests#120

Merged
Soar360 merged 1 commit into
mainfrom
feature/add-check-validation
Jun 27, 2026
Merged

feat: add Check validation utility class with comprehensive unit tests#120
Soar360 merged 1 commit into
mainfrom
feature/add-check-validation

Conversation

@Soar360

@Soar360 Soar360 commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

This pull request makes a minor formatting change to the StringExtensions.cs file. An extra newline was added at the end of the file to ensure proper file formatting.

Copilot AI review requested due to automatic review settings June 27, 2026 04:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces a new Check argument-validation utility to the LuYao.Common library and adds a corresponding unit test suite, plus a small formatting-only change in StringExtensions.cs.

Changes:

  • Added Check static utility class with validation helpers (null checks, string length checks, range/positive checks, etc.).
  • Added CheckTests unit tests covering major Check behaviors.
  • Added a trailing blank line in StringExtensions.cs (formatting).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.

File Description
tests/LuYao.Common.UnitTests/CheckTests.cs Adds unit tests for the new Check validation APIs.
src/LuYao.Common/StringExtensions.cs Formatting-only: ensures file ends with a newline/blank line.
src/LuYao.Common/Check.cs Introduces the new Check validation utility class.

Comment thread src/LuYao.Common/Check.cs
Comment on lines +303 to +316
public static float Positive(
float value,
string parameterName)
{
if (value == 0)
{
throw new ArgumentException($"{parameterName} is equal to zero");
}
else if (value < 0)
{
throw new ArgumentException($"{parameterName} is less than zero");
}
return value;
}
Comment thread src/LuYao.Common/Check.cs
Comment on lines +325 to +338
public static double Positive(
double value,
string parameterName)
{
if (value == 0)
{
throw new ArgumentException($"{parameterName} is equal to zero");
}
else if (value < 0)
{
throw new ArgumentException($"{parameterName} is less than zero");
}
return value;
}
Comment thread src/LuYao.Common/Check.cs
Comment on lines +440 to +451
public static float Range(
float value,
string parameterName,
float minimumValue,
float maximumValue = float.MaxValue)
{
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
Comment thread src/LuYao.Common/Check.cs
Comment on lines +462 to +474
public static double Range(
double value,
string parameterName,
double minimumValue,
double maximumValue = double.MaxValue)
{
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
}

return value;
}
Comment thread src/LuYao.Common/Check.cs

if (!typeof(TBaseType).IsAssignableFrom(type))
{
throw new ArgumentException($"{parameterName} (type of {type.AssemblyQualifiedName}) should be assignable to the {typeof(TBaseType).FullName}!");
Comment on lines +691 to +703
[TestMethod]
public void Range_Double_WithValueInRange_ReturnsValue()
{
// Arrange
double value = 5.5;

// Act
var result = Check.Range(value, nameof(value), minimumValue: 0.0, maximumValue: 10.0);

// Assert
Assert.AreEqual(value, result);
}

Comment on lines +596 to +621
[TestMethod]
public void Positive_Double_WithPositiveValue_ReturnsValue()
{
// Arrange
double value = 3.14;

// Act
var result = Check.Positive(value, nameof(value));

// Assert
Assert.AreEqual(value, result);
}

[TestMethod]
public void Positive_Decimal_WithPositiveValue_ReturnsValue()
{
// Arrange
decimal value = 99.99m;

// Act
var result = Check.Positive(value, nameof(value));

// Assert
Assert.AreEqual(value, result);
}

Comment on lines 170 to 174
var len = endIndex - startIndex;
return str.Substring(startIndex, len);
}

}
@Soar360 Soar360 merged commit 5a8dd58 into main Jun 27, 2026
2 checks passed
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.

2 participants