Пример #1
0
 public async Task <Response3> MapAsync(Response1 response1)
 {
     return(await Mapper <Response1, Response3> .MapAsync(response1)
            .With(r1 => r1.ConsumerID, (r3, consumerId) => r3.IDNumber = consumerId)
            //Calculated field
            .With(r1 => r1.AvgNoOfPurchasesPerMonth * r1.PeriodInMonths, (r3, total) => r3.TotalPurchases = total)
            //Using Switch
            .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")
            .End()
            //Switch mapping with case mappings
            .Switch(r1 => r1.InsuranceType)
            .CaseMap(insuranceType => insuranceType == InsuranceType.MutualFund,
                     //Mapping source InsuranceMutualFund to destination InsuranceInfo using Map
                     //You can debug using using Debugger.Break()
                     mapper => { Debugger.Break(); mapper.With(r1 => r1.InsuranceMutualFund, (r3, insuranceMutualFund) => r3.InsuranceInfo = insuranceMutualFund, Map); }
                     )
            .CaseMap(insuranceType => insuranceType == InsuranceType.Superannuation,
                     //Mapping source InsuranceSuperannuation to destination InsuranceInfo using Map
                     mapper => mapper.With(r1 => r1.InsuranceSuperannuation, (r3, insuranceSuperannuation) => r3.InsuranceInfo = insuranceSuperannuation, Map)
                     )
            //Mapping source InsuranceEmployment to destination InsuranceInfo using Map by default
            .ElseMap(mapper => mapper.With(r1 => r1.InsuranceEmployment, (r3, insuranceEmployment) => r3.InsuranceInfo = insuranceEmployment, Map))
            .End()
            //Mapping List
            .With(r1 => r1.BankingInfos, (r3, bankingInfos) => r3.BankingInformation = bankingInfos, Map)
            //Mapping Dictionary
            .With(r1 => r1.EmploymentCodes, (r3, employmentCodes) => r3.LabourCodes = employmentCodes, Map, val => val)
            //Using another map - When Details1 is not null then map Details1 to Details3 using another map
            .When(r1 => r1.Details != null, mapper => mapper.With(r1 => r1.Details, (r3, details3) => r3.Details = details3, Map))
            //Using another map - When Fund1 is not null then map Fund1 to Fund3 using another map
            .When(r1 => r1.MutualFund != null, mapper => mapper.With(r1 => r1.MutualFund, (r3, fund3) => r3.Fund = fund3, Map))
            .Exec());
 }
