public void ConvertToEnum(string value, TestEnum expected) { var result = DataTypeConverter.Convert <TestEnum?>(value, null); result.Should().NotBeNull() .And.Be(expected); }
public void ReturnTheSameString(string value) { var valueString = DataTypeConverter.ConvertAsString(value); var result = DataTypeConverter.Convert <string>(valueString); result.Should().Be(value); }
public void ConvertToBool(string value, bool expected) { var result = DataTypeConverter.Convert <bool?>(value, null); result.Should().NotBeNull() .And.Be(expected); }
public void ConvertToInt(string value, int expected) { var result = DataTypeConverter.Convert <int?>(value, null); result.Should().NotBeNull() .And.Be(expected); }
public List <Dictionary <string, object> > Extract() { var result = new List <Dictionary <string, object> >(); var table = GetTable(); if (table == null) { return(result); } var columns = GetColumns(table); var mapping = BuildMapping(columns); var rows = table.Element(ns + "rows").Elements(ns + "r"); foreach (var row in rows) { var fields = row.Elements(ns + "f").ToArray(); var obj = new Dictionary <string, object>(); var indexer = 0; for (int i = 0; i < fields.Length; i++) { var field = fields[i]; if (field.Attribute("k") != null) { indexer = Convert.ToInt32(field.Attribute("k").Value); } var map = mapping[indexer]; obj[map.Item1] = DataTypeConverter.Convert(field.Value, map.Item2); indexer++; } result.Add(obj); } return(result); }
public IPropertyCustomizer Type(SystemDataType dataType, string errorMessage = null) { propertyCustomizerHolder.SourceDataType = dataType; Validator(new DataTypeAttribute(dataType) .SetErrorMessage(errorMessage)); return(Type(DataTypeConverter.Convert(dataType))); }
public void ToSql_ForByteArray_ThrowsException() { var propertyFake = new Mock <IStructureProperty>(); propertyFake.Setup(x => x.Path).Returns("Bytes"); propertyFake.Setup(x => x.IsEnumerable).Returns(true); propertyFake.Setup(x => x.ElementDataType).Returns(typeof(byte)); propertyFake.Setup(x => x.DataType).Returns(typeof(byte[])); propertyFake.Setup(x => x.IsRootMember).Returns(true); var iac = new IndexAccessor(propertyFake.Object, _dataTypeConverter.Convert(propertyFake.Object)); var ex = Assert.Throws <SisoDbException>(() => _translator.ToDbType(iac.DataType)); Assert.AreEqual( ExceptionMessages.DbDataTypeTranslator_UnsupportedType.Inject("Byte[]"), ex.Message); }
public List <T> Extract() { var result = new List <T>(); var table = GetTable(); if (table == null) { return(result); } var columns = GetColumns(table); var mapping = BuildMapping(columns); var rows = table.Element(ns + "rows").Elements(ns + "r"); foreach (var row in rows) { var fields = row.Elements(ns + "f").ToArray(); T obj = Activator.CreateInstance <T>(); var indexer = 0; for (int i = 0; i < columns.Length; i++) { var field = fields[indexer]; if (field.Attribute("k") != null) { i = Convert.ToInt32(field.Attribute("k").Value); } Tuple <PropertyInfo, string> map; if (!mapping.TryGetValue(i, out map)) { indexer++; continue; } map.Item1.SetValue(obj, DataTypeConverter.Convert(field.Value, map.Item2), new object[0]); indexer++; } result.Add(obj); } return(result); }
internal static IStructureSchema Stub(Type structureType, bool generateIdAccessor = false, string[] indexAccessorsPaths = null) { var schemaStub = new Mock <IStructureSchema>(); schemaStub.Setup(s => s.Name).Returns(structureType.Name); if (generateIdAccessor) { var idAccessor = new IdAccessor(StructurePropertyTestFactory.GetIdProperty(structureType)); schemaStub.Setup(s => s.IdAccessor).Returns(idAccessor); } if (indexAccessorsPaths != null) { var indexAccessors = indexAccessorsPaths.Select(path => { var property = StructurePropertyTestFactory.GetPropertyByPath(structureType, path); return(new IndexAccessor(property, DataTypeConverter.Convert(property))); }); schemaStub.Setup(s => s.IndexAccessors).Returns(indexAccessors.ToArray); } return(schemaStub.Object); }
public override string ToString() { return(DataTypeConverter.Convert(this.DataType, this.BarType, new long?())); }
public override string ToString() { return(DataTypeConverter.Convert(this.DataType, this.BarType, this.BarSize)); }