Extra Small size test (XS)
This test is all about 2 objects with primitive type properties and actually it is not about objects at all. This test all about "Struct" types. Why is it so extra small and simple? - because we are using structs and the same signature for source and destination. Please take a look at the diagram bellow:
Here you will find mapping registration for different mappers:
Expressmapper:
Mapper.Register<Item, ItemViewModel>();
Automapper:
Mapper.CreateMap<Item, ItemViewModel>();
Mapster:
// Enum Mapping is not supported
OoMapper:
// Enum Mapping is not supported
TinyMapper:
// Enum Mapping is not supported
ValueInjecter:
// No code is required for setup mapping...
Small size test (S)
This test is all about 2 objects only with primitive type properties. Why is it so small and simple? - because we are using the same signature for the source and the destination. Please take a look at the diagram bellow:
Here you will find mapping registration for different mappers:
Expressmapper:
Mapper.Register<News, NewsViewModel>();
Automapper:
Mapper.CreateMap<News, NewsViewModel>();
Mapster:
// No code is required for setup mapping...
OoMapper:
Mapper.CreateMap<Item, ItemViewModel>();
TinyMapper:
TinyMapper.Bind<Item, ItemViewModel>();
ValueInjecter:
// No code is required for setup mapping...
Medium size test (S)
This test is all about 2 objects with ref type property. Please take a look at the diagram bellow:
Here you will find mapping registration for different mappers:
Expressmapper:
Mapper.Register<Role, RoleViewModel>();
Mapper.Register<User, UserViewModel>()
.Member(dest => dest.BelongTo,
src => src.Role);
Automapper:
Mapper.CreateMap<Role, RoleViewModel>();
Mapper.CreateMap<User, UserViewModel>()
.ForMember(dest => dest.BelongTo,
src => src.MapFrom(m => m.Role));
Mapster:
TypeAdapterConfig<User, UserViewModel>
.NewConfig()
.Map(dest => dest.BelongTo,
src => TypeAdapter
.Adapt<Role,
RoleViewModel<(src.Role));
OoMapper:
Mapper.CreateMap<Role, RoleViewModel>();
Mapper.CreateMap<User, UserViewModel>()
.ForMember(dest => dest.BelongTo,
src => src.MapFrom(m => m.Role));
TinyMapper:
// Mapping is not supported...
ValueInjecter:
Mapper.AddMap<User, UserViewModel>
(src =>
{
var userViewModel = new UserViewModel();
userViewModel.InjectFrom(src);
userViewModel.BelongTo =
Mapper.Map<Role,
RoleViewModel>(src.Role);
return userViewModel;
});
Large size test (L)
This test is all about 2 objects with collection type property. Please take a look at the diagram bellow:
Here you will find mapping registration for different mappers:
Expressmapper:
Mapper.Register<Article, ArticleViewModel>();
Mapper.Register<Author, AuthorViewModel>()
.Function(dest => dest.OwnedArticles,
src => src.Articles);
Automapper:
Mapper.CreateMap<Article, ArticleViewModel>();
Mapper.CreateMap<Author, AuthorViewModel>()
.ForMember(dest => dest.OwnedArticles,
src => src.ResolveUsing(m => m.Articles));
Mapster:
TypeAdapterConfig<Author, AuthorViewModel>
.NewConfig()
.Map(dest => dest.OwnedArticles,
src =>
TypeAdapter
.Adapt<IEnumerable<Article>
, ArticleViewModel[]>
(src.Articles));
OoMapper:
Mapper.CreateMap<Article, ArticleViewModel>();
Mapper.CreateMap<Author, AuthorViewModel>()
.ForMember(dest =>
dest.OwnedArticles,
src =>
src.MapFrom(m => m.Articles));
TinyMapper:
// Mapping is not supported
ValueInjecter:
Mapper.AddMap<Author, AuthorViewModel>
(src =>
{
var articles =
new ArticleViewModel[src.Articles.Count()];
var authorViewModel = new AuthorViewModel();
authorViewModel.InjectFrom(src);
for (var i = 0; i < articles.Length; i++)
{
articles[i] = Mapper.Map<Article,
ArticleViewModel>
(src.Articles.ElementAt(i));
}
authorViewModel.OwnedArticles = articles;
return authorViewModel;
});
XL size test (XL)
This test is all about 2 objects with a collection type property as well as nested collections and multiple reference type properties. Please take a look at the diagram bellow:
Here you will find mapping registration for different mappers:
Expressmapper:
Mapper.Register<ProductVariant,
ProductVariantViewModel>();
Mapper.Register<Product,
ProductViewModel>()
.Member(dest => dest.DefaultSharedOption,
src => src.DefaultOption);
Mapper.Register<Test, TestViewModel>()
.Member(dest => dest.Age, src => src.Age)
.Member(dest => dest.Weight,
src => src.Weight * 2)
.Member(dest => dest.Type,
src => (Types)src.Type)
.Member(dest => dest.Name,
src =>
string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age))
.Member(dest => dest.Description,
src =>
string.Format("{0} - {1}",
src.Name, src.Id))
.Member(dest => dest.SpareTheProduct,
src => src.SpareProduct);
Automapper:
Mapper.CreateMap<ProductVariant,
ProductVariantViewModel>();
Mapper.CreateMap<Product,
ProductViewModel>()
.ForMember(dest => dest.DefaultSharedOption,
src =>
src.MapFrom(m => m.DefaultOption));
Mapper.CreateMap<Test, TestViewModel>()
.ForMember(dest => dest.Age,
src => src.MapFrom(src => src.Age))
.ForMember(dest => dest.Weight,
src =>
src.MapFrom(src => src.Weight * 2))
.ForMember(dest => dest.Type,
src =>
src.MapFrom(m => (Types)m.Type))
.ForMember(dest => dest.Name,
src => src.MapFrom(m =>
string.Format("{0} - {1} - {2}",
m.Name, m.Weight, m.Age)))
.ForMember(dest => dest.Description,
src => src.MapFrom(m =>
string.Format("{0} - {1}",
src.Name, src.Id)))
.ForMember(dest => dest.SpareTheProduct,
src =>
src.MapFrom(m => m.SpareProduct));
Mapster:
TypeAdapterConfig<Product, ProductViewModel>
.NewConfig()
.Map(dest => dest.DefaultSharedOption,
src =>
TypeAdapter.Adapt<ProductVariant,
ProductVariantViewModel>
(src.DefaultOption));
TypeAdapterConfig<Test, TestViewModel>
.NewConfig()
.Map(dest => dest.Age, src => src.Age)
.Map(dest => dest.Weight,
src => src.Weight * 2)
.Map(dest => dest.Type,
src => (Types)src.Type)
.Map(dest => dest.Name,
src => string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age))
.Map(dest => dest.Name,
src => string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age))
.Map(dest => dest.SpareTheProduct,
src =>
TypeAdapter.Adapt<Product,
ProductViewModel>
(src.SpareProduct))
.Map(dest => dest.Description,
src => string.Format("{0} - {1}",
src.Name, src.Id));
OoMapper:
Mapper.CreateMap<ProductVariant,
ProductVariantViewModel>();
Mapper.CreateMap<Product,
ProductViewModel>()
.ForMember(dest => dest.DefaultSharedOption,
src =>
src.MapFrom(m => m.DefaultOption));
Mapper.CreateMap<Test, TestViewModel>()
.ForMember(dest => dest.Age,
src => src.MapFrom(src => src.Age))
.ForMember(dest => dest.Weight,
src =>
src.MapFrom(src => src.Weight * 2))
.ForMember(dest => dest.Type,
src =>
src.MapFrom(m => (Types)m.Type))
.ForMember(dest => dest.Name,
src => src.MapFrom(m =>
string.Format("{0} - {1} - {2}",
m.Name, m.Weight, m.Age)))
.ForMember(dest => dest.Description,
src => src.MapFrom(m =>
string.Format("{0} - {1}",
src.Name, src.Id)))
.ForMember(dest => dest.SpareTheProduct,
src =>
src.MapFrom(m => m.SpareProduct))
.ForMember(dest => dest.Products,
opt =>
opt.MapFrom(src => src.Products));
TinyMapper:
// Mapping is not supported
ValueInjecter:
Mapper.AddMap<Product,
ProductViewModel>(src =>
{
var productViewModel = new ProductViewModel();
productViewModel.InjectFrom(src);
productViewModel.DefaultSharedOption =
Mapper.Map<ProductVariant,
ProductVariantViewModel>(src.DefaultOption);
productViewModel.Options =
new List<ProductVariantViewModel>();
foreach (var pv in src.Options)
{
productViewModel.Options.Add(
Mapper.Map<ProductVariant,
ProductVariantViewModel>(pv));
}
return productViewModel;
});
Mapper.AddMap<Test, TestViewModel>(src =>
{
var testViewModel = new TestViewModel(
string.Format("{0} - {1}",
src.Name, src.Id));
testViewModel.InjectFrom(src);
testViewModel.Name = string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age);
testViewModel.Product =
Mapper.Map<Product,
ProductViewModel>(src.Product);
testViewModel.SpareTheProduct =
Mapper.Map<Product,
ProductViewModel>(src.SpareProduct);
testViewModel.Type = (Types) src.Type;
testViewModel.Weight = src.Weight*2;
testViewModel.Products =
new List<ProductViewModel>();
foreach (var product in src.Products)
{
testViewModel.Products.Add(
Mapper.Map<Product,
ProductViewModel>(product));
}
return testViewModel;
});
XXL size test (XXL)
This test is all about 2 objects with a collection type property as well as nested collections and multiple reference type properties. Also there are a lot of techniques are used like "Instantiate", "AfterMap", "BeforeMap", etc.. Please take a look at the diagram bellow:
Here you will find mapping registration for different mappers:
Expressmapper:
Mapper.Register<ProductVariant,
ProductVariantViewModel>();
Mapper.Register<Product,
ProductViewModel>()
.Member(dest => dest.DefaultSharedOption,
src => src.DefaultOption);
Mapper.Register<Test, TestViewModel>()
.Before((src, dest) => dest.Age = src.Age)
.After((src, dest) => dest.Weight = src.Weight * 2)
.Ignore(dest => dest.Age)
.Member(dest => dest.Type, src => (Types)src.Type)
.Member(dest => dest.Name,
src =>
string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age))
.Function(dest => dest.SpareTheProduct,
src => src.SpareProduct)
.Instantiate(src =>
new TestViewModel(
string.Format("{0} - {1}",
src.Name, src.Id)));
Automapper:
Mapper.CreateMap<ProductVariant,
ProductVariantViewModel>();
Mapper.CreateMap<Product,
ProductViewModel>()
.ForMember(dest => dest.DefaultSharedOption,
src => src.MapFrom(m => m.DefaultOption));
Mapper.CreateMap<Test, TestViewModel>()
.BeforeMap((src, dest) => dest.Age = src.Age)
.AfterMap((src, dest) => dest.Weight = src.Weight * 2)
.ForMember(dest => dest.Age, src => src.Ignore())
.ForMember(dest => dest.Type, src =>
src.MapFrom(m => (Types)m.Type))
.ForMember(dest => dest.Name,
src => src.MapFrom(m =>
string.Format("{0} - {1} - {2}",
m.Name, m.Weight, m.Age)))
.ForMember(dest => dest.SpareTheProduct,
src => src.ResolveUsing(m => m.SpareProduct))
.ConstructUsing((src =>
new TestViewModel(string.Format("{0} - {1}",
src.Name, src.Id))));
Mapster:
TypeAdapterConfig<Product, ProductViewModel>
.NewConfig()
.Map(dest => dest.DefaultSharedOption,
src =>
TypeAdapter.Adapt<ProductVariant,
ProductVariantViewModel>
(src.DefaultOption));
TypeAdapterConfig<Test, TestViewModel>
.NewConfig()
.Map(dest => dest.Age, src => src.Age)
.Map(dest => dest.Weight,
src => src.Weight * 2)
.Map(dest => dest.Type,
src => (Types)src.Type)
.Map(dest => dest.Name,
src => string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age))
.Map(dest => dest.Name,
src => string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age))
.Map(dest => dest.SpareTheProduct,
src =>
TypeAdapter.Adapt<Product,
ProductViewModel>
(src.SpareProduct))
.Map(dest => dest.Description,
src => string.Format("{0} - {1}",
src.Name, src.Id));
OoMapper:
// BeforeMap, AfterMap,
// Custom constructor are not supported
TinyMapper:
// Mapping is not supported
ValueInjecter:
Mapper.AddMap<Product,
ProductViewModel>(
src =>
{
var productViewModel = new ProductViewModel();
productViewModel.InjectFrom(src);
productViewModel.DefaultSharedOption =
Mapper.Map<ProductVariant,
ProductVariantViewModel>(src.DefaultOption);
productViewModel.Options =
new List<ProductVariantViewModel>();
foreach (var pv in src.Options)
{
productViewModel.Options.Add(
Mapper.Map<ProductVariant,
ProductVariantViewModel>(pv));
}
return productViewModel;
});
Mapper.AddMap<Test, TestViewModel>(src =>
{
var testViewModel = new TestViewModel(
string.Format("{0} - {1}",
src.Name, src.Id));
testViewModel.InjectFrom(src);
testViewModel.Name = string.Format("{0} - {1} - {2}",
src.Name, src.Weight, src.Age);
testViewModel.Product =
Mapper.Map<Product,
ProductViewModel>(src.Product);
testViewModel.SpareTheProduct =
Mapper.Map<Product,
ProductViewModel>(src.SpareProduct);
testViewModel.Type = (Types) src.Type;
testViewModel.Weight = src.Weight*2;
testViewModel.Products =
new List<ProductViewModel>();
foreach (var product in src.Products)
{
testViewModel.Products.Add(
Mapper.Map<Product,
ProductViewModel>(product));
}
return testViewModel;
});