Пример #2
0
        /// <summary>
        /// Performs a Process Transaction request on First Data Gateway.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Response PerformAuthRequest(Request request)
        {
            RestClient _client;

            _client = new RestClient(ConfigurationManager.AppSettings["TokenExPaymentUrl"]);
            _client.AddDefaultHeader("Content-Type", "application/json");
            string requestXML = RequestGenerator.GetRequest(request);
            var    req        = new RestRequest();

            req.AddParameter("application/json", requestXML, ParameterType.RequestBody);
            var       res             = _client.Post(req);
            var       jsonConf        = new JsonSerializerSettings();
            string    authCode        = "";
            string    transactionCode = "";
            string    cvvCode         = "";
            string    avsCode         = "";
            Response1 response1       = JsonConvert.DeserializeObject <Response1>(res.Content);

            foreach (Param param in response1.Params)
            {
                if (param.Key.ToLower().Equals("auth_code"))
                {
                    authCode = param.Value;
                }

                if (param.Key.ToLower().Equals("ref_num"))
                {
                    transactionCode = param.Value;
                }
                //avs_result_code
                if (param.Key.ToLower().Equals("avs_result_code"))
                {
                    avsCode = param.Value;
                }

                //cvv2_result_code
                if (param.Key.ToLower().Equals("cvv2_result_code"))
                {
                    cvvCode = param.Value;
                }
            }
            Response response = new Response();

            response.GatewayRequestRaw  = requestXML;
            response.GatewayResponseRaw = res.Content;
            response.MerchantDefined1   = avsCode;
            response.MerchantDefined2   = cvvCode;
            Hashtable      addinfo        = new Hashtable();
            SitePreference sitePreference = CSFactory.GetCacheSitePref();

            sitePreference.LoadAttributeValues();
            addinfo.Add("merchantId", sitePreference.GetAttributeValue <string>("gatewaymerchantid", string.Empty, string.Empty));
            response.AdditionalInfo = addinfo;
            response.AuthCode       = authCode;
            response.TransactionID  = transactionCode;
            if (response1.TransactionResult)
            {
                response.ResponseType = TransactionResponseType.Approved;
            }
            else
            {
                response.ResponseType = TransactionResponseType.Denied;
            }
            return(response);
        }
        public async Task MyMapper_Async_Test()
        {
            var dob = DateTime.Now;

            IResponseMapper mapper = new ResponseMapper();

            Response1 source = new Response1
            {
                ConsumerID = 123,
                Name       = "XYZ",
                AvgNoOfPurchasesPerMonth = 10,
                PeriodInMonths           = 12,
                Details = new Details1()
                {
                    DOB        = dob,
                    IsDisabled = true
                },
                MutualFund = new Fund1
                {
                    BankIdNo = 10,
                    Name     = "XYZ",
                    FundId   = 1,
                    Address  = new Address1
                    {
                        StreetNo = "123N",
                        State    = new State1
                        {
                            Name = "Victoria",
                            Abbr = "VIC"
                        },
                        Country = new Country1()
                        {
                            Name = "Australia",
                            Abbr = "AU"
                        }
                    },
                    FundKeys = new Dictionary <string, string>()
                    {
                        { "ABN", "123456" },
                        { "TFN", "9876543" }
                    }
                },
                InsuranceMutualFund = new InsuranceMutualFund {
                    MutualFundNumber = "123", TaxNo = "456"
                },
                InsuranceSuperannuation = new InsuranceSuperannuation {
                    SuperannuationNumber = "789", TaxFileNumber = "456"
                },
                InsuranceEmployment = new InsuranceEmployment {
                    EmploymentNumber = "678", TaxNumber = "456"
                },
                InsuranceType = Entities.InsuranceType.Employment,
                BankingInfos  = new List <BankingInfo1>()
                {
                    new BankingInfo1
                    {
                        AccountName = "ABC",
                        AccountNo   = "1"
                    },
                    new BankingInfo1
                    {
                        AccountName = "XYZ",
                        AccountNo   = "2"
                    }
                },
                EmploymentCodes = new Dictionary <EmploymentCode, string>()
                {
                    { EmploymentCode.E, "Engineer" }
                }
            };

            //Mapping source to new destination
            var destination = await mapper.MapAsync(source);

            Assert.IsTrue(destination.IDNumber == source.ConsumerID);
            Assert.IsTrue(destination.Name == source.Name);
            Assert.IsTrue(destination.TotalPurchases == source.AvgNoOfPurchasesPerMonth * source.PeriodInMonths);
            Assert.IsTrue(destination.Details.DateOfBirth == source.Details.DOB);
            Assert.IsTrue(destination.Details.IsHandicapped == source.Details.IsDisabled);
            Assert.IsTrue(source.PeriodInMonths == 12);
            Assert.IsTrue(destination.Period == "Year");
            Assert.IsTrue(source.InsuranceType == InsuranceType.Employment);
            Assert.IsTrue(destination.InsuranceInfo.MembershipNo == source.InsuranceEmployment.EmploymentNumber);
            Assert.IsTrue(destination.InsuranceInfo.TaxNumber == source.InsuranceEmployment.TaxNumber);
            Assert.IsTrue(destination.Fund.BankIdNo == source.MutualFund.BankIdNo);
            Assert.IsTrue(destination.Fund.FundId == source.MutualFund.FundId);
            Assert.IsTrue(destination.Fund.Name == source.MutualFund.Name);
            Assert.IsTrue(destination.Fund.Address.StreetNo == source.MutualFund.Address.StreetNo);
            Assert.IsTrue(destination.Fund.Address.State.Name == source.MutualFund.Address.State.Name);
            Assert.IsTrue(destination.Fund.Address.State.Abbr == source.MutualFund.Address.State.Abbr);
            Assert.IsTrue(destination.Fund.Address.Country.Name == source.MutualFund.Address.Country.Name);
            Assert.IsTrue(destination.Fund.Address.Country.Abbr == source.MutualFund.Address.Country.Abbr);
            Assert.IsTrue(destination.Fund.FundKeys["ABN"] == source.MutualFund.FundKeys["ABN"]);
            Assert.IsTrue(destination.Fund.FundKeys["TFN"] == source.MutualFund.FundKeys["TFN"]);
            Assert.IsTrue(destination.BankingInformation.Count == source.BankingInfos.Count);
            Assert.IsTrue(destination.BankingInformation[0].AccountName == source.BankingInfos[0].AccountName);
            Assert.IsTrue(destination.BankingInformation[0].AccountNumber == source.BankingInfos[0].AccountNo);
            Assert.IsTrue(destination.BankingInformation[1].AccountName == source.BankingInfos[1].AccountName);
            Assert.IsTrue(destination.BankingInformation[1].AccountNumber == source.BankingInfos[1].AccountNo);
            Assert.IsTrue(destination.LabourCodes.Count == source.EmploymentCodes.Count);
            Assert.IsTrue(destination.LabourCodes[LabourCode.ENG] == source.EmploymentCodes[EmploymentCode.E]);

            //Mapping source to existing destination
            Response3 destination_1 = new Response3()
            {
                Existing = "Mapping to existing destination object"
            };

            await mapper.MapAsync(source, destination_1);

            Assert.IsTrue(destination.IDNumber == source.ConsumerID);
            Assert.IsTrue(destination.Name == source.Name);
            Assert.IsTrue(destination_1.Existing == "Mapping to existing destination object");
            Assert.IsTrue(destination.TotalPurchases == source.AvgNoOfPurchasesPerMonth * source.PeriodInMonths);
            Assert.IsTrue(destination.Details.DateOfBirth == source.Details.DOB);
            Assert.IsTrue(destination.Details.IsHandicapped == source.Details.IsDisabled);
            Assert.IsTrue(source.PeriodInMonths == 12);
            Assert.IsTrue(destination.Period == "Year");
            Assert.IsTrue(source.InsuranceType == InsuranceType.Employment);
            Assert.IsTrue(destination.InsuranceInfo.MembershipNo == source.InsuranceEmployment.EmploymentNumber);
            Assert.IsTrue(destination.InsuranceInfo.TaxNumber == source.InsuranceEmployment.TaxNumber);
            Assert.IsTrue(destination.Fund.BankIdNo == source.MutualFund.BankIdNo);
            Assert.IsTrue(destination.Fund.FundId == source.MutualFund.FundId);
            Assert.IsTrue(destination.Fund.Name == source.MutualFund.Name);
            Assert.IsTrue(destination.Fund.Address.StreetNo == source.MutualFund.Address.StreetNo);
            Assert.IsTrue(destination.Fund.Address.State.Name == source.MutualFund.Address.State.Name);
            Assert.IsTrue(destination.Fund.Address.State.Abbr == source.MutualFund.Address.State.Abbr);
            Assert.IsTrue(destination.Fund.Address.Country.Name == source.MutualFund.Address.Country.Name);
            Assert.IsTrue(destination.Fund.Address.Country.Abbr == source.MutualFund.Address.Country.Abbr);
            Assert.IsTrue(destination.Fund.FundKeys["ABN"] == source.MutualFund.FundKeys["ABN"]);
            Assert.IsTrue(destination.Fund.FundKeys["TFN"] == source.MutualFund.FundKeys["TFN"]);
            Assert.IsTrue(destination.BankingInformation.Count == source.BankingInfos.Count);
            Assert.IsTrue(destination.BankingInformation[0].AccountName == source.BankingInfos[0].AccountName);
            Assert.IsTrue(destination.BankingInformation[0].AccountNumber == source.BankingInfos[0].AccountNo);
            Assert.IsTrue(destination.BankingInformation[1].AccountName == source.BankingInfos[1].AccountName);
            Assert.IsTrue(destination.BankingInformation[1].AccountNumber == source.BankingInfos[1].AccountNo);
            Assert.IsTrue(destination.LabourCodes.Count == source.EmploymentCodes.Count);
            Assert.IsTrue(destination.LabourCodes[LabourCode.ENG] == source.EmploymentCodes[EmploymentCode.E]);

            //Mapping source to existing destination (this)
            Response4 source_2 = new Response4()
            {
                IDNumber = "XYZ", AccountNumber = "123"
            };

            Response5 destination_2 = new Response5();

            await destination_2.MapAsync(source_2);

            Assert.IsTrue(destination_2.IDNumber == source_2.IDNumber);
            Assert.IsTrue(destination_2.AccNo == source_2.AccountNumber);
        }
