testingmockingobjectmapperabp-framework

How to mock Object Mapper


abp.io framework - testing

I am trying to set an ApplicationService class. The method I'm trying to test uses 'ObjectMapper.Map<classFrom, classTo>(obj)'

I have used NSubstitue as LazyServiceProvider, but I am unable to find the correct Substitute to create an ObjectMapper.

Has anyone done this?


Solution

  • We resolved the issue.

    We used a substitute for LazyServiceProvider.

    Then the key was using a very specific setup when the LazyServiceProvider is trying to create the Object Mapper (see the abp code).

    _abpProvider = Substitute.For<IAbpLazyServiceProvider>();
    _abpProvider.LazyGetService<IObjectMapper>(Arg.Any<Func<IServiceProvider, object>>()).Returns(_objectMapper);
    

    This allowed us to set up our own ObjectMapper in our test method, and have it be used in our ApplicationService.