Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -60,9 +60,6 @@
<Reference Include="Microsoft.Extensions.Caching.Memory, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Caching.Memory.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Configuration.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Configuration.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.dll</HintPath>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,48 @@ public void ShouldErrorIfDuplicateDataSourceIsConfigured()
[Fact]
public void ShouldErrorIfRedundantDataSourceIsConfigured()
{
Should.Throw<MappingConfigurationException>(() =>
var configEx = Should.Throw<MappingConfigurationException>(() =>
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicProperty<int>>()
.To<PublicField<string>>()
.Map(pp => pp.Value, pf => pf.Value);
}
});

configEx.Message.ShouldContain("PublicProperty<int>.Value");
configEx.Message.ShouldContain("PublicField<string>.Value");
configEx.Message.ShouldContain("does not need to be configured");
}

[Fact]
public void ShouldErrorIfRedundantConstructorParameterDataSourceIsConfigured()
{
var configEx = Should.Throw<MappingConfigurationException>(() =>
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicProperty<int>>()
.To<PublicCtor<string>>()
.Map(ctx => ctx.Source.Value)
.ToCtor<string>();
}
});

configEx.Message.ShouldContain("PublicProperty<int>.Value");
configEx.Message.ShouldContain("will automatically be mapped");
configEx.Message.ShouldContain("target constructor parameter");
configEx.Message.ShouldContain("PublicCtor<string>.value");
configEx.Message.ShouldContain("does not need to be configured");
}

[Fact]
public void ShouldErrorIfRedundantDerivedTypeDataSourceIsConfigured()
{
var configEx = Should.Throw<MappingConfigurationException>(() =>
{
using (var mapper = Mapper.CreateNew())
{
Expand All @@ -129,6 +170,8 @@ public void ShouldErrorIfRedundantDataSourceIsConfigured()
.To(x => x.Value);
}
});

configEx.Message.ShouldContain("already has configured data source");
}

[Fact]
Expand Down Expand Up @@ -262,6 +305,24 @@ public void ShouldErrorIfUnconvertibleConstructorValueConstantSpecified()
configurationException.Message.ShouldContain("Unable to convert");
}

[Fact]
public void ShouldErrorIfUnconvertibleConstructorSourceValueSpecified()
{
var configurationException = Should.Throw<MappingConfigurationException>(() =>
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicProperty<int>>()
.To<PublicCtor<Guid>>()
.Map(ctx => ctx.Source.Value)
.ToCtor<Guid>();
}
});

configurationException.Message.ShouldContain("Unable to convert");
}

[Fact]
public void ShouldErrorIfSimpleTypeConfiguredForComplexTarget()
{
Expand All @@ -281,6 +342,25 @@ public void ShouldErrorIfSimpleTypeConfiguredForComplexTarget()
"Person.Id of type 'Guid' cannot be mapped to target type 'Address'");
}

[Fact]
public void ShouldErrorIfSimpleTypeConfiguredForComplexConstructorParameter()
{
var configurationException = Should.Throw<MappingConfigurationException>(() =>
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicField<int>>()
.To<PublicCtor<Address>>()
.Map(ctx => ctx.Source.Value)
.ToCtor<Address>();
}
});

configurationException.Message.ShouldContain(
"PublicField<int>.Value of type 'int' cannot be mapped to target type 'Address'");
}

[Fact]
public void ShouldErrorIfSimpleTypeConfiguredForEnumerableTarget()
{
Expand All @@ -300,6 +380,25 @@ public void ShouldErrorIfSimpleTypeConfiguredForEnumerableTarget()
"PublicField<int>.Value of type 'int' cannot be mapped to target type 'int[]'");
}

[Fact]
public void ShouldErrorIfSimpleTypeConfiguredForEnumerableConstructorParameter()
{
var configurationException = Should.Throw<MappingConfigurationException>(() =>
{
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicField<string>>()
.To<PublicCtor<int[]>>()
.Map(ctx => ctx.Source.Value)
.ToCtor("value");
}
});

configurationException.Message.ShouldContain(
"PublicField<string>.Value of type 'string' cannot be mapped to target type 'int[]'");
}

[Fact]
public void ShouldErrorIfUnconvertibleEnumerableElementTypeConfigured()
{
Expand All @@ -308,9 +407,9 @@ public void ShouldErrorIfUnconvertibleEnumerableElementTypeConfigured()
using (var mapper = Mapper.CreateNew())
{
mapper.WhenMapping
.From<PublicField<PublicField<int>[]>>()
.From<PublicTwoFields<PublicField<int>[], int[]>>()
.To<PublicField<int[]>>()
.Map(s => s.Value, t => t.Value);
.Map(s => s.Value1, t => t.Value);
}
});

Expand Down
Loading