public void UnknowToExceptionTest() { Assert.Throws(typeof(RfcMappingException), () => { AbapBool.FromString("A"); }); }
public virtual object ToRemoteValue(AbapDataType remoteType, object value) { if (value == null) { return(null); } Type valueType = value.GetType(); if (valueType == typeof(Boolean)) { return(AbapBool.ToString((Boolean)value)); } if (valueType.Equals(typeof(double))) { return(((double)value).ToString(this.GetNumberFormat())); } if (valueType.Equals(typeof(float))) { return(((float)value).ToString(this.GetNumberFormat())); } if (valueType.Equals(typeof(Decimal))) { return(((Decimal)value).ToString(this.GetNumberFormat())); } if (valueType.Equals(typeof(Double))) { return(((Double)value).ToString(this.GetNumberFormat())); } if (valueType.IsEnum) { return(ConvertFromEnum(remoteType, value)); } if (remoteType == AbapDataType.DATE) { return(AbapDateTime.ToDateString((DateTime)value)); } if (remoteType == AbapDataType.TIME) { return(AbapDateTime.ToTimeString((DateTime)value)); } return(value); }
public void XToTrueTest() { Boolean boolean = AbapBool.FromString("X"); Assert.Equal(true, boolean); }
public void EmptyToFalseTest() { Boolean boolean = AbapBool.FromString(""); Assert.Equal(false, boolean); }
public void FalseToSpaceTest() { string X = AbapBool.ToString(false); Assert.Equal(" ", X); }
public void TrueToXTest() { string X = AbapBool.ToString(true); Assert.Equal("X", X); }
public virtual object FromRemoteValue(Type type, object value) { if (type.IsEnum) { return(this.ConvertToEnum(type, value)); } if (type.Equals(typeof(string))) { return(value == null ? "" : value.ToString()); } if (value == null || value.ToString().Equals("")) { if (type.IsNullable()) { return(null); } return(Activator.CreateInstance(type)); } if (type.Equals(typeof(Boolean))) { return(AbapBool.FromString(value.ToString())); } if (type.Equals(typeof(DateTime))) { return(AbapDateTime.FromString(value.ToString())); } if (type.Equals(typeof(DateTime?))) { return(AbapDateTime.FromString(value.ToString(), true)); } if (type.Equals(typeof(Decimal))) { if (value.ToString().StartsWith("*")) { throw new RqRfcException(string.Format("SAP truncated value {0}. Operation aborted", value)); } return(Convert.ToDecimal(value, value.ToString().Contains(",") ? this.CommaDecimalNumberFormat : this.PeriodDecimalNumberFormat)); } if (type.Equals(typeof(Double))) { if (value.ToString().StartsWith("*")) { throw new RqRfcException(string.Format("SAP truncated value {0}. Operation aborted", value)); } return(Convert.ToDouble(value, value.ToString().Contains(",") ? this.CommaDecimalNumberFormat : this.PeriodDecimalNumberFormat)); } if (type.Equals(typeof(byte[]))) { return(this.ToBytes(value)); } if (type.Equals(typeof(Stream))) { return(new MemoryStream(this.ToBytes(value))); } return(Convert.ChangeType(value, type)); }