Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ddc29df
Fixing hardcoded int in runtime-typed mapping data construbtion lambd…
SteveWilkes Dec 2, 2018
0b27300
Updating to v1.1-preview, with first 1.1-preview NuGet package
SteveWilkes Dec 2, 2018
94cd6d2
Updating preview package nuspec
SteveWilkes Dec 2, 2018
d3c6227
Adding null entries to object dictionaries if source entry is null
SteveWilkes Dec 3, 2018
3fc5f21
Correctly incementing loop counter when source elements are null
SteveWilkes Dec 3, 2018
e7fff2b
Copying null source entries to target dictionaries
SteveWilkes Dec 3, 2018
5320925
Updating to ReadableExpressions v2.1
SteveWilkes Dec 12, 2018
9eb4120
Fixing runtime-typed ObjectMappingData parameter cast check, re: #110
SteveWilkes Dec 12, 2018
e931c15
Updating to v1.1-preview2
SteveWilkes Dec 12, 2018
09ffb95
Features/simple type to target config 111 (#112)
SteveWilkes Dec 17, 2018
eccc0a6
Applying simple type ToTarget configurations inside complex type enum…
SteveWilkes Dec 17, 2018
2cb1cde
Avoiding creation of nested blocks when making population expressions
SteveWilkes Dec 17, 2018
5320402
Updating to v1.1 preview 3
SteveWilkes Dec 17, 2018
3a21c4a
Adding v1.1-preview3 NuGet package
SteveWilkes Dec 17, 2018
f6ae7e2
Using operators where available (#116)
SteveWilkes Dec 29, 2018
41e12b0
Updating to v1.1-preview4
SteveWilkes Dec 29, 2018
20e8c0b
Only using MapRepeated for mapping with recursive object graphs - fix…
SteveWilkes Jan 6, 2019
28ede69
Clarifying what constitutes a recursive member
SteveWilkes Jan 7, 2019
b87e801
Updating to v1.1-preview5 and NuGet package
SteveWilkes Jan 7, 2019
91099aa
Support for configured complex-to-simple Type enumerable projection s…
SteveWilkes Jan 11, 2019
1262847
Improved null handling in object collection to object collection mapping
SteveWilkes Jan 11, 2019
fa70a42
Updating docs, re: Type conversion and operators
SteveWilkes Jan 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<Reference Include="AgileObjects.NetStandardPolyfills, Version=1.4.0.0, Culture=neutral, PublicKeyToken=06131ac1c008ad4e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.NetStandardPolyfills.1.4.0\lib\net40\AgileObjects.NetStandardPolyfills.dll</HintPath>
</Reference>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.0.0\lib\net40\AgileObjects.ReadableExpressions.dll</HintPath>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.1.0\lib\net40\AgileObjects.ReadableExpressions.dll</HintPath>
</Reference>
<Reference Include="AutoMapper, Version=7.0.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\AutoMapper.7.0.1\lib\net45\AutoMapper.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion AgileMapper.PerformanceTester.Net45/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AgileObjects.NetStandardPolyfills" version="1.4.0" targetFramework="net452" />
<package id="AgileObjects.ReadableExpressions" version="2.0.0" targetFramework="net452" />
<package id="AgileObjects.ReadableExpressions" version="2.1.0" targetFramework="net452" />
<package id="AutoMapper" version="7.0.1" targetFramework="net452" />
<package id="Expressmapper" version="1.9.1" targetFramework="net452" />
<package id="Mapster" version="3.2.0" targetFramework="net452" />
Expand Down
2 changes: 1 addition & 1 deletion AgileMapper.UnitTests.Common/ShouldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public static IDictionary<TKey, TValue> ShouldContainKeyAndValue<TKey, TValue>(
Asplode("Dictionary with key " + expectedKey, "No contained key");
}

value.ShouldBeSameAs(expectedValue);
value.ShouldBe(expectedValue);

return dictionary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
<Reference Include="AgileObjects.NetStandardPolyfills, Version=1.4.0.0, Culture=neutral, PublicKeyToken=06131ac1c008ad4e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.NetStandardPolyfills.1.4.0\lib\net35\AgileObjects.NetStandardPolyfills.dll</HintPath>
</Reference>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.0.0\lib\net35\AgileObjects.ReadableExpressions.dll</HintPath>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.1.0\lib\net35\AgileObjects.ReadableExpressions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Dynamic, Version=1.1.2.22, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<HintPath>..\packages\DynamicLanguageRuntime.1.1.2\lib\Net35\Microsoft.Dynamic.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion AgileMapper.UnitTests.Net35/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AgileObjects.NetStandardPolyfills" version="1.4.0" targetFramework="net35" />
<package id="AgileObjects.ReadableExpressions" version="2.0.0" targetFramework="net35" />
<package id="AgileObjects.ReadableExpressions" version="2.1.0" targetFramework="net35" />
<package id="DynamicLanguageRuntime" version="1.1.2" targetFramework="net35" />
<package id="NUnit" version="3.6.1" targetFramework="net35" />
<package id="NUnit3TestAdapter" version="3.10.0" targetFramework="net35" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<Reference Include="AgileObjects.NetStandardPolyfills, Version=1.4.0.0, Culture=neutral, PublicKeyToken=06131ac1c008ad4e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.NetStandardPolyfills.1.4.0\lib\net40\AgileObjects.NetStandardPolyfills.dll</HintPath>
</Reference>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.0.0\lib\net40\AgileObjects.ReadableExpressions.dll</HintPath>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.1.0\lib\net40\AgileObjects.ReadableExpressions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down Expand Up @@ -75,6 +75,7 @@
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="Configuration\Inline\WhenConfiguringDataSourcesInline.cs" />
<Compile Include="Configuration\Inline\WhenConfiguringDerivedTypesInline.cs" />
<Compile Include="Configuration\WhenApplyingMapperConfigurations.cs" />
<Compile Include="Configuration\WhenApplyingMapperConfigurationsIncorrectly.cs" />
<Compile Include="Configuration\WhenConfiguringDataSources.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace AgileObjects.AgileMapper.UnitTests.NonParallel.Configuration.Inline
{
using Common;
using MoreTestClasses;
using NetStandardPolyfills;
using TestClasses;
using Xunit;

public class WhenConfiguringDerivedTypesInline : NonParallelTestsBase
{
[Fact]
public void ShouldScanConfiguredAssembliesInline()
{
TestThenReset(() =>
{
var result = Mapper
.Map(new { NumberOfLegs = 100, SlitherNoise = "ththtth" })
.Over(new Earthworm() as AnimalBase, cgf => cgf
.LookForDerivedTypesIn(typeof(Dog).GetAssembly(), typeof(Earthworm).GetAssembly()));

result.NumberOfLegs.ShouldBe(100);
((Earthworm)result).SlitherNoise.ShouldBe("ththtth");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
{
using Common;
using MoreTestClasses;
using NetStandardPolyfills;
using TestClasses;
using Xunit;

public class WhenConfiguringDerivedTypes : NonParallelTestsBase
{
[Fact]
public void ShouldScanConfiguredAssemblies()
public void ShouldScanConfiguredAssembliesViaTheStaticApi()
{
TestThenReset(() =>
{
Expand All @@ -30,5 +31,57 @@ public void ShouldScanConfiguredAssemblies()
((Earthworm)wormResult).SlitherNoise.ShouldBe("sssSSS");
});
}

[Fact]
public void ShouldScanConfiguredAssembliesViaTheInstanceApi()
{
TestThenReset(() =>
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.LookForDerivedTypesIn(typeof(Dog).GetAssembly(), typeof(Earthworm).GetAssembly());

var result = mapper
.Map(new { NumberOfLegs = 1000, SlitherNoise = "thththtth" })
.Over(new Earthworm() as AnimalBase);

result.NumberOfLegs.ShouldBe(1000);
((Earthworm)result).SlitherNoise.ShouldBe("thththtth");
}
});
}

[Fact]
public void ShouldSetAssembliesToScanGlobally()
{
TestThenReset(() =>
{
using (var mapper1 = Mapper.CreateNew())
using (var mapper2 = Mapper.CreateNew())
{
// Set assembly scanning on mapper1...
mapper1.WhenMapping
.LookForDerivedTypesIn(typeof(Dog).GetAssembly(), typeof(Earthworm).GetAssembly());

// ...use mapper2 to cache the assembly scan results...
var result1 = mapper2
.Map(new { NumberOfLegs = 4, WoofSound = "AWESOME" })
.OnTo(new Dog() as AnimalBase);

result1.NumberOfLegs.ShouldBe(4);
((Dog)result1).WoofSound.ShouldBe("AWESOME");

// ...use mapper1 with a type outside the base type's assembly;
// assemblies are cached globally, so the scan settings should be too:
var result2 = mapper1
.Map(new { NumberOfLegs = 100, SlitherNoise = "SLITHERRR" })
.OnTo(new Earthworm() as AnimalBase);

result2.NumberOfLegs.ShouldBe(100);
((Earthworm)result2).SlitherNoise.ShouldBe("SLITHERRR");
}
});
}
}
}
2 changes: 1 addition & 1 deletion AgileMapper.UnitTests.NonParallel/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AgileObjects.NetStandardPolyfills" version="1.4.0" targetFramework="net461" />
<package id="AgileObjects.ReadableExpressions" version="2.0.0" targetFramework="net461" />
<package id="AgileObjects.ReadableExpressions" version="2.1.0" targetFramework="net461" />
<package id="xunit" version="2.4.1" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
Expand Down
4 changes: 2 additions & 2 deletions AgileMapper.UnitTests/AgileMapper.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
<Reference Include="AgileObjects.NetStandardPolyfills, Version=1.4.0.0, Culture=neutral, PublicKeyToken=06131ac1c008ad4e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.NetStandardPolyfills.1.4.0\lib\net40\AgileObjects.NetStandardPolyfills.dll</HintPath>
</Reference>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.0.0\lib\net40\AgileObjects.ReadableExpressions.dll</HintPath>
<Reference Include="AgileObjects.ReadableExpressions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=9f54ad81db69da8e, processorArchitecture=MSIL">
<HintPath>..\packages\AgileObjects.ReadableExpressions.2.1.0\lib\net40\AgileObjects.ReadableExpressions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Primitives, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Primitives.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void ShouldErrorIfUnconvertibleConstantSpecifiedInline()
}
});

inlineConfigEx.Message.ShouldContain("Unable to convert configured decimal? ");
inlineConfigEx.Message.ShouldContain("Unable to convert configured 'decimal?' ");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
{
using System.Linq;
using Common;
using MoreTestClasses;
using NetStandardPolyfills;
using TestClasses;
#if !NET35
using Xunit;
Expand Down Expand Up @@ -112,20 +110,5 @@ public void ShouldMapACustomTypePairInACollectionInline()
mapper.InlineContexts().Count.ShouldBe(2);
}
}

[Fact]
public void ShouldScanConfiguredAssembliesInline()
{
using (var mapper = Mapper.CreateNew())
{
var result = mapper
.Map(new { NumberOfLegs = 100, SlitherNoise = "ththtth" })
.Over(new Earthworm() as AnimalBase, cgf => cgf
.LookForDerivedTypesIn(typeof(Dog).GetAssembly(), typeof(Earthworm).GetAssembly()));

result.NumberOfLegs.ShouldBe(100);
((Earthworm)result).SlitherNoise.ShouldBe("ththtth");
}
}
}
}
142 changes: 142 additions & 0 deletions AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,92 @@ public void ShouldApplyMultipleConfiguredMembersBySourceType()
}
}

