Skip to content

Commit e4777d6

Browse files
authored
Releases/1.4 preview (#136)
* v1.4-preview branch * Bugs/issue129 (#131) * Short-circuiting expression replacement when target and replacement are the same * Specifically retrieving ToTarget data sources where required * Returning existing arrays in ICollection.ToArray if possible * Updating release notes * Adding v1.4-preview NuGet package * Bugs/issue130 (#132) * Method renames / Extending typed ToTarget test, re: #129, #130 * Extending typed ToTarget test / Adding failing ToTarget mapping callback test / Compiling ConfigInfo.ToMappingData caller * Improving MappingCreationContext ctors * Moving MappingCreationContext logic into MappingCreationContext * Tidying * Removing unused method / Tidying * Support for mapping callbacks within non-implementation pair, ToTarget mappings * Support for implementation pair ToTarget configuration Removing unnecessary package from EF2 Core test project * Continued * Tidying * Fixing support for ToTarget data sources in repeated mappings * Handling null configured implementation ToTarget data sources * Updating to v1.4-preview2 * Features/configured source member validation (#134) * Erroring if redundant matching source member is configured * Improving configured data source validation Support for same-typed configured data source for otherwise-unconstructable target members * Fixing ToTarget complex type entry dictionary mapping, re: #133 * Skipping existing dictionary value checks when target is definitely unpopulated * Code coverage changes / Tidying * Updating to v1.4-preview3 * Fixing build * Fixing complex type dictionary merging * Updating release notes * Updating to v1.4 * v1.4 NuGet package
1 parent a0ee13d commit e4777d6

File tree

57 files changed

+1151
-352
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1151
-352
lines changed

AgileMapper.UnitTests.Orms.EfCore2/AgileMapper.UnitTests.Orms.EfCore2.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@
6060
<Reference Include="Microsoft.Extensions.Caching.Memory, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
6161
<HintPath>..\packages\Microsoft.Extensions.Caching.Memory.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll</HintPath>
6262
</Reference>
63-
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
64-
<HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
65-
</Reference>
6663
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
6764
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll</HintPath>
6865
</Reference>

AgileMapper.UnitTests/Configuration/WhenConfiguringDataSourcesIncorrectly.cs

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,48 @@ public void ShouldErrorIfDuplicateDataSourceIsConfigured()
112112
[Fact]
113113
public void ShouldErrorIfRedundantDataSourceIsConfigured()
114114
{
115-
Should.Throw<MappingConfigurationException>(() =>
115+
var configEx = Should.Throw<MappingConfigurationException>(() =>
116+
{
117+
using (var mapper = Mapper.CreateNew())
118+
{
119+
mapper.WhenMapping
120+
.From<PublicProperty<int>>()
121+
.To<PublicField<string>>()
122+
.Map(pp => pp.Value, pf => pf.Value);
123+
}
124+
});
125+
126+
configEx.Message.ShouldContain("PublicProperty<int>.Value");
127+
configEx.Message.ShouldContain("PublicField<string>.Value");
128+
configEx.Message.ShouldContain("does not need to be configured");
129+
}
130+
131+
[Fact]
132+
public void ShouldErrorIfRedundantConstructorParameterDataSourceIsConfigured()
133+
{
134+
var configEx = Should.Throw<MappingConfigurationException>(() =>
135+
{
136+
using (var mapper = Mapper.CreateNew())
137+
{
138+
mapper.WhenMapping
139+
.From<PublicProperty<int>>()
140+
.To<PublicCtor<string>>()
141+
.Map(ctx => ctx.Source.Value)
142+
.ToCtor<string>();
143+
}
144+
});
145+
146+
configEx.Message.ShouldContain("PublicProperty<int>.Value");
147+
configEx.Message.ShouldContain("will automatically be mapped");
148+
configEx.Message.ShouldContain("target constructor parameter");
149+
configEx.Message.ShouldContain("PublicCtor<string>.value");
150+
configEx.Message.ShouldContain("does not need to be configured");
151+
}
152+
153+
[Fact]
154+
public void ShouldErrorIfRedundantDerivedTypeDataSourceIsConfigured()
155+
{
156+
var configEx = Should.Throw<MappingConfigurationException>(() =>
116157
{
117158
using (var mapper = Mapper.CreateNew())
118159
{
@@ -129,6 +170,8 @@ public void ShouldErrorIfRedundantDataSourceIsConfigured()
129170
.To(x => x.Value);
130171
}
131172
});
173+
174+
configEx.Message.ShouldContain("already has configured data source");
132175
}
133176

134177
[Fact]
@@ -262,6 +305,24 @@ public void ShouldErrorIfUnconvertibleConstructorValueConstantSpecified()
262305
configurationException.Message.ShouldContain("Unable to convert");
263306
}
264307

308+
[Fact]
309+
public void ShouldErrorIfUnconvertibleConstructorSourceValueSpecified()
310+
{
311+
var configurationException = Should.Throw<MappingConfigurationException>(() =>
312+
{
313+
using (var mapper = Mapper.CreateNew())
314+
{
315+
mapper.WhenMapping
316+
.From<PublicProperty<int>>()
317+
.To<PublicCtor<Guid>>()
318+
.Map(ctx => ctx.Source.Value)
319+
.ToCtor<Guid>();
320+
}
321+
});
322+
323+
configurationException.Message.ShouldContain("Unable to convert");
324+
}
325+
265326
[Fact]
266327
public void ShouldErrorIfSimpleTypeConfiguredForComplexTarget()
267328
{
@@ -281,6 +342,25 @@ public void ShouldErrorIfSimpleTypeConfiguredForComplexTarget()
281342
"Person.Id of type 'Guid' cannot be mapped to target type 'Address'");
282343
}
283344

345+
[Fact]
346+
public void ShouldErrorIfSimpleTypeConfiguredForComplexConstructorParameter()
347+
{
348+
var configurationException = Should.Throw<MappingConfigurationException>(() =>
349+
{
350+
using (var mapper = Mapper.CreateNew())
351+
{
352+
mapper.WhenMapping
353+
.From<PublicField<int>>()
354+
.To<PublicCtor<Address>>()
355+
.Map(ctx => ctx.Source.Value)
356+
.ToCtor<Address>();
357+
}
358+
});
359+
360+
configurationException.Message.ShouldContain(
361+
"PublicField<int>.Value of type 'int' cannot be mapped to target type 'Address'");
362+
}
363+
284364
[Fact]
285365
public void ShouldErrorIfSimpleTypeConfiguredForEnumerableTarget()
286366
{
@@ -300,6 +380,25 @@ public void ShouldErrorIfSimpleTypeConfiguredForEnumerableTarget()
300380
"PublicField<int>.Value of type 'int' cannot be mapped to target type 'int[]'");
301381
}
302382

