public void CreateInstanceThrowsArgumentNullExceptionForNullReader() { var objectInfo = new ExpandoObjectInfo(); var exception = Assert.Throws<ArgumentNullException>( () => objectInfo.CreateInstance(null)); Assert.Equal("reader", exception.ParamName); }
public void GetIdentifierValueThrowsNotSupportedException() { var objectInfo = new ExpandoObjectInfo(); var exception = Assert.Throws<NotSupportedException>( () => objectInfo.GetIdentifierValue(new ExpandoObject())); Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason); }
public void GetColumnInfoThrowsNotSupportedException() { var objectInfo = new ExpandoObjectInfo(); var exception = Assert.Throws<NotSupportedException>( () => objectInfo.GetColumnInfo("Name")); Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason); }
public void CreateInstanceSetsPropertyValueToNullIfPassedDBNull() { var objectInfo = new ExpandoObjectInfo(); var mockReader = new Mock<IDataReader>(); mockReader.Setup(x => x.FieldCount).Returns(1); mockReader.Setup(x => x.IsDBNull(It.IsAny<int>())).Returns(true); mockReader.Setup(x => x.GetName(0)).Returns("Name"); var instance = (dynamic)objectInfo.CreateInstance(mockReader.Object); Assert.Null(instance.Name); }
public void CreateInstance() { var objectInfo = new ExpandoObjectInfo(); var mockReader = new Mock<IDataReader>(); mockReader.Setup(x => x.FieldCount).Returns(2); mockReader.Setup(x => x.IsDBNull(It.IsAny<int>())).Returns(false); mockReader.Setup(x => x.GetName(0)).Returns("Id"); mockReader.Setup(x => x.GetName(1)).Returns("Name"); mockReader.Setup(x => x.GetValue(0)).Returns(12345); mockReader.Setup(x => x.GetValue(1)).Returns("Fred Flintstone"); var instance = (dynamic)objectInfo.CreateInstance(mockReader.Object); Assert.NotNull(instance); Assert.IsType<ExpandoObject>(instance); Assert.Equal(12345, instance.Id); Assert.Equal("Fred Flintstone", instance.Name); }
private static Dictionary <Type, IObjectInfo> GetObjectInfos() { var dictionary = new Dictionary <Type, IObjectInfo>(); #if !NET_3_5 var expandoObjectInfo = new ExpandoObjectInfo(); dictionary.Add(typeof(System.Dynamic.ExpandoObject), expandoObjectInfo); dictionary.Add(typeof(object), expandoObjectInfo); // If the generic argument <dynamic> is used (in ISession.Fetch for example), typeof(T) will return object. var tupleObjectInfo = new TupleObjectInfo(); dictionary.Add(typeof(Tuple <>), tupleObjectInfo); dictionary.Add(typeof(Tuple <,>), tupleObjectInfo); dictionary.Add(typeof(Tuple <, ,>), tupleObjectInfo); dictionary.Add(typeof(Tuple <, , ,>), tupleObjectInfo); dictionary.Add(typeof(Tuple <, , , ,>), tupleObjectInfo); dictionary.Add(typeof(Tuple <, , , , ,>), tupleObjectInfo); dictionary.Add(typeof(Tuple <, , , , , ,>), tupleObjectInfo); #endif return(dictionary); }
public void CreateInstanceIgnoresMicroLiteRowNumber() { var objectInfo = new ExpandoObjectInfo(); var mockReader = new Mock<IDataReader>(); mockReader.Setup(x => x.FieldCount).Returns(3); mockReader.Setup(x => x.IsDBNull(It.IsAny<int>())).Returns(false); mockReader.Setup(x => x.GetName(0)).Returns("Id"); mockReader.Setup(x => x.GetName(1)).Returns("Name"); mockReader.Setup(x => x.GetName(2)).Returns("MicroLiteRowNumber"); mockReader.Setup(x => x.GetValue(0)).Returns(12345); mockReader.Setup(x => x.GetValue(1)).Returns("Fred Flintstone"); mockReader.Setup(x => x.GetValue(2)).Returns(1); var instance = (dynamic)objectInfo.CreateInstance(mockReader.Object); var dictionary = (IDictionary<string, object>)instance; Assert.False(dictionary.ContainsKey("MicroLiteRowNumber")); }
public void ForTypeReturnsExpandoObject() { var objectInfo = new ExpandoObjectInfo(); Assert.Equal(typeof(ExpandoObject), objectInfo.ForType); }
public void VerifyInstanceStateThrowsNotSupportedException() { var objectInfo = new ExpandoObjectInfo(); var exception = Assert.Throws<NotSupportedException>( () => objectInfo.VerifyInstanceForInsert(new ExpandoObject())); Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason); }
public void IsDefaultIdentifierThrowsNotSupportedException() { var objectInfo = new ExpandoObjectInfo(); var exception = Assert.Throws<NotSupportedException>( () => objectInfo.IsDefaultIdentifier(0)); Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason); }
private static Dictionary<Type, IObjectInfo> GetObjectInfos() { var dictionary = new Dictionary<Type, IObjectInfo>(); #if !NET35 var expandoObjectInfo = new ExpandoObjectInfo(); dictionary.Add(typeof(System.Dynamic.ExpandoObject), expandoObjectInfo); dictionary.Add(typeof(object), expandoObjectInfo); // If the generic argument <dynamic> is used (in ISession.Fetch for example), typeof(T) will return object. var tupleObjectInfo = new TupleObjectInfo(); dictionary.Add(typeof(Tuple<>), tupleObjectInfo); dictionary.Add(typeof(Tuple<,>), tupleObjectInfo); dictionary.Add(typeof(Tuple<,,>), tupleObjectInfo); dictionary.Add(typeof(Tuple<,,,>), tupleObjectInfo); dictionary.Add(typeof(Tuple<,,,,>), tupleObjectInfo); dictionary.Add(typeof(Tuple<,,,,,>), tupleObjectInfo); dictionary.Add(typeof(Tuple<,,,,,,>), tupleObjectInfo); #endif return dictionary; }