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))); } }
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); } }
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."); } }
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."); } }
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."); } }