using MyMapper.UnitTests.Entities;
using MyMapper.UnitTests.Mappers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Xml.Serialization;
public static void Main()
Console.WriteLine("MyMapper");
IResponseMapper mapper = new ResponseMapper();
Response1 source = new Response1
AvgNoOfPurchasesPerMonth = 10,
FundKeys = new Dictionary<string, string>()
InsuranceMutualFund = new InsuranceMutualFund { MutualFundNumber = "123", TaxNo = "456" },
InsuranceSuperannuation = new InsuranceSuperannuation { SuperannuationNumber = "789", TaxFileNumber = "456" },
InsuranceEmployment = new InsuranceEmployment { EmploymentNumber = "678", TaxNumber = "456" },
InsuranceType = InsuranceType.Employment,
BankingInfos = new List<BankingInfo1>()
var destination = mapper.Map(source);
Console.WriteLine("destination.IDNumber == source.ConsumerID : " + (destination.IDNumber == source.ConsumerID).ToString());
Console.WriteLine("destination.Name == source.Name : " + (destination.Name == source.Name).ToString());
Console.WriteLine("destination.TotalPurchases == source.AvgNoOfPurchasesPerMonth * response1.PeriodInMonths : " + (destination.TotalPurchases == source.AvgNoOfPurchasesPerMonth * source.PeriodInMonths).ToString());
Console.WriteLine("destination.Details.DateOfBirth == source.Details.DOB : " + (destination.Details.DateOfBirth == source.Details.DOB).ToString());
Console.WriteLine("destination.Details.IsHandicapped == source.Details.IsDisabled : " + (destination.Details.IsHandicapped == source.Details.IsDisabled).ToString());
Console.WriteLine("destination.InsuranceInfo.MembershipNo == source.InsuranceEmployment.EmploymentNumber : " + (destination.InsuranceInfo.MembershipNo == source.InsuranceEmployment.EmploymentNumber).ToString());
Console.WriteLine("source.PeriodInMonths : " + (source.PeriodInMonths == 12).ToString());
Console.WriteLine("destination.Period == \"Year\" : " + (destination.Period == "Year").ToString());
Console.WriteLine("source.InsuranceType == InsuranceType.Employment : " + (source.InsuranceType == InsuranceType.Employment).ToString());
Console.WriteLine("destination.InsuranceInfo.TaxNumber == source.InsuranceEmployment.TaxNumber : " + (destination.InsuranceInfo.TaxNumber == source.InsuranceEmployment.TaxNumber).ToString());
Console.WriteLine("destination.Fund.BankIdNo == source.MutualFund.BankIdNo : " + (destination.Fund.BankIdNo == source.MutualFund.BankIdNo).ToString());
Console.WriteLine("destination.Fund.FundId == source.MutualFund.FundId : " + (destination.Fund.FundId == source.MutualFund.FundId).ToString());
Console.WriteLine("destination.Fund.Name == source.MutualFund.Name : " + (destination.Fund.Name == source.MutualFund.Name).ToString());
Console.WriteLine("destination.Fund.Address.StreetNo == source.MutualFund.Address.StreetNo : " + (destination.Fund.Address.StreetNo == source.MutualFund.Address.StreetNo).ToString());
Console.WriteLine("destination.Fund.Address.State.Name == source.MutualFund.Address.State.Name : " + (destination.Fund.Address.State.Name == source.MutualFund.Address.State.Name).ToString());
Console.WriteLine("destination.Fund.Address.State.Abbr == source.MutualFund.Address.State.Abbr : " + (destination.Fund.Address.State.Abbr == source.MutualFund.Address.State.Abbr).ToString());
Console.WriteLine("destination.Fund.Address.Country.Name == source.MutualFund.Address.Country.Name : " + (destination.Fund.Address.Country.Name == source.MutualFund.Address.Country.Name).ToString());
Console.WriteLine("destination.Fund.Address.Country.Abbr == source.MutualFund.Address.Country.Abbr : " + (destination.Fund.Address.Country.Abbr == source.MutualFund.Address.Country.Abbr).ToString());
Console.WriteLine("destination.Fund.FundKeys[\"ABN\"] == source.MutualFund.FundKeys[\"ABN\"] : " + (destination.Fund.FundKeys["ABN"] == source.MutualFund.FundKeys["ABN"]).ToString());
Console.WriteLine("destination.Fund.FundKeys[\"TFN\"] == source.MutualFund.FundKeys[\"TFN\"] : " + (destination.Fund.FundKeys["TFN"] == source.MutualFund.FundKeys["TFN"]).ToString());
Console.WriteLine("destination.BankingInformation.Count == source.BankingInfos.Count : " + (destination.BankingInformation.Count == source.BankingInfos.Count).ToString());
Console.WriteLine("destination.BankingInformation[0].AccountName == source.BankingInfos[0].AccountName : " + (destination.BankingInformation[0].AccountName == source.BankingInfos[0].AccountName).ToString());
Console.WriteLine("destination.BankingInformation[0].AccountNumber == source.BankingInfos[0].AccountNo : " + (destination.BankingInformation[0].AccountNumber == source.BankingInfos[0].AccountNo).ToString());
Console.WriteLine("destination.BankingInformation[1].AccountName == source.BankingInfos[1].AccountName : " + (destination.BankingInformation[1].AccountName == source.BankingInfos[1].AccountName).ToString());
Console.WriteLine("destination.BankingInformation[1].AccountNumber == source.BankingInfos[1].AccountNo : " + (destination.BankingInformation[1].AccountNumber == source.BankingInfos[1].AccountNo).ToString());
namespace MyMapper.UnitTests.Mappers
using MyMapper.Converters;
using MyMapper.UnitTests.Entities;
using System.Threading.Tasks;
public interface IResponseMapper
Response3 Map(Response1 response1);
Task<Fund3> MapAsync(Fund1 fund1);
public class ResponseMapper : IResponseMapper
public Fund3 Map(Fund1 fund1)
return Mapper<Fund1, Fund3>.Exec<EntityConverter<Fund1, Fund3>>(fund1);
public async Task<Fund3> MapAsync(Fund1 fund1)
return await Mapper<Fund1, Fund3>.MapAsync(fund1).Exec();
public Details3 Map(Details1 details1)
return Mapper<Details1, Details3>.Map(details1)
.With(d1 => d1.DOB, (d3, dob) => d3.DateOfBirth = dob)
.With(d1 => d1.IsDisabled, (d3, disabled) => d3.IsHandicapped = disabled)
public async Task<Details3> MapAsync(Details1 details1)
return await Mapper<Details1, Details3>.MapAsync(details1)
.With(d1 => d1.DOB, (d3, dob) => d3.DateOfBirth = dob)
.With(d1 => d1.IsDisabled, (d3, disabled) => d3.IsHandicapped = disabled)
public BankingInfo3 Map(BankingInfo1 bankingInfo1)
return Mapper<BankingInfo1, BankingInfo3>.Map(bankingInfo1)
.With(bi1 => bi1.AccountNo, (bi3, accNo) => bi3.AccountNumber = accNo)
public InsuranceInfo Map(InsuranceMutualFund insuranceMutualFund)
return Mapper<InsuranceMutualFund, InsuranceInfo>.Map(insuranceMutualFund)
.With(imf => imf.MutualFundNumber, (insuranceInfo, mutualFundNumber) => insuranceInfo.MembershipNo = mutualFundNumber)
.With(imf => imf.TaxNo, (insuranceInfo, taxNo) => insuranceInfo.TaxNumber = taxNo)
public InsuranceInfo Map(InsuranceSuperannuation insuranceSuperannuation)
return Mapper<InsuranceSuperannuation, InsuranceInfo>.Map(insuranceSuperannuation)
.With(imf => imf.SuperannuationNumber, (insuranceInfo, mutualFundNumber) => insuranceInfo.MembershipNo = mutualFundNumber)
.With(imf => imf.TaxFileNumber, (insuranceInfo, taxFileNo) => insuranceInfo.TaxNumber = taxFileNo)
public InsuranceInfo Map(InsuranceEmployment insuranceEmployment)
return Mapper<InsuranceEmployment, InsuranceInfo>.Map(insuranceEmployment)
.With(ie => ie.EmploymentNumber, (insuranceInfo, employmentNumber) => insuranceInfo.MembershipNo = employmentNumber)
.With(imf => imf.TaxNumber, (insuranceInfo, taxNumber) => insuranceInfo.TaxNumber = taxNumber)
public Response3 Map(Response1 response1)
return Mapper<Response1, Response3>.Map(response1)
.With(r1 => r1.ConsumerID, (r3, consumerId) => r3.IDNumber = consumerId)
.With(r1 => r1.AvgNoOfPurchasesPerMonth * r1.PeriodInMonths, (r3, total) => r3.TotalPurchases = total)
.Switch(r1 => r1.PeriodInMonths)
.Case(periodInMonths => periodInMonths > 0 && periodInMonths <= 3, (r3, periodInMonths) => r3.Period = "Quarter")
.Case(periodInMonths => periodInMonths > 3 && periodInMonths <= 6, (r3, periodInMonths) => r3.Period = "Half")
.Case(periodInMonths => periodInMonths > 6 && periodInMonths <= 9, (r3, periodInMonths) => r3.Period = "Three Quarter")
.Case(periodInMonths => periodInMonths > 9 && periodInMonths <= 12, (r3, periodInMonths) => r3.Period = "Year")
.Else((r3, periodInMonths) => r3.Period = "Unknown")
.Switch(r1 => r1.InsuranceType)
.CaseMap(insuranceType => insuranceType == InsuranceType.MutualFund,
mapper => { Debugger.Break(); mapper.With(r1 => r1.InsuranceMutualFund, (r3, insuranceMutualFund) => r3.InsuranceInfo = insuranceMutualFund, Map); }
.CaseMap(insuranceType => insuranceType == InsuranceType.Superannuation,
mapper => mapper.With(r1 => r1.InsuranceSuperannuation, (r3, insuranceSuperannuation) => r3.InsuranceInfo = insuranceSuperannuation, Map)
.ElseMap(mapper => mapper.With(r1 => r1.InsuranceEmployment, (r3, insuranceEmployment) => r3.InsuranceInfo = insuranceEmployment, Map))
.With(r1 => r1.BankingInfos, (r3, bankingInfos) => r3.BankingInformation = bankingInfos, Map)
.When(r1 => r1.Details != null, mapper => mapper.With(r1 => r1.Details, (r3, details3) => r3.Details = details3, Map))
.When(r1 => r1.MutualFund != null, mapper => mapper.With(r1 => r1.MutualFund, (r3, fund3) => r3.Fund = fund3, Map))
namespace MyMapper.UnitTests.Entities
public DateTime DOB { get; set; }
public bool IsDisabled { get; set; }
public string StreetNo { get; set; }
public State1 State { get; set; }
public Country1 Country { get; set; }
public string Name { get; set; }
public string Abbr { get; set; }
public string Name { get; set; }
public string Abbr { get; set; }
public int? BankIdNo { get; set; }
public string Name { get; set; }
public int FundId { get; set; }
public Address1 Address { get; set; }
public Dictionary<string, string> FundKeys { get; set; }
public class BankingInfo1
public string AccountNo { get; set; }
public string AccountName { get; set; }
public class InsuranceMutualFund
public string MutualFundNumber { get; set; }
public string TaxNo { get; set; }
public class InsuranceSuperannuation
public string SuperannuationNumber { get; set; }
public string TaxFileNumber { get; set; }
public class InsuranceEmployment
public string EmploymentNumber { get; set; }
public string TaxNumber { get; set; }
public enum InsuranceType
public int ConsumerID { get; set; }
public string Name { get; set; }
public int AvgNoOfPurchasesPerMonth { get; set; }
public int PeriodInMonths { get; set; }
public Details1 Details { get; set; }
public Fund1 MutualFund { get; set; }
public IList<BankingInfo1> BankingInfos { get; set; }
public InsuranceMutualFund InsuranceMutualFund { get; set; }
public InsuranceSuperannuation InsuranceSuperannuation { get; set; }
public InsuranceEmployment InsuranceEmployment { get; set; }
public InsuranceType InsuranceType { get; set; }
public DateTime DateOfBirth { get; set; }
public bool IsHandicapped { get; set; }
public string StreetNo { get; set; }
public State3 State { get; set; }
public Country3 Country { get; set; }
public string Name { get; set; }
public string Abbr { get; set; }
public string Name { get; set; }
public string Abbr { get; set; }
public int? BankIdNo { get; set; }
public string Name { get; set; }
public int FundId { get; set; }
public Address3 Address { get; set; }
public Dictionary<string, string> FundKeys { get; set; }
public class BankingInfo3
public string AccountNumber { get; set; }
public string AccountName { get; set; }
public class InsuranceInfo
public string MembershipNo { get; set; }
public string TaxNumber { get; set; }
public int IDNumber { get; set; }
public string Name { get; set; }
public int TotalPurchases { get; set; }
public Details3 Details { get; set; }
public Fund3 Fund { get; set; }
public IList<BankingInfo3> BankingInformation { get; set; }
public string Period { get; set; }
public InsuranceInfo InsuranceInfo { get; set; }
public string Existing { get; set; }