Skip to content

Commit 75da4a3

Browse files
committed
Support for configuring assemblies to scan when looking for derived types
1 parent 88e42da commit 75da4a3

File tree

12 files changed

+217
-2
lines changed

12 files changed

+217
-2
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{049E1EE5-48CE-441A-B166-3CF6BEC17957}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>AgileObjects.AgileMapper.UnitTests.MoreTestClasses</RootNamespace>
11+
<AssemblyName>AgileObjects.AgileMapper.UnitTests.MoreTestClasses</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<PublishUrl>publish\</PublishUrl>
15+
<Install>true</Install>
16+
<InstallFrom>Disk</InstallFrom>
17+
<UpdateEnabled>false</UpdateEnabled>
18+
<UpdateMode>Foreground</UpdateMode>
19+
<UpdateInterval>7</UpdateInterval>
20+
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
21+
<UpdatePeriodically>false</UpdatePeriodically>
22+
<UpdateRequired>false</UpdateRequired>
23+
<MapFileExtensions>true</MapFileExtensions>
24+
<ApplicationRevision>0</ApplicationRevision>
25+
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
26+
<IsWebBootstrapper>false</IsWebBootstrapper>
27+
<UseApplicationTrust>false</UseApplicationTrust>
28+
<BootstrapperEnabled>true</BootstrapperEnabled>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
31+
<DebugSymbols>true</DebugSymbols>
32+
<DebugType>full</DebugType>
33+
<Optimize>false</Optimize>
34+
<OutputPath>bin\Debug\</OutputPath>
35+
<DefineConstants>DEBUG;TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
40+
<DebugType>pdbonly</DebugType>
41+
<Optimize>true</Optimize>
42+
<OutputPath>bin\Release\</OutputPath>
43+
<DefineConstants>TRACE</DefineConstants>
44+
<ErrorReport>prompt</ErrorReport>
45+
<WarningLevel>4</WarningLevel>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Reference Include="System" />
49+
<Reference Include="System.Core" />
50+
<Reference Include="System.Xml.Linq" />
51+
<Reference Include="System.Data.DataSetExtensions" />
52+
<Reference Include="Microsoft.CSharp" />
53+
<Reference Include="System.Data" />
54+
<Reference Include="System.Xml" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Compile Include="..\CommonAssemblyInfo.cs">
58+
<Link>Properties\CommonAssemblyInfo.cs</Link>
59+
</Compile>
60+
<Compile Include="..\VersionInfo.cs">
61+
<Link>Properties\VersionInfo.cs</Link>
62+
</Compile>
63+
<Compile Include="AnimalBase.cs" />
64+
<Compile Include="Dog.cs" />
65+
<Compile Include="Properties\AssemblyInfo.cs" />
66+
</ItemGroup>
67+
<ItemGroup>
68+
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
69+
<Visible>False</Visible>
70+
<ProductName>.NET Framework 3.5 SP1</ProductName>
71+
<Install>false</Install>
72+
</BootstrapperPackage>
73+
</ItemGroup>
74+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
75+
</Project>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AgileObjects.AgileMapper.UnitTests.MoreTestClasses
2+
{
3+
public abstract class AnimalBase
4+
{
5+
public int NumberOfLegs { get; set; }
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace AgileObjects.AgileMapper.UnitTests.MoreTestClasses
2+
{
3+
public class Dog : AnimalBase
4+
{
5+
public string WoofSound { get; set; }
6+
}
7+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("AgileObjects.AgileMapper.UnitTests.MoreTestClasses")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyTrademark("")]
11+
[assembly: AssemblyCulture("")]
12+
13+
// Setting ComVisible to false makes the types in this assembly not visible
14+
// to COM components. If you need to access a type in this assembly from
15+
// COM, set the ComVisible attribute to true on that type.
16+
[assembly: ComVisible(false)]
17+
18+
// The following GUID is for the ID of the typelib if this project is exposed to COM
19+
[assembly: Guid("049e1ee5-48ce-441a-b166-3cf6bec17957")]

AgileMapper.UnitTests.NonParallel/AgileMapper.UnitTests.NonParallel.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<Link>VersionInfo.cs</Link>
6868
</Compile>
6969
<Compile Include="Configuration\WhenConfiguringDataSources.cs" />
70+
<Compile Include="Configuration\WhenConfiguringDerivedTypes.cs" />
7071
<Compile Include="Configuration\WhenConfiguringMappingCallbacks.cs" />
7172
<Compile Include="NonParallelTestsBase.cs" />
7273
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -80,6 +81,10 @@
8081
<Project>{4e101600-ebef-4e1f-9ec3-d6070f7417dd}</Project>
8182
<Name>AgileMapper.Net40</Name>
8283
</ProjectReference>
84+
<ProjectReference Include="..\AgileMapper.UnitTests.MoreTestClasses\AgileMapper.UnitTests.MoreTestClasses.csproj">
85+
<Project>{049e1ee5-48ce-441a-b166-3cf6bec17957}</Project>
86+
<Name>AgileMapper.UnitTests.MoreTestClasses</Name>
87+
</ProjectReference>
8388
<ProjectReference Include="..\AgileMapper.UnitTests\AgileMapper.UnitTests.csproj">
8489
<Project>{a3f2d405-8c0b-4033-9ec5-1b64007593fb}</Project>
8590
<Name>AgileMapper.UnitTests</Name>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace AgileObjects.AgileMapper.UnitTests.NonParallel.Configuration
2+
{
3+
using MoreTestClasses;
4+
using TestClasses;
5+
using Xunit;
6+
7+
public class WhenConfiguringDerivedTypes : NonParallelTestsBase
8+
{
9+
[Fact]
10+
public void ShouldScanConfiguredAssemblies()
11+
{
12+
TestThenReset(() =>
13+
{
14+
Mapper.WhenMapping
15+
.LookForDerivedTypesIn(typeof(Dog).Assembly, typeof(Earthworm).Assembly);
16+
17+
var dogResult = Mapper
18+
.Map(new { NumberOfLegs = 4, WoofSound = "Bark!" })
19+
.OnTo(new Dog() as AnimalBase);
20+
21+
dogResult.NumberOfLegs.ShouldBe(4);
22+
((Dog)dogResult).WoofSound.ShouldBe("Bark!");
23+
24+
var wormResult = Mapper
25+
.Map(new { NumberOfLegs = 0, SlitherNoise = "sssSSS" })
26+
.Over(new Earthworm() as AnimalBase);
27+
28+
wormResult.NumberOfLegs.ShouldBe(0);
29+
((Earthworm)wormResult).SlitherNoise.ShouldBe("sssSSS");
30+
});
31+
}
32+
}
33+
}

AgileMapper.UnitTests/AgileMapper.UnitTests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Compile Include="Dictionaries\Configuration\WhenConfiguringNestedDictionaryMapping.cs" />
8080
<Compile Include="Dictionaries\Configuration\WhenConfiguringTargetDictionaryMapping.cs" />
8181
<Compile Include="Dictionaries\WhenCreatingRootDictionaryMembers.cs" />
82+
<Compile Include="TestClasses\Earthworm.cs" />
8283
<Compile Include="TestClasses\IPublicInterface.cs" />
8384
<Compile Include="TestClasses\MegaProduct.cs" />
8485
<Compile Include="TestClasses\ProductDto.cs" />
@@ -196,6 +197,10 @@
196197
<Project>{4e101600-ebef-4e1f-9ec3-d6070f7417dd}</Project>
197198
<Name>AgileMapper.Net40</Name>
198199
</ProjectReference>
200+
<ProjectReference Include="..\AgileMapper.UnitTests.MoreTestClasses\AgileMapper.UnitTests.MoreTestClasses.csproj">
201+
<Project>{049e1ee5-48ce-441a-b166-3cf6bec17957}</Project>
202+
<Name>AgileMapper.UnitTests.MoreTestClasses</Name>
203+
</ProjectReference>
199204
</ItemGroup>
200205
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
201206
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

AgileMapper.UnitTests/Configuration/WhenConfiguringDerivedTypes.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
namespace AgileObjects.AgileMapper.UnitTests.Configuration
22
{
33
using AgileMapper.Configuration;
4+
using MoreTestClasses;
45
using Shouldly;
56
using TestClasses;
67
using Xunit;
78

89
public class WhenConfiguringDerivedTypes
910
{
11+
[Fact]
12+
public void ShouldScanConfiguredAssemblies()
13+
{
14+
using (var mapper = Mapper.CreateNew())
15+
{
16+
mapper.WhenMapping
17+
.LookForDerivedTypesIn(typeof(Dog).Assembly, typeof(Earthworm).Assembly);
18+
19+
var result = mapper
20+
.Map(new { NumberOfLegs = 1000, SlitherNoise = "thththtth" })
21+
.Over(new Earthworm() as AnimalBase);
22+
23+
result.NumberOfLegs.ShouldBe(1000);
24+
((Earthworm)result).SlitherNoise.ShouldBe("thththtth");
25+
}
26+
}
27+
1028
[Fact]
1129
public void ShouldMapACustomTypePair()
1230
{
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AgileObjects.AgileMapper.UnitTests.TestClasses
2+
{
3+
using MoreTestClasses;
4+
5+
public class Earthworm : AnimalBase
6+
{
7+
public string SlitherNoise { get; set; }
8+
}
9+
}

AgileMapper.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26228.4
4+
VisualStudioVersion = 15.0.26403.7
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{05AB6D17-6066-41D5-8E79-31C342DFC2DC}"
77
ProjectSection(SolutionItems) = preProject
@@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AgileMapper.UnitTests.Polyf
2424
EndProject
2525
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AgileMapper", "AgileMapper\AgileMapper.csproj", "{46D95C53-B4CB-4EE7-9573-5D3EF96099C0}"
2626
EndProject
27+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AgileMapper.UnitTests.MoreTestClasses", "AgileMapper.UnitTests.MoreTestClasses\AgileMapper.UnitTests.MoreTestClasses.csproj", "{049E1EE5-48CE-441A-B166-3CF6BEC17957}"
28+
EndProject
2729
Global
2830
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2931
Debug|Any CPU = Debug|Any CPU
@@ -54,6 +56,10 @@ Global
5456
{46D95C53-B4CB-4EE7-9573-5D3EF96099C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
5557
{46D95C53-B4CB-4EE7-9573-5D3EF96099C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
5658
{46D95C53-B4CB-4EE7-9573-5D3EF96099C0}.Release|Any CPU.Build.0 = Release|Any CPU
59+
{049E1EE5-48CE-441A-B166-3CF6BEC17957}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
60+
{049E1EE5-48CE-441A-B166-3CF6BEC17957}.Debug|Any CPU.Build.0 = Debug|Any CPU
61+
{049E1EE5-48CE-441A-B166-3CF6BEC17957}.Release|Any CPU.ActiveCfg = Release|Any CPU
62+
{049E1EE5-48CE-441A-B166-3CF6BEC17957}.Release|Any CPU.Build.0 = Release|Any CPU
5763
EndGlobalSection
5864
GlobalSection(SolutionProperties) = preSolution
5965
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)