383+
[Fact]
384+
public void ShouldErrorIfSimpleTypeConfiguredForEnumerableConstructorParameter()
385+
{
386+
var configurationException = Should.Throw<MappingConfigurationException>(() =>
387+
{
388+
using (var mapper = Mapper.CreateNew())
389+
{
390+
mapper.WhenMapping
391+
.From<PublicField<string>>()
392+
.To<PublicCtor<int[]>>()
393+
.Map(ctx => ctx.Source.Value)
394+
.ToCtor("value");
395+
}
396+
});
397+
398+
configurationException.Message.ShouldContain(
399+
"PublicField<string>.Value of type 'string' cannot be mapped to target type 'int[]'");
400+
}
401+
303402
[Fact]
304403
public void ShouldErrorIfUnconvertibleEnumerableElementTypeConfigured()
305404
{
@@ -308,9 +407,9 @@ public void ShouldErrorIfUnconvertibleEnumerableElementTypeConfigured()
308407
using (var mapper = Mapper.CreateNew())
309408
{
310409
mapper.WhenMapping
311-
.From<PublicField<PublicField<int>[]>>()
410+
.From<PublicTwoFields<PublicField<int>[], int[]>>()
312411
.To<PublicField<int[]>>()
313-
.Map(s => s.Value, t => t.Value);
412+
.Map(s => s.Value1, t => t.Value);
314413
}
315414
});
316415

0 commit comments

Comments
 (0)