Skip to content

Commit

Permalink
Merge branch 'Development' of https://github.com/expressmapper/Expres…
Browse files Browse the repository at this point in the history
…sMapper into Development
  • Loading branch information
anisimovyuriy committed Jun 29, 2015
2 parents 7a96a69 + 6866c15 commit fef30b5
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 235 deletions.
19 changes: 19 additions & 0 deletions ExpressMapper NET40/DelegateCustomTypeMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;

namespace ExpressMapper
{
internal class DelegateCustomTypeMapper<T, TN> : ICustomTypeMapper<T, TN>
{
private readonly Func<T, TN> _mapFunc;

public DelegateCustomTypeMapper(Func<T, TN> mapFunc)
{
_mapFunc = mapFunc;
}

public TN Map(IMappingContext<T, TN> context)
{
return _mapFunc(context.Source);
}
}
}
1 change: 1 addition & 0 deletions ExpressMapper NET40/ExpressMapper NET40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="CollectionTypes.cs" />
<Compile Include="Constants.cs" />
<Compile Include="DefaultMappingContext.cs" />
<Compile Include="DelegateCustomTypeMapper.cs" />
<Compile Include="IMappingContext.cs" />
<Compile Include="IMappingService.cs" />
<Compile Include="Ioc\DependencyResolver.cs" />
Expand Down
224 changes: 53 additions & 171 deletions ExpressMapper NET40/MappingService.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions ExpressMapper NET40/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.2.0")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
3 changes: 3 additions & 0 deletions ExpressMapper NET45/ExpressMapper NET45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Compile Include="..\ExpressMapper NET40\DefaultMappingContext.cs">
<Link>DefaultMappingContext.cs</Link>
</Compile>
<Compile Include="..\ExpressMapper NET40\DelegateCustomTypeMapper.cs">
<Link>DelegateCustomTypeMapper.cs</Link>
</Compile>
<Compile Include="..\ExpressMapper NET40\ICustomTypeMapper.cs">
<Link>ICustomTypeMapper.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions ExpressMapper NET451/ExpressMapper NET451.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<Compile Include="..\ExpressMapper NET40\DefaultMappingContext.cs">
<Link>DefaultMappingContext.cs</Link>
</Compile>
<Compile Include="..\ExpressMapper NET40\DelegateCustomTypeMapper.cs">
<Link>DelegateCustomTypeMapper.cs</Link>
</Compile>
<Compile Include="..\ExpressMapper NET40\ICustomTypeMapper.cs">
<Link>ICustomTypeMapper.cs</Link>
</Compile>
Expand Down
66 changes: 34 additions & 32 deletions ExpressMapper.Tests NET40/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,38 +517,40 @@ public void ExistingDestCollEquals()
}
}

//[Test]
//public void ExistingDestCollEqualsWithNullElement()
//{
// Mapper.Register<TestCollection, TestCollectionViewModel>();
// Mapper.Register<TestItem, TestItemViewModel>()
// .Member(dest => dest.Array, src => src.Queryable)
// .Ignore(dest => dest.Queryable);

// Mapper.Compile();
// var testResult = Functional.ExistingDestCollEqualsWithNullElement();

// var testItemHash = testResult.Value.GetHashCode();
// var arrayHash = testResult.Value.Array.GetHashCode();
// var testArr = new List<int>(testResult.Value.Array.Length);
// testArr.AddRange(testResult.Value.Array.Select(tc => tc.GetHashCode()));


// var result = Mapper.Map(testResult.Key, testResult.Value);
// Assert.AreEqual(result, testResult.Value);
// Assert.AreEqual(result.GetHashCode(), testItemHash);
// Assert.AreEqual(result.Array.GetHashCode(), arrayHash);