// See https://github.com/agileobjects/AgileMapper/issues/111
[Fact]
public void ShouldConditionallyApplyAToTargetConfiguredSimpleTypeConstant()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<string>().ToANew<string>()
.If(ctx => string.IsNullOrEmpty(ctx.Source))
.Map(default(string)).ToTarget();

var source = new Address { Line1 = "Here", Line2 = string.Empty };
var result = mapper.Map(source).ToANew<Address>();

result.Line1.ShouldBe("Here");
result.Line2.ShouldBeNull();
}
}

[Fact]
public void ShouldApplyAToTargetConfiguredSimpleTypeConstant()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<string>().ToANew<string>()
.Map((s, t) => string.IsNullOrEmpty(s) ? null : s).ToTarget();

var source = new Address { Line1 = "There", Line2 = string.Empty };
var result = mapper.Map(source).ToANew<Address>();

result.Line1.ShouldBe("There");
result.Line2.ShouldBeNull();
}
}

[Fact]
public void ShouldConditionallyApplyAToTargetConfiguredNestedSimpleTypeExpression()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<int>().ToANew<int>()
.If(ctx => ctx.Source % 2 == 0)
.Map(ctx => ctx.Source * 2).ToTarget();

var nonMatchingSource = new { ValueValue = 3 };
var nonMatchingResult = mapper.Map(nonMatchingSource).ToANew<PublicField<PublicField<int>>>();

