public void CreditDebitIndicator_ValidInput_Deserialises(string input, CreditDebitIndicator expected) { var response = new RestResponse(); response.Content = $@"""{input}"""; var deserializer = new CustomJsonCodec(new Configuration()); var actual = deserializer.Deserialize <CreditDebitIndicator>(response); Assert.Equal(expected, actual); }
/// <summary> /// Set amount /// </summary> /// <param name="indicator"></param> /// <param name="amount"></param> /// <returns></returns> public bool SetAmount(CreditDebitIndicator indicator, CurrencyAmount amount) { if (_isSaved) { return(false); } if (amount == null) { return(false); } if (amount.IsNegative()) { return(false); } _cdIndicator = indicator; _amount.Set(amount); return(true); }
/// <summary> /// parse XML to item entity /// </summary> /// <param name="coreDriver"></param> /// <param name="management"></param> /// <param name="head"></param> /// <param name="elem"></param> /// <returns></returns> /// <exception cref="TransactionDataFileFormatException"></exception> /// <exception cref="SystemException"></exception> public static ItemEntity Parse(CoreDriver coreDriver, MasterDataManagement management, HeadEntity head, XElement elem) { #region get line number XAttribute lineNumStr = elem.Attribute(TransDataUtils.XML_LINE_NUM); if (lineNumStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 363, String.Format( "Field {0} is missing in.", TransDataUtils.XML_LINE_NUM), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } int lineNum; if (!Int32.TryParse(lineNumStr.Value, out lineNum)) { coreDriver.logDebugInfo(typeof(HeadEntity), 363, String.Format( "Format of field {0} is error.", TransDataUtils.XML_LINE_NUM), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion #region get account type XAttribute typeStr = elem.Attribute(TransDataUtils.XML_ACCOUNT_TYPE); if (typeStr == null) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Field {0} is missing in.", TransDataUtils.XML_ACCOUNT_TYPE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (typeStr.Value.Length != 1 || (typeStr.Value[0] != (char)AccountType.CUSTOMER && typeStr.Value[0] != (char)AccountType.GL_ACCOUNT && typeStr.Value[0] != (char)AccountType.VENDOR)) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Format of field {0} is error.", TransDataUtils.XML_ACCOUNT_TYPE), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } AccountType type = (AccountType)typeStr.Value[0]; #endregion #region amount XAttribute amountStr = elem.Attribute(TransDataUtils.XML_AMOUNT); if (amountStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 375, String.Format( "Field {0} is missing in.", TransDataUtils.XML_AMOUNT), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } CurrencyAmount amount; try { amount = CurrencyAmount.Parse(amountStr.Value); } catch (Exception e) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion #region credit debit indicator XAttribute cdIndStr = elem.Attribute(TransDataUtils.XML_CD_INDICATOR); if (cdIndStr == null) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Field {0} is missing in.", TransDataUtils.XML_CD_INDICATOR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } if (cdIndStr.Value.Length != 1 || (cdIndStr.Value[0] != (char)CreditDebitIndicator.CREDIT && cdIndStr.Value[0] != (char)CreditDebitIndicator.DEBIT)) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, String.Format( "Format of field {0} is error.", TransDataUtils.XML_CD_INDICATOR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } CreditDebitIndicator indicator = (CreditDebitIndicator)cdIndStr.Value[0]; #endregion #region G/L account XAttribute glAccountStr = elem.Attribute(TransDataUtils.XML_GL_ACCOUNT); if (glAccountStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 414, String.Format( "Field {0} is missing in.", TransDataUtils.XML_GL_ACCOUNT), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } MasterDataIdentity_GLAccount glAccount; try { glAccount = new MasterDataIdentity_GLAccount( glAccountStr.Value); } catch (Exception e) { coreDriver .logDebugInfo(typeof(HeadEntity), 375, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } #endregion // vendor XAttribute vendorStr = elem.Attribute(TransDataUtils.XML_VENDOR); // customer XAttribute customerStr = elem.Attribute(TransDataUtils.XML_CUSTOMER); XAttribute businessAreaStr = elem .Attribute(TransDataUtils.XML_BUSINESS_AREA); try { ItemEntity newItem = new ItemEntity(coreDriver, management, head, lineNum); #region set account, vendor and customer if (type == AccountType.GL_ACCOUNT) { newItem.SetGLAccount(glAccount); } else if (type == AccountType.VENDOR) { if (vendorStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 414, String .Format("Field %s is missing in.", TransDataUtils.XML_VENDOR), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } MasterDataIdentity vendorId = new MasterDataIdentity( vendorStr.Value); newItem.SetVendor(vendorId, glAccount); } else if (type == AccountType.CUSTOMER) { if (customerStr == null) { coreDriver.logDebugInfo(typeof(HeadEntity), 414, String .Format("Field %s is missing in.", TransDataUtils.XML_CUSTOMER), MessageType.ERRO); throw new TransactionDataFileFormatException(""); } MasterDataIdentity customerId = new MasterDataIdentity( customerStr.Value); newItem.SetCustomer(customerId, glAccount); } #endregion newItem.SetAmount(indicator, amount); if (businessAreaStr != null) { newItem.SetBusinessArea(new MasterDataIdentity(businessAreaStr.Value)); } coreDriver.logDebugInfo( typeof(ItemEntity), 455, String.Format("Parsed line Item {0}.", newItem.LineNum), MessageType.INFO); return(newItem); } catch (IdentityTooLong e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (IdentityNoData e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (IdentityInvalidChar e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (ArgumentNullException e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new SystemException(e); } catch (MasterDataIdentityNotDefined e) { coreDriver.logDebugInfo(typeof(ItemEntity), 463, e.Message, MessageType.ERRO); throw new TransactionDataFileFormatException(""); } catch (CurrencyAmountFormatException e) { throw new TransactionDataFileFormatException(e.Message); } }