示例#1
0
 public void TestDateTimeTypePopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<DateTimeType>("SELECT CAST('2011-01-01' AS datetime2)"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual(new DateTime(2011, 1, 1), poco.DateTime);
     }
 }
示例#2
0
 public void TestDeclareTypeOfByParameter()
 {
     using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
     {
         var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
         var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);
         cb.DeclareTypeOf(typeof (int));
         Assert.IsTrue(cb.OpCodes.Count == 0);
         Assert.IsTrue(cb.TypesToLocalOffset.ContainsKey(typeof (int)));
     }
 }
示例#3
0
 public void TestColumnAttributeTestPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<ColumnAttributeTest>("SELECT 'X' as X, 'Y' as Y"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual("X", poco.X);
         Assert.AreEqual("Y", poco.Y);
     }
 }
示例#4
0
        public void TestInitializeValueTypeOfByParameter()
        {
            using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
            {
                var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
                var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);

                cb.InitializeValueTypeOf(typeof (int));
                Assert.AreEqual(1, cb.TypesToLocalOffset.Count);
                Assert.IsTrue(cb.TypesToLocalOffset.ContainsKey(typeof (int)));
                Assert.AreEqual(2, cb.OpCodes.Count);
                // TODO: Not a fan of binding to the opcode generation here.
                Assert.AreEqual(OpCodes.Initobj, cb.OpCodes.First().OpCode);
                Assert.AreEqual(OpCodes.Ldloca_S, cb.OpCodes.Last().OpCode);
            }
        }
示例#5
0
        public void TestCall01()
        {
            using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
            {
                var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
                var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);

                var method = typeof (int).GetMethod("ToString", BindingFlags.Public | BindingFlags.Instance, null,
                                                    Type.EmptyTypes, null);
                Assert.IsNotNull(method);
                var mb = cb.Call(method);
                Assert.IsNotNull(mb);
                Assert.AreEqual(1, cb.TypesToArguments.Count, "Argument count mismatch.");
                Assert.AreEqual(0, cb.TypesToLocalOffset.Count, "Local count mismatch.");
                Assert.AreEqual(mb.MethodInfo, method, "Method mutation.");
            }
        }
示例#6
0
        public void TestPopulateFromReaderPopulatorT()
        {
            using (var wrapper = new TestReaderWrapper<PopulateFromReaderByProtectedCtor>("SELECT 123, 456"))
            {
                var poco = wrapper.Populator.Populate()(wrapper.Reader);
                var emit = wrapper.Populator.GeneratedIl;

                Assert.IsNotNull(poco);
                Assert.AreEqual(123, poco.Foo0, "Foo0 != 123");
                Assert.AreEqual(456, poco.Foo1, "Foo1 != 456");
            }
        }
示例#7
0
 public void TestUnexpectedConstructorPopulatorT()
 {
     using(var wrapper = new TestReaderWrapper<UnexpectedConstructor>("SELECT NULL"))
     {
         wrapper.Populator.Populate()(wrapper.Reader);
     }
 }
示例#8
0
        public void TestSupportedNullableIntrinisicTypesWithValuesPopulatorT()
        {
            using (var wrapper = new TestReaderWrapper<SupportedNullableIntrinisicTypes>("SELECT CAST(1 AS tinyint), CAST(1 AS tinyint), CAST(1 AS smallint), CAST(1 AS smallint), 5, 1, CAST(1 AS bigint), CAST(1 AS bigint), 'b', CAST(123.456 AS float(24)), CAST(123.456 AS float(53)), CAST(345 AS decimal), CAST(1 AS bit), CAST(0 AS bit)"))
            {
                var fn = wrapper.Populator.Populate();
                var emit = wrapper.Populator.GeneratedIl;
                var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
                Assert.IsNotNull(poco);
                Assert.AreEqual(false, poco.TestBoolFalse);
                Assert.AreEqual(true, poco.TestBoolTrue);

                Assert.AreEqual((byte)1, poco.TestByte);
                Assert.AreEqual((sbyte)1, poco.TestSbyte);

                Assert.AreEqual('b', poco.TestChar);
                Assert.AreEqual(345, poco.TestDecimal);
                Assert.AreEqual(123.456d, poco.TestDouble);
                Assert.AreEqual(123.456f, poco.TestFloat);
                Assert.AreEqual(5, poco.TestInt);
                Assert.AreEqual(1L, poco.TestLong);

                Assert.AreEqual((short)1, poco.TestShort);
                Assert.AreEqual((uint)1, poco.TestUint);
                Assert.AreEqual(1UL, poco.TestUlong);
                Assert.AreEqual((ushort)1, poco.TestUshort);
            }
        }
示例#9
0
 public void TestSupportedNullableIntrinisicTypesAsNullPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<SupportedNullableIntrinisicTypes>("SELECT NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.IsNull(poco.TestBoolFalse);
         Assert.IsNull(poco.TestBoolTrue);
         Assert.IsNull(poco.TestByte);
         Assert.IsNull(poco.TestChar);
         Assert.IsNull(poco.TestDecimal);
         Assert.IsNull(poco.TestDouble);
         Assert.IsNull(poco.TestFloat);
         Assert.IsNull(poco.TestInt);
         Assert.IsNull(poco.TestLong);
         Assert.IsNull(poco.TestSbyte);
         Assert.IsNull(poco.TestShort);
         Assert.IsNull(poco.TestUint);
         Assert.IsNull(poco.TestUlong);
         Assert.IsNull(poco.TestUshort);
     }
 }
示例#10
0
 public void TestSupportedIntrinsicIntegerTypesPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<SupportedIntrinsicIntegerTypes>("SELECT CAST(1 AS tinyint), CAST(1 AS tinyint), CAST(-128 AS smallint), CAST(255 AS smallint), -500000, 500000, CAST(-6000000 AS bigint), CAST(6000000 AS bigint)"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual((byte)1, poco.TestByte);
         Assert.AreEqual((sbyte)1, poco.TestSbyte);
         Assert.AreEqual(-128, poco.TestShort);
         Assert.AreEqual(255, poco.TestUshort);
         Assert.AreEqual(-500000, poco.TestInt);
         Assert.AreEqual((uint)500000, poco.TestUint);
         Assert.AreEqual(-6000000L, poco.TestLong);
         Assert.AreEqual(6000000UL, poco.TestUlong);
     }
 }
示例#11
0
 public void TestGuidTypePopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<GuidType>("SELECT CAST('A8B08CD5-B19A-4F47-86DE-7AB70F10F23D' AS uniqueidentifier)"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual(new Guid("A8B08CD5-B19A-4F47-86DE-7AB70F10F23D"), poco.Guid);
     }
 }
示例#12
0
 public void TestObjectInheritancePopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<FdwDataObjectInheritancePocoTest1>("SELECT 123, 'test0', 'test1'"))
     {
         var poco = wrapper.Populator.Populate()(wrapper.Reader);
         Assert.IsNotNull(poco);
         Assert.AreEqual(123, poco.Id, "poco.Id <> 123");
         Assert.AreEqual("test0", poco.Foo0, "Foo0 != 'test0'");
         Assert.AreEqual("test1", poco.Foo1, "Foo1 != 'test1'");
     }
 }
示例#13
0
 public void TestImmutablePocoPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<ImmutablePocoTest0>("SELECT 'test0', 'test1'"))
     {
         var poco = wrapper.Populator.Populate()(wrapper.Reader);
         Assert.IsNotNull(poco);
         Assert.AreEqual("test0", poco.Foo0, "Foo0 != 'test0'");
         Assert.AreEqual("test1", poco.Foo1, "Foo1 != 'test1'");
     }
 }
示例#14
0
 public void TestNullableFieldAsValuePopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<NullablePocoTest0>("SELECT 123"))
     {
         var poco = wrapper.Populator.Populate()(wrapper.Reader);
         Assert.IsNotNull(poco);
         Assert.AreEqual(123, poco.Foo0, "Foo0 != 123");
     }
 }
示例#15
0
 public void TestNullableFieldAsNullPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<NullablePocoTest0>("SELECT NULL"))
     {
         var poco = wrapper.Populator.Populate()(wrapper.Reader);
         Assert.IsNotNull(poco);
         Assert.IsNull(poco.Foo0);
     }
 }
示例#16
0
 public void TestNullableDateTimeTypeAsNullPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.IsNull(poco.DateTime);
         Assert.IsFalse(poco.DateTime.HasValue);
     }
 }
示例#17
0
 public void TestListPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<SimpleListClass>("SELECT '1' S UNION SELECT '2' S"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
     }
 }
示例#18
0
 public void TestInvalidIlGenerationException()
 {
     using (var wrapper = new TestReaderWrapper<EmptyPocoTest0>("SELECT NULL"))
     {
         wrapper.Populator.PostCodeGenerationAction += (s, e) => e.Generator.Emit(OpCodes.Ldloc, 1024);
         var fn = wrapper.Populator.Populate();
         wrapper.Populator.Execute(wrapper.Reader, fn);
     }
 }
示例#19
0
        public void TestNewByParameter()
        {
            using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
            {
                var populator = new Populator<FdwDataObjectInheritancePocoTest0, SqlDataReader>(wrapper.Reader);
                var cb = new CodeBaseBody<FdwDataObjectInheritancePocoTest0, SqlDataReader>(populator);

                var ctor =
                    typeof (FdwDataObjectInheritancePocoTest0).GetConstructor(
                        BindingFlags.Public | BindingFlags.Instance, null, new[] {typeof (int)}, null);
                Assert.IsNotNull(ctor);
                cb.New(ctor);
                Assert.AreEqual(1, cb.OpCodes.Count, "Opcode count mismatch.");
                Assert.AreEqual(cb.OpCodes.Peek().OpCode, OpCodes.Newobj, "Opcode type mismatch.");
            }
        }
示例#20
0
 public void TestSupportedIntrinsicBooleanTypesPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<SupportedIntrinsicBooleanTypes>("SELECT CAST(1 AS bit), CAST(0 AS bit)"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual(true, poco.TestBoolTrue);
         Assert.AreEqual(false, poco.TestBoolFalse);
     }
 }
示例#21
0
 public void TestSupportedIntrinsicCharacterTypesPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<SupportedIntrinsicCharacterTypes>("SELECT 'b', 'foo'"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual('b', poco.TestChar);
         Assert.AreEqual("foo", poco.TestString);
     }
 }
示例#22
0
 public void TestSupportedIntrinsicFloatingPointTypesPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<SupportedIntrinsicFloatingPointTypes>("SELECT CAST(123.456 AS float(24)), CAST(456.798 AS float(53)), CAST(3148.29 AS decimal)"))
     {
         var fn = wrapper.Populator.Populate();
         var emit = wrapper.Populator.GeneratedIl;
         var poco = wrapper.Populator.Execute(wrapper.Reader, fn);
         Assert.IsNotNull(poco);
         Assert.AreEqual(123.456f, poco.TestFloat);
         Assert.AreEqual(456.798d, poco.TestDouble);
         Assert.AreEqual(3148, poco.TestDecimal);
     }
 }
示例#23
0
 public void TestJumpTo()
 {
     using (var wrapper = new TestReaderWrapper<NullableDateTimeType>("SELECT NULL"))
     {
         var populator = new Populator<EmptyPocoTest0, SqlDataReader>(wrapper.Reader);
         var cb = new CodeBaseBody<EmptyPocoTest0, SqlDataReader>(populator);
         cb.JumpTo(OpCodes.Nop, new Label());
         Assert.AreEqual(1, cb.OpCodes.Count, "Opcode count mismatch.");
         Assert.AreEqual(cb.OpCodes.Peek().OpCode, OpCodes.Nop, "Opcode type mismatch.");
     }
 }
示例#24
0
 public void TestEmptyPocoPopulatorT()
 {
     using (var wrapper = new TestReaderWrapper<EmptyPocoTest0>("SELECT NULL"))
     {
         var poco = wrapper.Populator.Populate()(wrapper.Reader);
         Assert.IsNotNull(poco);
     }
 }