Skip to content

Commit ccab637

Browse files
committed
Changing profile name and adding a test for configuration
1 parent 846b0e6 commit ccab637

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/AutoMapper/Configuration/MapperConfigurationExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void AddMaps(params Type[] typesFromAssembliesContainingMappingDefinition
8686
private void AddMapsCore(IEnumerable<Assembly> assembliesToScan)
8787
{
8888
var allTypes = assembliesToScan.Where(a => !a.IsDynamic).SelectMany(a => a.GetDefinedTypes()).ToArray();
89-
var autoMapAttributeProfile = new NamedProfile("AutoMapAttributeProfile");
89+
var autoMapAttributeProfile = new NamedProfile(nameof(AutoMapAttribute));
9090

9191
foreach (var type in allTypes)
9292
{

src/UnitTests/AttributeBasedMaps.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Should_map()
3636
[Fact]
3737
public void Should_validate_successfully()
3838
{
39-
typeof(AutoMapperConfigurationException).ShouldNotBeThrownBy(() => Configuration.AssertConfigurationIsValid("AutoMapAttributeProfile"));
39+
typeof(AutoMapperConfigurationException).ShouldNotBeThrownBy(() => Configuration.AssertConfigurationIsValid(nameof(AutoMapAttribute)));
4040
}
4141
}
4242

@@ -71,7 +71,35 @@ public void Should_reverse_map()
7171
[Fact]
7272
public void Should_validate_successfully()
7373
{
74-
typeof(AutoMapperConfigurationException).ShouldNotBeThrownBy(() => Configuration.AssertConfigurationIsValid("AutoMapAttributeProfile"));
74+
typeof(AutoMapperConfigurationException).ShouldNotBeThrownBy(() => Configuration.AssertConfigurationIsValid(nameof(AutoMapAttribute)));
75+
}
76+
}
77+
78+
public class When_duplicating_map_configuration_with_code_and_attribute : NonValidatingSpecBase
79+
{
80+
public class Source
81+
{
82+
public int Value { get; set; }
83+
}
84+
85+
[AutoMap(typeof(Source))]
86+
public class Dest
87+
{
88+
public int Value { get; set; }
89+
}
90+
91+
protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(cfg =>
92+
{
93+
cfg.CreateMissingTypeMaps = false;
94+
cfg.AddMaps(typeof(When_specifying_map_and_reverse_map_with_attribute));
95+
cfg.CreateMap<Source, Dest>();
96+
});
97+
98+
[Fact]
99+
public void Should_not_validate_successfully()
100+
{
101+
typeof(DuplicateTypeMapConfigurationException).ShouldBeThrownBy(() => Configuration.AssertConfigurationIsValid());
102+
75103
}
76104
}
77105
}

0 commit comments

Comments
 (0)