© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
38 replies
Kymera

AutoMapper best practices

Hey guys! I am using AutoMapper to map my service objects to DTOs, but i was wondering if I am doing it clean.

[HttpPost]
public IActionResult Get()
{
var map = _mapService.GetMap();

var result = _mapper.Map<MapDto>(map);

return Ok(result);
}

How do I make sure that this works? I have created some tests for the controller but they don't feel quite right...

Test startup method:

public MapControllerTests()
{
mapService = new Mock<IMapService>();
mapper = new Mock<IMapper>();

var serviceResponse = new Map { Points = [new Point()] };

mapService.Setup(m => m.GetMap()).Returns(serviceResponse);
mapper.Setup(m => m.Map<MapDto>(serviceResponse)).Returns(new MapDto { Points = [] }); // <-- Feels like too much logic in test

mapController = new MapController(mapper.Object, mapService.Object);
}
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Permission best practices
C#CC# / help
3y ago
✅ C# best practices clarification
C#CC# / help
3y ago
❔ ✅ AutoMapper DI
C#CC# / help
3y ago