Пример #1
0
 public TestResult FiveParameters()
 {
     return(RunTest(2.75,
                    () =>
     {
         using (var conn = GetOpenConnection())
             using (var cmd = new SqlCommand("DECLARE @A int", conn))
             {
                 cmd.Parameters.Add("@B", SqlDbType.Int).Value = 25;
                 cmd.Parameters.Add("@C", SqlDbType.DateTime).Value = DateTime.Now;
                 cmd.Parameters.Add("@D", SqlDbType.Bit).Value = true;
                 cmd.Parameters.Add("@E", SqlDbType.VarChar, 500).Value = "Hello world!";
                 cmd.Parameters.Add("@F", SqlDbType.UniqueIdentifier).Value = Guid.NewGuid();
                 cmd.ExecuteNonQuery();
             }
     },
                    () => DB.Execute("DECLARE @A int", new {
         B = 25,
         C = Col.DateTime(DateTime.Now),
         D = true,
         E = Col.VarChar("Hello world!", 500),
         F = Guid.NewGuid()
     })
                    ));
 }
Пример #2
0
        public void StructuredDynamicYielder()
        {
            var result = new StructuredDynamicYielder(new[] { new {
                                                                  A = Col.DateTime(testDateTime),
                                                                  B = Col.DateTime(null)
                                                              } }).First();

            Assert.AreEqual(2, result.FieldCount);
            Assert.AreEqual(typeof(DateTime), result.GetValue(0).GetType());
            Assert.AreEqual(testDateTime, result.GetValue(0));
            Assert.AreEqual(DBNull.Value, result.GetValue(1));
        }
Пример #3
0
        public void Structured()
        {
            var rows = DB.GetRows("SELECT * FROM @Input", new {
                Input = Col.Structured("ListOfDateTimes", new[] {
                    new { A = Col.DateTime(testDateTime) },
                    new { A = Col.DateTime(null) }
                })
            });

            Assert.AreEqual(2, rows.Count);
            Assert.AreEqual(typeof(DateTime), rows[0].A.GetType());
            Assert.AreEqual(testDateTime, rows[0].A);
            Assert.AreEqual(null, rows[1].A);
        }
Пример #4
0
        public TestResult Typed_FiveParameters()
        {
            return(RunTest(10,
                           () =>
            {
                using (var conn = GetOpenConnection())
                    using (var cmd = new SqlCommand("SELECT @Name AS name, @CreateDate AS create_date, @ObjectID AS object_id, @SchemaID AS schema_id, @Type AS type", conn))
                    {
                        cmd.Parameters.Add("@Name", SqlDbType.VarChar, 100).Value = "name";
                        cmd.Parameters.Add("@CreateDate", SqlDbType.DateTime).Value = DateTime.Now;
                        cmd.Parameters.Add("@ObjectID", SqlDbType.Int).Value = 25;
                        cmd.Parameters.Add("@SchemaID", SqlDbType.Int).Value = 27;
                        cmd.Parameters.Add("@Type", SqlDbType.VarChar, 20).Value = "type";

                        var reader = cmd.ExecuteReader();
                        reader.Read();

                        var obj = new SysAllObject {
                            name = (string)reader["name"],
                            create_date = (DateTime)reader["create_date"],
                            object_id = (int)reader["object_id"],
                            schema_id = (int)reader["schema_id"],
                            type = (string)reader["type"]
                        };
                    }
            },
                           () =>
            {
                var obj = DB.GetRow <SysAllObject>("SELECT @Name AS name, @CreateDate AS create_date, @ObjectID AS object_id, @SchemaID AS schema_id, @Type AS type", new {
                    Name = Col.VarChar("name", 100),
                    CreateDate = Col.DateTime(DateTime.Now),
                    ObjectID = 25,
                    SchemaID = 27,
                    Type = Col.VarChar("type", 20)
                });
            }
                           ));
        }
Пример #5
0
 public void Factory()
 {
     Assert.IsInstanceOf <SqlDateTime>(Col.DateTime(testDateTime));
 }