public void FormatMapTest() { string fieldValue = "Call"; ICSVFormatRule rule = _rules[6]; // optiontype string expected = "C"; string actual; actual = CSVFormatter_Accessor.FormatField(fieldValue, rule); Assert.AreEqual(expected, actual); }
public void FormatDateTest() { string fieldValue = "2013-10-01"; ICSVFormatRule rule = _rules[5]; // expirationdate string expected = "10/1/2013"; string actual; actual = CSVFormatter_Accessor.FormatField(fieldValue, rule); Assert.AreEqual(expected, actual); }
public void FormatNumericTest() { string fieldValue = "20"; ICSVFormatRule rule = _rules[4]; // strikeprice string expected = "20.00"; string actual; actual = CSVFormatter_Accessor.FormatField(fieldValue, rule); Assert.AreEqual(expected, actual); }
public void FormatConstantTest() { string fieldValue = string.Empty; ICSVFormatRule rule = _rules[0]; // account string expected = "Adar"; string actual; actual = CSVFormatter_Accessor.FormatField(fieldValue, rule); Assert.AreEqual(expected, actual); }
private static string FormatField(string fieldValue, ICSVFormatRule rule) { CSVField field = new CSVField(fieldValue, rule); return(field.ToString()); }
internal CSVField(string inputString, ICSVFormatRule rule) { _inputString = inputString ?? String.Empty; _fieldValue = String.Empty; try { switch (rule.FormatType) { case CSVFormatType.Datetime: if (!string.IsNullOrEmpty(_inputString)) { _fieldValue = DateTime.Parse(_inputString); _fieldFormatString = rule.FormatString; } break; case CSVFormatType.DatetimeOffset: if (!string.IsNullOrEmpty(_inputString)) { _fieldValue = DateTimeOffset.Parse(_inputString); _fieldFormatString = rule.FormatString; } break; case CSVFormatType.Map: if (!string.IsNullOrEmpty(_inputString)) { // formatString contains translate map _fieldValue = Translate(_inputString, rule.FormatString); _fieldFormatString = null; } break; case CSVFormatType.Numeric: if (!string.IsNullOrEmpty(_inputString)) { _fieldValue = Double.Parse(_inputString); _fieldFormatString = rule.FormatString; } break; case CSVFormatType.String: _fieldValue = _inputString; _fieldFormatString = rule.FormatString; break; case CSVFormatType.Timespan: if (!string.IsNullOrEmpty(_inputString)) { _fieldValue = TimeSpan.Parse(_inputString); _fieldFormatString = rule.FormatString; } break; } } catch (System.FormatException) { _fieldValue = string.Format(CSVErrorMessages.ErrorMsgParsingError, _inputString, rule.FormatType); _fieldFormatString = null; } catch (System.OverflowException) { _fieldValue = string.Format(CSVErrorMessages.ErrorMsgOverflowError, _inputString, rule.FormatType); _fieldFormatString = null; } }