Skip to content

Add FluentValidation validators for archive and restore commands #14

Description

@ismailbarankarasu

Background

Pet report commands such as Cancel and Resolve validate that PetReportId is not Guid.Empty. The Archive and Restore commands currently do not have their own FluentValidation validators.

The relevant commands are:

src/RescueLink.Application/Features/PetReports/Archive/ArchivePetReportCommand.cs
src/RescueLink.Application/Features/PetReports/Restore/RestorePetReportCommand.cs

Goal

Add consistent request validation for Archive and Restore operations without changing handler or domain behavior.

Files to Create

Create:

src/RescueLink.Application/Features/PetReports/Archive/ArchivePetReportCommandValidator.cs
src/RescueLink.Application/Features/PetReports/Restore/RestorePetReportCommandValidator.cs

Create tests:

tests/RescueLink.Application.Tests/Features/Archive/ArchivePetReportCommandValidatorTests.cs
tests/RescueLink.Application.Tests/Features/PetReports/Restore/RestorePetReportCommandValidatorTests.cs

Follow the existing pattern in:

src/RescueLink.Application/Features/PetReports/Cancel/CancelPetReportCommandValidator.cs
tests/RescueLink.Application.Tests/Features/PetReports/Cancel/CancelPetReportCommandValidatorTests.cs

Suggested Implementation

Each validator should:

  1. Inherit from AbstractValidator<TCommand>.
  2. Add a rule for PetReportId.
  3. Require the ID to be non-empty using .NotEmpty().
  4. Avoid database calls or ownership checks inside the validator; those responsibilities remain in the handler/domain flow.

Each test class should cover:

  • A valid Guid produces a valid result.
  • Guid.Empty produces an invalid result.
  • The invalid result contains one validation error.

Acceptance Criteria

  • ArchivePetReportCommandValidator is added in the Archive feature folder.
  • RestorePetReportCommandValidator is added in the Restore feature folder.
  • Both validators reject Guid.Empty.
  • Both validators accept a non-empty Guid.
  • Focused unit tests are added for both validators.
  • No controller, handler, entity, or persistence behavior is changed.
  • dotnet build RescueLink.slnx succeeds.
  • dotnet test RescueLink.slnx succeeds.

Difficulty

Easy — suitable for someone learning FluentValidation and unit testing in .NET.

Before Starting

Please comment with a short plan and confirm that you have reviewed the existing Cancel validator and its tests.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions