Skip to content

Commit a0ee13d

Browse files
authored
Releases/1.3 preview (#128)
* Fixing mapping of derived Collection<T> types / Improving uncommon collection support * Updating to v.1.3-preview / Adding NuGet package * Automatically mapping complex type members to null if the only populated member is an identifier, and it isn't given a non-default value. Fixes #121. * Bugs/issue123 (#124) * Issue #123: Support for using DerivedTypePair configuration to specify types for target interface members * Improving detection of join entities / Tidying * Using Expression -> source member conversion to get child Members of configured source members / Allowing for configured, derived to-interface mapping * Setting ObjectMappingData.DeclaredTypeMappingData when creating a new mapping data for a ToTarget() mapping * Preventing configured member matching reaching up past an entry point * Using MapperData.OriginalMapperData to store original ToTarget() mapper datas and find entry point candidates * Features/typed to target (#126) * Adding typed .ToTarget() method to allow single-configuration setup of derived type pairing and to-target data source * Erroring if unconstructable derived type specified in pairing * Updating ToTarget documentation * Updating release notes * Updating to v1.3-preview2 and adding NuGet package * Adding .AndWhenMapping configuration reset option to MappingConfigContinuation / Support for configuring data sources for ToTarget members * Bugs/issue125 (#127) * Adding test coverage for nested runtime-typed members, re: #125 * Tidying * Using existing ObjectMapperData for repeated mapping runtime-Typed child mapping * Adding simple type short-circuits to MapChild calls * Short-circuiting simple-Type -> object mappings / Removing SimpleTypeMappingExpressionFactory as all simple target-Type mapping scenarios now handled in-mapper * Organising projects into folders * Updating to v1.3 * Adding v1.3 NuGet package
1 parent 18098f0 commit a0ee13d

File tree

61 files changed

+1341
-350
lines changed

Some content is hidden

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

61 files changed

+1341
-350
lines changed

AgileMapper.UnitTests/Configuration/WhenConfiguringDataSources.cs

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,28 @@ public void ShouldApplyAConfiguredExpressionInAMemberEnumerable()
500500
}
501501
}
502502

503+
[Fact]
504+
public void ShouldApplyAConfiguredExpressionToAnArray()
505+
{
506+
using (var mapper = Mapper.CreateNew())
507+
{
508+
mapper.WhenMapping
509+
.From<PublicProperty<string>>()
510+
.To<PublicField<int[]>>()
511+
#if NETCOREAPP2_0
512+
.Map(ctx => ctx.Source.Value.Split(':', System.StringSplitOptions.None))
513+
#else
514+
.Map(ctx => ctx.Source.Value.Split(':'))
515+
#endif
516+
.To(x => x.Value);
517+
518+
var source = new PublicProperty<string> { Value = "8:7:6:5" };
519+
var result = mapper.Map(source).ToANew<PublicField<int[]>>();
520+
521+
result.Value.ShouldBe(8, 7, 6, 5);
522+
}
523+
}
524+
503525
[Fact]
504526
public void ShouldApplyAConfiguredExpressionInAMemberNonGenericEnumerableConditionally()
505527
{
@@ -1443,6 +1465,86 @@ public void ShouldApplyMultipleConfiguredEnumerableRootSources()
14431465
}
14441466
}
14451467