nonMatchingResult.Value.ShouldNotBeNull();
nonMatchingResult.Value.Value.ShouldBe(3);

var matchingSource = new { ValueValue = 4 };
var matchingResult = mapper.Map(matchingSource).ToANew<PublicField<PublicField<int>>>();

matchingResult.Value.ShouldNotBeNull();
matchingResult.Value.Value.ShouldBe(8);
}
}

[Fact]
public void ShouldConditionallyApplyAToTargetConfiguredSimpleTypeExpressionInAComplexTypeList()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<int>().ToANew<int>()
.If((s, t) => s % 2 == 0)
.Map(ctx => ctx.Source * 2).ToTarget();

var source = new PublicField<List<PublicField<int>>>
{
Value = new List<PublicField<int>>
{
new PublicField<int> { Value = 1 },
new PublicField<int> { Value = 2 },
new PublicField<int> { Value = 3 }
}
};
var result = mapper.Map(source).ToANew<PublicField<List<PublicField<int>>>>();

result.Value.ShouldNotBeNull();
result.Value.ShouldBe(pf => pf.Value, 1, 4, 3);
}
}

[Fact]
public void ShouldConditionallyApplyAConfiguredMember()
{
Expand Down Expand Up @@ -740,6 +826,62 @@ public void ShouldApplyAConfiguredComplexTypeEnumerableConditionally()
}
}

