Skip to content

[Code Quality] Servy.Core ServiceMapper.ToDto is dead code in src/ (only tests call it) #1049

@Christophe-Rogiers

Description

@Christophe-Rogiers

Severity: Info

File: src/Servy.Core/Mappers/ServiceMapper.cs

Lines: 22-89 (ToDto method)

Issue:
ServiceMapper.ToDto(Service domain, int? id = null) has zero callers in src/. It is only invoked from the unit-test project (tests/Servy.Core.UnitTests/Mappers/ServiceMapperTests.cs). All real persistence paths build the ServiceDto inline:

ServiceMapper.ToDomain (the inverse direction) IS used in production, so the class itself is not entirely dead — but ToDto is.

Why this matters:

  1. Tests "verify" a method nobody calls in production, giving false confidence in the persistence path.
  2. Anyone fixing a real DTO bug in ServiceManager.InstallServiceAsync won't see the test failure because the test exercises a different code path (ToDto vs the inline construction).
  3. ToDto and the inline construction can drift silently. Same root cause as [Code Quality] Servy ServiceCommands.InstallService rebuilds Config→DTO mapping (drifts from MainViewModel.ModelToServiceDto, different sentinel values) #1021.

Suggested fix:
Either:

  1. Remove ToDto entirely (and its tests) — make the inline constructions the single source of truth, or
  2. Refactor ServiceManager.InstallServiceAsync, MainViewModel.ModelToServiceDto, and Servy ServiceCommands.InstallService to call ServiceMapper.ToDto, eliminating ~150 lines of duplicate mapping logic and resolving [Code Quality] Servy ServiceCommands.InstallService rebuilds Config→DTO mapping (drifts from MainViewModel.ModelToServiceDto, different sentinel values) #1021 at the same time.

Option 2 is the structurally cleaner fix — option 1 just acknowledges the dead code.

Code snippet (existing call sites):

$ grep -rn "ServiceMapper\.ToDto\|\.ToDto(" src/
# (no matches)

$ grep -rn "ServiceMapper\.ToDto" tests/
tests/Servy.Core.UnitTests/Mappers/ServiceMapperTests.cs:35
tests/Servy.Core.UnitTests/Mappers/ServiceMapperTests.cs:102

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions