CreateInstance() public method

public CreateInstance ( IDataReader reader ) : object
reader IDataReader
return object
        public void CreateInstanceThrowsArgumentNullExceptionForNullReader()
        {
            var objectInfo = new ExpandoObjectInfo();

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

            Assert.Equal("reader", exception.ParamName);
        }
        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);
        }
        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"));
        }