コード例 #1
0
        public void CreateInstanceThrowsArgumentNullExceptionForNullReader()
        {
            var objectInfo = new ExpandoObjectInfo();

            var exception = Assert.Throws<ArgumentNullException>(
                () => objectInfo.CreateInstance(null));

            Assert.Equal("reader", exception.ParamName);
        }
コード例 #2
0
        public void GetIdentifierValueThrowsNotSupportedException()
        {
            var objectInfo = new ExpandoObjectInfo();

            var exception = Assert.Throws<NotSupportedException>(
                () => objectInfo.GetIdentifierValue(new ExpandoObject()));

            Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason);
        }
コード例 #3
0
        public void GetColumnInfoThrowsNotSupportedException()
        {
            var objectInfo = new ExpandoObjectInfo();

            var exception = Assert.Throws<NotSupportedException>(
                () => objectInfo.GetColumnInfo("Name"));

            Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: ObjectInfo.cs プロジェクト: mwhelan/MicroLite
        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);
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        public void ForTypeReturnsExpandoObject()
        {
            var objectInfo = new ExpandoObjectInfo();

            Assert.Equal(typeof(ExpandoObject), objectInfo.ForType);
        }
コード例 #9
0
        public void VerifyInstanceStateThrowsNotSupportedException()
        {
            var objectInfo = new ExpandoObjectInfo();

            var exception = Assert.Throws<NotSupportedException>(
                () => objectInfo.VerifyInstanceForInsert(new ExpandoObject()));

            Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason);
        }
コード例 #10
0
        public void IsDefaultIdentifierThrowsNotSupportedException()
        {
            var objectInfo = new ExpandoObjectInfo();

            var exception = Assert.Throws<NotSupportedException>(
                () => objectInfo.IsDefaultIdentifier(0));

            Assert.Equal(exception.Message, ExceptionMessages.ExpandoObjectInfo_NotSupportedReason);
        }
コード例 #11
0
ファイル: ObjectInfo.cs プロジェクト: TrevorPilley/MicroLite
        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;
        }