Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Suggestion: IMapper.From should return IAdapterBuilder<TSource> not TypeAdapterBuilder<TSource>

Open Ergamon opened this issue 3 years ago • 1 comments

I have currently the following code

private readonly IMapper mapper; // Set by dependency injection

I can easily set up a mockup for IMapper and unit test the following code:

mapper.Map<TDestination>(source);

but how can I test

mapper.From(source).AddParameters("param", 42).AdaptToType<TDestination>();

In my opinion the interface should not return a concrete type, but also an abstraction.

public interface IMapper { TypeAdapterConfig Config { get; }

IAdapterBuilder<TSource> From<TSource>(TSource source); // Not TypeAdapterBuilder<TSource>

TDestination Map<TDestination>(object source);

TDestination Map<TSource, TDestination>(TSource source);

TDestination Map<TSource, TDestination>(TSource source, TDestination destination);

object Map(object source, Type sourceType, Type destinationType);

object Map(object source, object destination, Type sourceType, Type destinationType);

}

Ergamon avatar Sep 30 '21 09:09 Ergamon

Class with internal constructor causes issues when using with NSubstitute

gritcsenko avatar Jul 12 '22 01:07 gritcsenko