Skip to content

refactor(test): use AutoMapper in test utilities #196

Closed
@coderabbitai

Description

@coderabbitai

Description

Currently, the test utilities in PlayerFakes.cs use manual mapping to create request and response models. Since we've migrated to AutoMapper for model mapping in the main codebase, we should also utilize AutoMapper in the test utilities for consistency.

Background

This issue originated from a code review comment in PR #194:
#194 (comment)

Proposed Changes

  • Add AutoMapper configuration to test project if not already available
  • Refactor manual mapping methods in PlayerFakes.cs to use AutoMapper
  • Ensure proper testing of AutoMapper configuration validity

Example Implementation

Instead of manually mapping properties like this:

public static PlayerResponseModel CreateResponseModelForOneNew()
{
    var player = CreateOneNew();
    return new PlayerResponseModel
    {
        Id = player.Id,
        FullName = $"{player.FirstName} {(string.IsNullOrWhiteSpace(player.MiddleName) ? "" : player.MiddleName + " ")}{player.LastName}".Trim(),
        // Other properties...
    };
}

We could use AutoMapper:

public static PlayerResponseModel CreateResponseModelForOneNew() =>
    Mapper.Map<PlayerResponseModel>(CreateOneNew());

This would reduce code duplication and ensure mapping consistency between production and test code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions