public void ModelFactory_Contract_ContractWithProductsAndFees_IsConverted() { Contract contractModel = TestData.ContractModelWithProductsAndTransactionFees; ModelFactory modelFactory = new ModelFactory(); ContractResponse contractResponse = modelFactory.ConvertFrom(contractModel); contractResponse.ShouldNotBeNull(); contractResponse.EstateId.ShouldBe(contractModel.EstateId); contractResponse.OperatorId.ShouldBe(contractModel.OperatorId); contractResponse.ContractId.ShouldBe(contractModel.ContractId); contractResponse.Description.ShouldBe(contractModel.Description); contractResponse.Products.ShouldNotBeNull(); contractResponse.Products.ShouldHaveSingleItem(); ContractProduct contractProduct = contractResponse.Products.Single(); Product expectedContractProduct = contractModel.Products.Single(); contractProduct.ProductId.ShouldBe(expectedContractProduct.ProductId); contractProduct.Value.ShouldBe(expectedContractProduct.Value); contractProduct.DisplayText.ShouldBe(expectedContractProduct.DisplayText); contractProduct.Name.ShouldBe(expectedContractProduct.Name); contractProduct.TransactionFees.ShouldNotBeNull(); contractProduct.TransactionFees.ShouldHaveSingleItem(); ContractProductTransactionFee productTransactionFee = contractProduct.TransactionFees.Single(); ContractProductTransactionFee expectedProductTransactionFee = contractProduct.TransactionFees.Single(); productTransactionFee.TransactionFeeId.ShouldBe(expectedProductTransactionFee.TransactionFeeId); productTransactionFee.Value.ShouldBe(expectedProductTransactionFee.Value); productTransactionFee.CalculationType.ShouldBe(expectedProductTransactionFee.CalculationType); productTransactionFee.Description.ShouldBe(expectedProductTransactionFee.Description); }
public ContractResponse ConvertFrom(Contract contract) { if (contract == null) { return(null); } ContractResponse contractResponse = new ContractResponse { ContractId = contract.ContractId, EstateId = contract.EstateId, OperatorId = contract.OperatorId, OperatorName = contract.OperatorName, Description = contract.Description }; if (contract.Products != null && contract.Products.Any()) { contractResponse.Products = new List <ContractProduct>(); contract.Products.ForEach(p => { ContractProduct contractProduct = new ContractProduct { ProductId = p.ProductId, Value = p.Value, DisplayText = p.DisplayText, Name = p.Name }; if (p.TransactionFees != null && p.TransactionFees.Any()) { contractProduct.TransactionFees = new List <ContractProductTransactionFee>(); p.TransactionFees.ForEach(tf => { ContractProductTransactionFee transactionFee = new ContractProductTransactionFee { TransactionFeeId = tf.TransactionFeeId, Value = tf.Value, Description = tf.Description, }; transactionFee.CalculationType = Enum.Parse <CalculationType>(tf.CalculationType.ToString()); contractProduct.TransactionFees.Add(transactionFee); }); } contractResponse.Products.Add(contractProduct); }); } return(contractResponse); }
public void ContractEntities_ConvertFrom_ContractConverted() { ContractEntity contract = TestData.ContractEntity; List <ContractProductEntity> contractProducts = new List <ContractProductEntity> { TestData.ContractProductEntity }; List <ContractProductTransactionFeeEntity> contractProductsTransactionFees = new List <ContractProductTransactionFeeEntity> { TestData.ContractProductTransactionFeeEntity }; ModelFactory modelFactory = new ModelFactory(); ContractModel contractModel = modelFactory.ConvertFrom(contract, contractProducts, contractProductsTransactionFees); contractModel.ShouldNotBeNull(); contractModel.EstateId.ShouldBe(contract.EstateId); contractModel.ContractId.ShouldBe(contract.ContractId); contractModel.OperatorId.ShouldBe(contract.OperatorId); contractModel.Description.ShouldBe(contract.Description); contractModel.Products.ShouldNotBeNull(); contractModel.Products.ShouldHaveSingleItem(); Product contractProduct = contractModel.Products.Single(); ContractProduct expectedContractProduct = contractProducts.Single(); contractProduct.ProductId.ShouldBe(expectedContractProduct.ProductId); contractProduct.DisplayText.ShouldBe(expectedContractProduct.DisplayText); contractProduct.Name.ShouldBe(expectedContractProduct.ProductName); contractProduct.Value.ShouldBe(expectedContractProduct.Value); contractProduct.TransactionFees.ShouldNotBeNull(); contractProduct.TransactionFees.ShouldHaveSingleItem(); ContractProductTransactionFeeModel contractProductTransactionFee = contractProduct.TransactionFees.Single(); ContractProductTransactionFee expectedContractProductTransactionFee = contractProductsTransactionFees.Single(); contractProductTransactionFee.TransactionFeeId.ShouldBe(expectedContractProductTransactionFee.TransactionFeeId); contractProductTransactionFee.Description.ShouldBe(expectedContractProductTransactionFee.Description); contractProductTransactionFee.Value.ShouldBe(expectedContractProductTransactionFee.Value); contractProductTransactionFee.CalculationType.ShouldBe((CalculationType)expectedContractProductTransactionFee.CalculationType); }
/// <summary> /// Converts from. /// </summary> /// <param name="transactionFees">The transaction fees.</param> /// <returns></returns> public List <ContractProductTransactionFee> ConvertFrom(List <TransactionFee> transactionFees) { List <ContractProductTransactionFee> result = new List <ContractProductTransactionFee>(); transactionFees.ForEach(tf => { ContractProductTransactionFee transactionFee = new ContractProductTransactionFee { TransactionFeeId = tf.TransactionFeeId, Value = tf.Value, Description = tf.Description, }; transactionFee.CalculationType = Enum.Parse <CalculationType>(tf.CalculationType.ToString()); transactionFee.FeeType = Enum.Parse <FeeType>(tf.FeeType.ToString()); result.Add(transactionFee); }); return(result); }
public void ContractEntities_ContractProductTransactionFee_ConvertFrom_TransactionFeeConverted() { List <ContractProductTransactionFeeEntity> contractProductsTransactionFees = new List <ContractProductTransactionFeeEntity> { TestData.ContractProductTransactionFeeEntity }; ModelFactory modelFactory = new ModelFactory(); List <ContractProductTransactionFeeModel> transactionFeesModelList = modelFactory.ConvertFrom(contractProductsTransactionFees); transactionFeesModelList.ShouldNotBeNull(); transactionFeesModelList.ShouldHaveSingleItem(); ContractProductTransactionFeeModel contractProductTransactionFee = transactionFeesModelList.Single(); ContractProductTransactionFee expectedContractProductTransactionFee = contractProductsTransactionFees.Single(); contractProductTransactionFee.TransactionFeeId.ShouldBe(expectedContractProductTransactionFee.TransactionFeeId); contractProductTransactionFee.Description.ShouldBe(expectedContractProductTransactionFee.Description); contractProductTransactionFee.Value.ShouldBe(expectedContractProductTransactionFee.Value); contractProductTransactionFee.CalculationType.ShouldBe((CalculationType)expectedContractProductTransactionFee.CalculationType); }