1468+
// See https://github.com/agileobjects/AgileMapper/issues/125
1469+
[Fact]
1470+
public void ShouldHandleDeepNestedRuntimeTypedMembersWithACachedMappingPlan()
1471+
{
1472+
using (var mapper = Mapper.CreateNew())
1473+
{
1474+
mapper.WhenMapping
1475+
.From<Issue125.Source.ParamSet>().To<Issue125.Target.ParamSet>()
1476+
.Map(ctxt => ctxt.Source.ParamObj)
1477+
.ToCtor<Issue125.Target.ParamObj>()
1478+
.And.Ignore(t => t.ParamObj);
1479+
1480+
// Bug only happens when the mapping plan is cached up-front
1481+
mapper
1482+
.GetPlanFor<Issue125.Source.ParamSet>()
1483+
.ToANew<Issue125.Target.ParamSet>();
1484+
1485+
var source = new Issue125.Source.ParamSet
1486+
{
1487+
ParamObj = new Issue125.Source.ParamObj
1488+
{
1489+
Name = "Test PO",
1490+
Collection = new Issue125.Source.ParamCol
1491+
{
1492+
Children =
1493+
{
1494+
new Issue125.Source.ParamValue
1495+
{
1496+
Definition = Issue125.Source.ParamDef.Create(),
1497+
Values = { 1, 2, 3, 4, 5, 6 }
1498+
}
1499+
}
1500+
}
1501+
},
1502+
ParamValues =
1503+
{
1504+
new Issue125.Source.ParamValue
1505+
{
1506+
Definition = Issue125.Source.ParamDef.Create(),
1507+
Values = { 2, 4, 6, 8, 10, 12 }
1508+
}
1509+
}
1510+
};
1511+
1512+
var result = source.MapUsing(mapper).ToANew<Issue125.Target.ParamSet>();
1513+
1514+
result.ShouldNotBeNull();
1515+
1516+
result.ParamObj.ShouldNotBeNull();
1517+
result.ParamObj.Name.ShouldBe("Test PO");
1518+
result.ParamObj.Collection.ShouldNotBeNull();
1519+
1520+
result.ParamObj.Collection.ParamObj.ShouldBeNull();
1521+
result.ParamObj.Collection.Children.ShouldNotBeNull();
1522+
result.ParamObj.Collection.Children.ShouldHaveSingleItem();
1523+
result.ParamObj.Collection.Children.First().Definition.ShouldNotBeNull();
1524+
result.ParamObj.Collection.Children.First().Definition.Identification.ShouldBe("Test ParamDef");
1525+
result.ParamObj.Collection.Children.First().Definition.Default.ShouldBe(42);
1526+
result.ParamObj.Collection.Children.First().Definition.Min.ShouldBe(0);
1527+
result.ParamObj.Collection.Children.First().Definition.Max.ShouldBe(100);
1528+
result.ParamObj.Collection.Children.First().Definition.Type.ShouldBe("Integer");
1529+
result.ParamObj.Collection.Children.First().Values.ShouldNotBeNull();
1530+
result.ParamObj.Collection.Children.First().Values.ShouldBe(1, 2, 3, 4, 5, 6);
1531+
1532+
result.ParamValues.ShouldNotBeNull();
1533+
result.ParamValues.ShouldHaveSingleItem();
1534+
result.ParamValues.First().Definition.ShouldNotBeNull();
1535+
result.ParamValues.First().Definition.Identification.ShouldBe("Test ParamDef");
1536+
result.ParamValues.First().Definition.Default.ShouldBe(42);
1537+
result.ParamValues.First().Definition.Min.ShouldBe(0);
1538+
result.ParamValues.First().Definition.Max.ShouldBe(100);
1539+
result.ParamValues.First().Definition.Type.ShouldBe("Integer");
1540+
result.ParamValues.First().Values.ShouldNotBeNull();
1541+
result.ParamValues.First().Values.ShouldBe(2, 4, 6, 8, 10, 12);
1542+
1543+
result.ParamObj.Collection.Children.First().Definition.ShouldNotBeSameAs(
1544+
result.ParamValues.First().Definition);
1545+
}
1546+
}
1547+
14461548
internal class IdTester
14471549
{
14481550
public int ClassId { get; set; }
@@ -1472,5 +1574,149 @@ internal class ModelDto
14721574

14731575
public string SomeOtherRankingStuff { get; set; }
14741576
}
1577+
1578+
// ReSharper disable CollectionNeverQueried.Local
1579+
// ReSharper disable MemberCanBePrivate.Local
1580+
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
1581+
internal static class Issue125
1582+
{
1583+
// ReSharper disable UnusedAutoPropertyAccessor.Local
1584+
public static class Source
1585+
{
1586+
public class ParamSet
1587+
{
1588+
public ParamSet()
1589+
{
1590+
ParamValues = new List<ParamValue>();
1591+
}
1592+
1593+
public ParamObj ParamObj { get; set; }
1594+
1595+
public IList<ParamValue> ParamValues { get; }
1596+
}
1597+
1598+
public class ParamObj
1599+
{
1600+
public string Name { get; set; }
1601+
1602+
public ParamCol Collection { get; set; }
1603+
}
1604+
1605+
public class ParamCol
1606+
{
1607+
public ParamCol()
1608+
{
1609+
Children = new List<ParamValue>();
1610+
}
1611+
1612+
public IList<ParamValue> Children { get; }
1613+
}
1614+
1615+
public class ParamValue
1616+
{
1617+
public ParamValue()
1618+
{
1619+
Values = new List<object>();
1620+
}
1621+
1622+
public ParamDef Definition { get; set; }
1623+
1624+
public IList<object> Values { get; }
1625+
}
1626+
1627+
public class ParamDef
1628+
{
1629+
public static ParamDef Create()
1630+
{
1631+
return new ParamDef
1632+
{
1633+
Identification = "Test ParamDef",
1634+
Default = 42,
1635+
Min = 0,
1636+
Max = 100,
1637+
Type = "Integer"
1638+
};
1639+
}
1640+
1641+
public object Default { get; set; }
1642+
1643+
public object Min { get; set; }
1644+
1645+
public object Max { get; set; }
1646+
1647+
public string Type { get; set; }
1648+
1649+
public string Identification { get; set; }
1650+
}
1651+
}
1652+
// ReSharper restore UnusedAutoPropertyAccessor.Local
1653+
1654+
// ReSharper disable ClassNeverInstantiated.Local
1655+
// ReSharper disable UnusedAutoPropertyAccessor.Local
1656+
public static class Target
1657+
{
1658+
public class ParamSet
1659+
{
1660+
public ParamSet(ParamObj po)
1661+
{
1662+
ParamObj = po;
1663+
ParamValues = new List<ParamValue>();
1664+
}
1665+
1666+
public ParamObj ParamObj { get; set; }
1667+
1668+
public IList<ParamValue> ParamValues { get; }
1669+
}
1670+
1671+
public class ParamObj
1672+
{
1673+
public string Name { get; set; }
1674+
1675+
public ParamCol Collection { get; set; }
1676+
}
1677+
1678+
public class ParamCol
1679+
{
1680+
public ParamCol()
1681+
{
1682+
Children = new List<ParamValue>();
1683+
}
1684+
1685+
public ParamObj ParamObj { get; set; }
1686+
1687+
public IList<ParamValue> Children { get; }
1688+
}
1689+
1690+
public class ParamValue
1691+
{
1692+
public ParamValue()
1693+
{
1694+
Values = new List<object>();
1695+
}
1696+
1697+
public ParamDef Definition { get; set; }
1698+
1699+
public IList<object> Values { get; }
1700+
}
1701+
1702+
public class ParamDef
1703+
{
1704+
public object Default { get; set; }
1705+
1706+
public object Min { get; set; }
1707+
1708+
public object Max { get; set; }
1709+
1710+
public string Type { get; set; }
1711+
1712+
public string Identification { get; set; }
1713+
}
1714+
}
1715+
// ReSharper restore UnusedAutoPropertyAccessor.Local
1716+
// ReSharper restore ClassNeverInstantiated.Local
1717+
}
1718+
// ReSharper restore AutoPropertyCanBeMadeGetOnly.Local
1719+
// ReSharper restore MemberCanBePrivate.Local
1720+
// ReSharper restore CollectionNeverQueried.Local
14751721
}
14761722
}

0 commit comments

Comments
 (0)