public void CharConverterTest() { Assert.That(CharConverter.Convert('A'), Is.EqualTo("A")); Assert.That(CharConverter.Convert("B"), Is.EqualTo('B')); Assert.Throws(typeof(FieldConvertError), delegate { CharConverter.Convert("AB"); }); }
protected byte[] GetDataElement(String data) { if (converter != null) { return(encoding.GetBytes(converter.Convert(data))); } return(encoding.GetBytes(data)); }
public void Conversion() { // Arrange IConverter converter = new CharConverter(); var value = "c"; var expectedValue = 'c'; // Act var actualValue = converter.Convert(value, converter.TargetType); // Assert Assert.NotNull(actualValue); Assert.IsType <char>(actualValue); Assert.Equal(expectedValue, (Char)actualValue); }
public IRecord Next() { IRecord rec = reader.Current; ILeader l = rec.Leader; bool is_utf_8 = false; if (l.CharCodingScheme == 'a') { is_utf_8 = true; } if (is_utf_8 && unicodeNormalize == NormalizationForm.FormC) { return(rec); } var fields = rec.GetVariableFields(); foreach (var f in fields) { if (!(f is IDataField)) { continue; } var field = (IDataField)f; var subfields = field.GetSubfields(); foreach (var sf in subfields) { String oldData = sf.Data; String newData = oldData; if (!is_utf_8) { newData = convert.Convert(newData); } if (unicodeNormalize != NormalizationForm.FormC) { newData = newData.Normalize(unicodeNormalize); } if (!oldData.Equals(newData)) { sf.Data = newData; } } } l.CharCodingScheme = 'a'; rec.Leader = l; return(rec); }
protected string GetDataElement(String data) { String dataElement = null; if (converter == null) { dataElement = data; } else { dataElement = converter.Convert(data); } if (normalize) { dataElement = dataElement.Normalize(NormalizationForm.FormC); } return(dataElement); }
/// <summary> /// Gets the char value of a field /// </summary> /// <param name="tag">the FIX tag</param> /// <returns>the char value</returns> /// <exception cref="FieldNotFoundException" /> public char GetChar(int tag) { try { Fields.IField fld = _fields[tag]; if (fld.GetType() == typeof(CharField)) { return(((CharField)fld).Obj); } else { return(CharConverter.Convert(fld.ToString())); } } catch (System.Collections.Generic.KeyNotFoundException) { throw new FieldNotFoundException(tag); } }
private String GetDataAsString(byte[] bytes) { String dataElement = null; if (encoding.Equals("UTF-8") || encoding.Equals("UTF8")) { try { dataElement = Encoding.UTF8.GetString(bytes); } catch (NotSupportedException e) { throw new MarcException("unsupported encoding", e); } } else if (encoding.Equals("MARC-8") || encoding.Equals("MARC8")) { if (converterAnsel == null) { converterAnsel = new AnselToUnicode(); } dataElement = converterAnsel.Convert(bytes); } else if (encoding.Equals("ISO-8859-1") || encoding.Equals("ISO_8859_1")) { try { dataElement = Encoding.GetEncoding("ISO-8859-1").GetString(bytes); } catch (NotSupportedException e) { throw new MarcException("unsupported encoding", e); } } return(dataElement); }
public void BadValueConversion() { // Arrange IConverter converter = new CharConverter(); var value = "Hello"; var expectedExceptionMessage = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(char)); var expectedInnerExceptionMessage = "String must be exactly one character long."; // Act using (new LangageSwitcher("en-us")) { var actualException = Assert.Throws <CommandLineParserException>(() => converter.Convert(value, converter.TargetType)); // Assert Assert.Equal(expectedExceptionMessage, actualException.Message); Assert.NotNull(actualException.InnerException); var actualInnerExecption = Assert.IsAssignableFrom <FormatException>(actualException.InnerException); Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message); } }