Пример #4
0
 public Response3 Map(Response1 response1)
 {
     return Mapper<Response1, Response3>.Map(response1)
                                             .With(r1 => r1.ConsumerID, (r3, consumerId) => r3.IDNumber = consumerId)
                                             //Calculated field
                                             .With(r1 => r1.AvgNoOfPurchasesPerMonth * r1.PeriodInMonths, (r3, total) => r3.TotalPurchases = total)
                                             //Using Switch
                                             .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")
                                             .End()
                                             //Switch mapping with case mappings
                                             .Switch(r1 => r1.InsuranceType)
                                                 .CaseMap(insuranceType => insuranceType == InsuranceType.MutualFund,
                                                                 //Mapping source InsuranceMutualFund to destination InsuranceInfo using Map
                                                                 //You can debug using using Debugger.Break()
                                                                 mapper => { Debugger.Break(); mapper.With(r1 => r1.InsuranceMutualFund, (r3, insuranceMutualFund) => r3.InsuranceInfo = insuranceMutualFund, Map); }
                                                          )
                                                 .CaseMap(insuranceType => insuranceType == InsuranceType.Superannuation,
                                                                 //Mapping source InsuranceSuperannuation to destination InsuranceInfo using Map
                                                                 mapper => mapper.With(r1 => r1.InsuranceSuperannuation, (r3, insuranceSuperannuation) => r3.InsuranceInfo = insuranceSuperannuation, Map)
                                                          )
                                                 //Mapping source InsuranceEmployment to destination InsuranceInfo using Map by default
                                                 .ElseMap(mapper => mapper.With(r1 => r1.InsuranceEmployment, (r3, insuranceEmployment) => r3.InsuranceInfo = insuranceEmployment, Map))
                                             .End()
                                             //Mapping List
                                             .With(r1 => r1.BankingInfos, (r3, bankingInfos) => r3.BankingInformation = bankingInfos, Map)
                                             //Conditional mapping with another map - When Details1 is not null then map Details1 to Details3 using another map
                                             .When(r1 => r1.Details != null, mapper => mapper.With(r1 => r1.Details, (r3, details3) => r3.Details = details3, Map))
                                             //Conditional mapping with another map - When Fund1 is not null then map Fund1 to Fund3 using another map
                                             .When(r1 => r1.MutualFund != null, mapper => mapper.With(r1 => r1.MutualFund, (r3, fund3) => r3.Fund = fund3, Map))
                                         .Exec();
 }