Skip to content

Add ID Validation#65

Open
robinmanuelthiel wants to merge 3 commits intomainfrom
feat/rmt-id-validation
Open

Add ID Validation#65
robinmanuelthiel wants to merge 3 commits intomainfrom
feat/rmt-id-validation

Conversation

@robinmanuelthiel
Copy link
Owner

@robinmanuelthiel robinmanuelthiel commented Sep 4, 2025

No description provided.

Copy link

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 ID validation to the BasketItem model by implementing checks for both the Id and ProductId properties to ensure they are not null, empty, or whitespace.

  • Adds validation for the Id property to ensure it's not empty or whitespace
  • Adds validation for the ProductId property to ensure it's not empty
  • Integrates these validations into the existing Validate method

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

// New validation for Id
if (string.IsNullOrWhiteSpace(ProductId.ToString()))
{
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The error message incorrectly references 'Quantity' when validating ProductId. It should be 'ProductId must not be empty' instead.

Suggested change
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
results.Add(new ValidationResult("ProductId must not be empty", new[] { "ProductId" }));

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +31
// New validation for Id
if (string.IsNullOrWhiteSpace(ProductId.ToString()))
{
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Using ToString() on ProductId will never return null or whitespace since ToString() always returns a string representation. For GUID validation, check if ProductId equals Guid.Empty instead.

Suggested change
// New validation for Id
if (string.IsNullOrWhiteSpace(ProductId.ToString()))
{
results.Add(new ValidationResult("Quantity must not be empty", new[] { "ProductId" }));
// New validation for ProductId
if (ProductId <= 0)
{
results.Add(new ValidationResult("ProductId must be a positive integer", new[] { "ProductId" }));

Copilot uses AI. Check for mistakes.
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