// for (var i = 0; i < result.Array.Length; i++)
// {
// if (i == 3)
// {
// Assert.AreNotEqual(result.Array[i], null);
// Assert.AreNotEqual(result.Array[i].GetHashCode(), testArr[i]);
// }
// Assert.AreEqual(result.Array[i].GetHashCode(), testArr[i]);
// }
//}
[Test]
public void ExistingDestCollEqualsWithNullElement()
{
Mapper.Register<TestCollection, TestCollectionViewModel>();
Mapper.Register<TestItem, TestItemViewModel>()
.Member(dest => dest.Array, src => src.Queryable)
.Ignore(dest => dest.Queryable);

Mapper.Compile();
var testResult = Functional.ExistingDestCollEqualsWithNullElement();

var testItemHash = testResult.Value.GetHashCode();
var arrayHash = testResult.Value.Array.GetHashCode();
var testArr = new List<int?>(testResult.Value.Array.Length);
testArr.AddRange(testResult.Value.Array.Select(tc => tc == null ? (int?)null : tc.GetHashCode()));

var result = Mapper.Map(testResult.Key, testResult.Value);
Assert.AreEqual(result, testResult.Value);
Assert.AreEqual(result.GetHashCode(), testItemHash);
Assert.AreEqual(result.Array.GetHashCode(), arrayHash);

for (var i = 0; i < result.Array.Length; i++)
{
if (i == 3)
{
Assert.AreEqual(null, result.Array[i]);
Assert.AreEqual(null, testArr[i]);
}
else
{
Assert.AreEqual(result.Array[i].GetHashCode(), testArr[i]);
}
}
}

[Test]
public void ExistingSrcCollGreater()
Expand Down
3 changes: 2 additions & 1 deletion ExpressMapper.Tests.Model/Models/TestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TestModel
public List<Size> Sizes { get; set; }
public DateTime Created { get; set; }
public string Gender { get; set; }
public GenderTypes? NullableGender { get; set; }
public GenderTypes? NullableGender { get; set; }
public string[] StringCollection { get; set; }
}
}
57 changes: 29 additions & 28 deletions ExpressMapper.Tests.Model/ViewModels/TestViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
using ExpressMapper.Tests.Model.Enums;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ExpressMapper.Tests.Model.ViewModels
{
public class TestViewModel : IEquatable<TestViewModel>
{
public Guid Id { get; set; }
using System.Linq;

namespace ExpressMapper.Tests.Model.ViewModels
{
public class TestViewModel : IEquatable<TestViewModel>
{
public Guid Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public int NotNullable { get; set; }
public int? Nullable { get; set; }
public int? Nullable { get; set; }
public decimal? Weight { get; set; }
public long Height { get; set; }
public bool BoolValue { get; set; }
public CountryViewModel Country { get; set; }
public bool BoolValue { get; set; }
public CountryViewModel Country { get; set; }
public List<SizeViewModel> Sizes { get; set; }
public DateTime Created { get; set; }
public GenderTypes Gender { get; set; }
public string NullableGender { get; set; }
public int GenderIndex { get; set; }
public bool Equals(TestViewModel other)
{
var sizes = true;
if (Sizes != null && other.Sizes != null)
{
if (Sizes.Count == other.Sizes.Count)
{
if (Sizes.Where((t, i) => !t.Equals(other.Sizes[i])).Any())
{
sizes = false;
}
}
public int GenderIndex { get; set; }
public List<String> StringCollection { get; set; }
public bool Equals(TestViewModel other)
{
var sizes = true;
if (Sizes != null && other.Sizes != null)
{
if (Sizes.Count == other.Sizes.Count)
{
if (Sizes.Where((t, i) => !t.Equals(other.Sizes[i])).Any())
{
sizes = false;
}
}
}

return Id == other.Id && Name == other.Name && Age == other.Age && NotNullable == other.NotNullable && Nullable.GetValueOrDefault() == other.Nullable.GetValueOrDefault() && Weight == other.Weight && BoolValue == other.BoolValue && Gender == other.Gender && NullableGender == other.NullableGender && GenderIndex == other.GenderIndex &&
Created == other.Created && ((Country == null && other.Country == null) || Country.Equals(other.Country)) && sizes;
}
}
}
return Id == other.Id && Name == other.Name && Age == other.Age && NotNullable == other.NotNullable && Nullable.GetValueOrDefault() == other.Nullable.GetValueOrDefault() && Weight == other.Weight && BoolValue == other.BoolValue && Gender == other.Gender && NullableGender == other.NullableGender && GenderIndex == other.GenderIndex &&
Created == other.Created && ((Country == null && other.Country == null) || Country.Equals(other.Country)) && sizes;
}
}
}

0 comments on commit fef30b5

Please sign in to comment.