// See https://github.com/agileobjects/AgileMapper/issues/113
[Fact]
public void ShouldApplyAConfiguredComplexToSimpleTypeEnumerableProjection()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicField<PublicField<int>[]>>()
.To<PublicField<int[]>>()
.Map(
pfpfi => pfpfi.Value.Select(v => v.Value),
pfi => pfi.Value);

var source = new PublicField<PublicField<int>[]>
{
Value = new[]
{
new PublicField<int> { Value = 1 },
new PublicField<int> { Value = 2 },
new PublicField<int> { Value = 3 }
}
};

var result = mapper.Map(source).ToANew<PublicField<int[]>>();

result.Value.ShouldNotBeEmpty();
result.Value.ShouldBe(1, 2, 3);
}
}

// See https://github.com/agileobjects/AgileMapper/issues/113
[Fact]
public void ShouldApplyAConfiguredComplexToSimpleTypeEnumerableProjectionToTheRootTarget()
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicField<int>[]>()
.To<int[]>()
.Map(ctx => ctx.Source.Select(v => v.Value))
.ToTarget();

var source = new[]
{
new PublicField<int> { Value = 1 },
new PublicField<int> { Value = 2 },
new PublicField<int> { Value = 3 }
};

var result = mapper.Map(source).ToANew<int[]>();

result.ShouldNotBeEmpty();
result.ShouldBe(1, 2, 3);
}
}

[Fact]
public void ShouldApplyAConfiguredSourceAndTargetFunction()
{
Expand Down
Loading