Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
Use ConvertAll for collection mapping if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Dec 6, 2018
1 parent 6a8dc71 commit a49a361
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
return new UserDTO()
{
Age = Age,
Debs = Debs.Select(thisDeb => new AccountDTO()
Debs = Debs.ConvertAll(thisDeb => new AccountDTO()
{
BankName = thisDeb.BankName,
Number = thisDeb.Number
}).ToList(),
}),
Source = new UserSourceDTO(providerName: Source.ProviderName, providerAddress: Source.ProviderAddress),
Login = Login,
ImageData = ImageData.ToArray(),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,10 @@
<data name="_021_MultiParameterPureMappingMethod_FIxed" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\021_MultiParameterPureMappingMethod_FIxed.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_022_CollectionMappingIListToList" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\022_CollectionMappingIListToList.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="_022_CollectionMappingIListToList_Fixed" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>TestCaseData\022_CollectionMappingIListToList_Fixed.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public void should_be_able_to_implement_multi_parameter_pure_method()
TestCodeRefactoring(_021_MultiParameterPureMappingMethod, _021_MultiParameterPureMappingMethod_FIxed);
}

[Test]
public void should_be_able_to_map_IList_to_List_using_linq()
{
TestCodeRefactoring(_022_CollectionMappingIListToList, _022_CollectionMappingIListToList_Fixed);
}

protected override string LanguageName => LanguageNames.CSharp;

protected override CodeRefactoringProvider CreateProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
return new UserDTO()
{
Age = entity.Age,
Debs = entity.Debs.Select(entityDeb => new AccountDTO()
Debs = entity.Debs.ConvertAll(entityDeb => new AccountDTO()
{
BankName = entityDeb.BankName,
Number = entityDeb.Number
}).ToList(),
}),
Source = new UserSourceDTO(providerName: entity.Source.ProviderName, providerAddress: entity.Source.ProviderAddress),
ImageData = entity.ImageData,
LuckyNumbers = entity.LuckyNumbers,
Expand All @@ -29,14 +29,14 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
FlatNo = entity.MainAddress.FlatNo,
BuildingNo = entity.MainAddress.BuildingNo
},
Addresses = entity.Addresses.Select(entityAddress => new AddressDTO()
Addresses = entity.Addresses.ConvertAll(entityAddress => new AddressDTO()
{
City = entityAddress.City,
ZipCode = entityAddress.ZipCode,
Street = entityAddress.Street,
FlatNo = entityAddress.FlatNo,
BuildingNo = entityAddress.BuildingNo
}).ToList().AsReadOnly(),
}).AsReadOnly(),
UnitId = entity.Unit.Id,
ExtraSavings = entity.ExtraSavings.Value
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public List<int> LuckyNumbers { get; set; }
public AddressEntity MainAddress { get; set; }
public string AddressCity { get; set; }
public List<AddressEntity> Addresses { get; set; }
public IList<AddressEntity> Addresses { get; set; }
public UnitEntity Unit { get; set; }

public int GetTotal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
return new TDto()
{
Age = entity.Age,
Debs = entity.Debs.Select(entityDeb => new AccountDTO()
Debs = entity.Debs.ConvertAll(entityDeb => new AccountDTO()
{
BankName = entityDeb.BankName,
Number = entityDeb.Number
}).ToList(),
}),
Source = new UserSourceDTO(providerName: entity.Source.ProviderName, providerAddress: entity.Source.ProviderAddress),
ImageData = entity.ImageData,
LuckyNumbers = entity.LuckyNumbers,
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public List<int> LuckyNumbers { get; set; }
public AddressEntity MainAddress { get; set; }
public string AddressCity { get; set; }
public List<AddressEntity> Addresses { get; set; }
public IList<AddressEntity> Addresses { get; set; }
public UnitEntity Unit { get; set; }

public int GetTotal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public static void Map(UserEntity src, UserDTO dst)
{
dst.Age = src.Age;
dst.Debs = src.Debs.Select(srcDeb => new AccountDTO()
dst.Debs = src.Debs.ConvertAll(srcDeb => new AccountDTO()
{
BankName = srcDeb.BankName,
Number = srcDeb.Number
}).ToList();
});
dst.Source = new UserSourceDTO(providerName: src.Source.ProviderName, providerAddress: src.Source.ProviderAddress);
dst.ImageData = src.ImageData;
dst.LuckyNumbers = src.LuckyNumbers;
Expand All @@ -27,14 +27,14 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
FlatNo = src.MainAddress.FlatNo,
BuildingNo = src.MainAddress.BuildingNo
};
dst.Addresses = src.Addresses.Select(srcAddress => new AddressDTO()
dst.Addresses = src.Addresses.ConvertAll(srcAddress => new AddressDTO()
{
City = srcAddress.City,
ZipCode = srcAddress.ZipCode,
Street = srcAddress.Street,
FlatNo = srcAddress.FlatNo,
BuildingNo = srcAddress.BuildingNo
}).ToList().AsReadOnly();
}).AsReadOnly();
dst.UnitId = src.Unit.Id;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public List<int> LuckyNumbers { get; set; }
public AddressEntity MainAddress { get; set; }
public string AddressCity { get; set; }
public List<AddressEntity> Addresses { get; set; }
public IList<AddressEntity> Addresses { get; set; }
public UnitEntity Unit { get; set; }

public int GetTotal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
BankName = entity.Account.BankName,
Number = entity.Account.Number
};
Debs = entity.Debs.Select(entityDeb => new AccountDTO()
Debs = entity.Debs.ConvertAll(entityDeb => new AccountDTO()
{
BankName = entityDeb.BankName,
Number = entityDeb.Number
}).ToList();
});
Source = new UserSourceDTO(providerName: entity.Source.ProviderName, providerAddress: entity.Source.ProviderAddress);
ImageData = entity.ImageData;
LuckyNumbers = entity.LuckyNumbers;
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace MappingGenerator.Test.MappingGenerator.TestCaseData
public List<int> LuckyNumbers { get; set; }
public AddressEntity MainAddress { get; set; }
public string AddressCity { get; set; }
public List<AddressEntity> Addresses { get; set; }
public IList<AddressEntity> Addresses { get; set; }
public UnitEntity Unit { get; set; }

public int GetTotal()
Expand Down
Loading

0 comments on commit a49a361

Please sign in to comment.