Browse Source

Update exception message for missing object mapping

pull/23630/head
maliming 1 year ago
parent
commit
3599fc454c
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 12
      framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs
  2. 9
      framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs

12
framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs

@ -99,26 +99,26 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider
protected virtual AbpException GetNoMapperFoundException<TSource, TDestination>() protected virtual AbpException GetNoMapperFoundException<TSource, TDestination>()
{ {
var newLine = Environment.NewLine; var newLine = Environment.NewLine;
var message = "No type mapper class was found for the given source and destination types." + var message = "No object mapping was found for the specified source and destination types." +
newLine + newLine +
newLine + newLine +
"Mapping types:" + "Mapping attempted:" +
newLine + newLine +
$"{typeof(TSource).Name} -> {typeof(TDestination).Name}" + $"{typeof(TSource).Name} -> {typeof(TDestination).Name}" +
newLine + newLine +
$"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" + $"{typeof(TSource).FullName} -> {typeof(TDestination).FullName}" +
newLine + newLine +
newLine + newLine +
"Define a mapping class to resolve this issue:" + "How to fix:" +
newLine +
"Define a mapping class for these types:" +
newLine + newLine +
" - Use MapperBase<TSource, TDestination> for one-way mapping." + " - Use MapperBase<TSource, TDestination> for one-way mapping." +
newLine + newLine +
" - Use TwoWayMapperBase<TDestination, TSource> for two-way mapping." + " - Use TwoWayMapperBase<TDestination, TSource> for two-way mapping." +
newLine + newLine +
newLine + newLine +
"See the Mapperly documentation for details:" + "For details, see the Mapperly integration document https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration";
newLine +
"https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration";
return new AbpException(message); return new AbpException(message);
} }

9
framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/AbpMapperlyModule_Basic_Tests.cs

@ -106,13 +106,14 @@ public class AbpMapperlyModule_Basic_Tests : AbpIntegratedTest<MapperlyTestModul
public void Should_Throw_Exception_If_Mapper_Is_Not_Found() public void Should_Throw_Exception_If_Mapper_Is_Not_Found()
{ {
var exception = Assert.Throws<AbpException>(() =>_objectMapper.Map<MyEntity, MyClassDto>(new MyEntity())); var exception = Assert.Throws<AbpException>(() =>_objectMapper.Map<MyEntity, MyClassDto>(new MyEntity()));
exception.Message.ShouldBe("No type mapper class was found for the given source and destination types.\n\n" + exception.Message.ShouldBe("No object mapping was found for the specified source and destination types.\n\n" +
"Mapping types:\n" + "Mapping attempted:\n" +
"MyEntity -> MyClassDto\n" + "MyEntity -> MyClassDto\n" +
"Volo.Abp.Mapperly.SampleClasses.MyEntity -> Volo.Abp.Mapperly.MyClassDto\n\n" + "Volo.Abp.Mapperly.SampleClasses.MyEntity -> Volo.Abp.Mapperly.MyClassDto\n\n" +
"Define a mapping class to resolve this issue:\n" + "How to fix:\n" +
"Define a mapping class for these types:" + "\n" +
" - Use MapperBase<TSource, TDestination> for one-way mapping.\n" + " - Use MapperBase<TSource, TDestination> for one-way mapping.\n" +
" - Use TwoWayMapperBase<TDestination, TSource> for two-way mapping.\n\n" + " - Use TwoWayMapperBase<TDestination, TSource> for two-way mapping.\n\n" +
"See the Mapperly documentation for details:\nhttps://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration"); "For details, see the Mapperly integration document https://abp.io/docs/latest/framework/infrastructure/object-to-object-mapping#mapperly-integration");
} }
} }

Loading…
Cancel
Save