示例#1
0
        public async void TestGetDateTime()
        {
            var reader = new ListDataReader <Student>(_Students);
            var ps     = _Properties.Where(i => i.CanRead).ToArray();

            foreach (var st in _Students)
            {
                await reader.ReadAsync();

                var index = 0;
                foreach (var p in ps)
                {
                    if (p.PropertyType == typeof(DateTime) || (p.PropertyType == typeof(DateTime?) && p.GetMethod.Invoke(st, new object[0]) != null))
                    {
                        Assert.Equal(p.GetMethod.Invoke(st, new object[0]), reader.GetDateTime(index));
                    }
                    else if (p.PropertyType.GetTypeInfo().IsGenericType &&
                             p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) &&
                             p.GetMethod.Invoke(st, new object[0]) == null)
                    {
                        Assert.ThrowsAny <RuntimeBinderException>(() => reader.GetDateTime(index));
                    }
                    else
                    {
                        Assert.ThrowsAny <RuntimeBinderException>(() => reader.GetDateTime(index));
                    }
                    index++;
                }
            }
        }
        public void TestGetDateTime()
        {
            var reader = new ListDataReader <Student>(_Students);

            reader.Read();
            var col = "DateTime2";

            Assert.Equal(new DateTime(1990, 2, 3), reader.GetDateTime(col));
            reader.Read();
            reader.Read();
            Assert.Equal(new DateTime(1991, 2, 3), reader.GetDateTime(col));
        }