Madhu
Madhu

Reputation: 1

How to use IMapper in Xunit test for Service method

I tried to create for mapper moq object but it is not working can anyone help on the how to access the mapping solution while run the test case in service method. I tried below code

private Mock<IMapper> _mapper = new Mock<IMapper>();

I pass the service dependency injection

_abcService = new AbcService(_mapper.Object);


System.NullReferenceException: 'Object reference not set to an instance of an object.'

getting this error

Upvotes: 0

Views: 255

Answers (1)

worldwildwebdev
worldwildwebdev

Reputation: 414

As Jimmy Bogard stated in his AutoMapper Usage Guide don't mock AutoMapper because it doesn't add any value. Just pass real instance to your service and mock elsewhere ex. the data layer. This means that you should not have any business logic in you configuration profiles.

You can also assert that your configuration profiles are correct. See this. May be relevant to that question.

Upvotes: 1

Related Questions