Beispiel #1
0
 public void TestInParamsNullable()
 {
     using (var command = new TestDataCommand())
     {
         command.Text             = "update top(1) Name = @Name where Age in @Age";
         command.ConnectionString = "sqlConnectionString";
         var num = command.ExecuteNonQuery(new { Name = "1", Age = new List <int?>()
                                                 {
                                                     1, 2, null
                                                 } });
         var com = command.Connection.Command;
         Assert.Equal("update top(1) Name = @Name where Age in (@Age0,@Age1,@Age2)", com.CommandText);
         Assert.Equal("1", com.Parameters["@Name"].Value);
         for (int i = 0; i < 3; i++)
         {
             var p = com.Parameters[$"@Age{i}"];
             if (i + 1 != 3)
             {
                 Assert.Equal(i + 1, p.Value);
             }
             else
             {
                 Assert.Equal(DBNull.Value, p.Value);
             }
             Assert.Equal(DbType.Int32, p.DbType);
         }
     }
 }
Beispiel #2
0
 public void TestExecuteEntity()
 {
     using (var command = new TestDataCommand())
     {
         command.ConnectionString = "sqlConnectionString";
         var s = command.ExecuteEntity <Student>(_Students[1]);
         _Test(_Students[0], s);
     }
 }
Beispiel #3
0
 public void TestExecuteDataReader()
 {
     using (var command = new TestDataCommand())
     {
         command.ConnectionString = "sqlConnectionString";
         var reader = command.ExecuteDataReader(_Students[0]);
         Assert.IsType <SetDataReader <Student> >(reader);
     }
 }
Beispiel #4
0
 public void TestBeginTransaction(IsolationLevel i)
 {
     using (var command = new TestDataCommand())
     {
         command.ConnectionString = "sqlConnectionString";
         var tran = command.BeginTransaction(i);
         Assert.Equal(i, tran.IsolationLevel);
     }
 }
Beispiel #5
0
        public async void TestExecuteNonQueryAsync()
        {
            using (var command = new TestDataCommand())
            {
                command.ConnectionString = "sqlConnectionString";
                var num = await command.ExecuteNonQueryAsync(_Students[2]);

                Assert.Equal(3, num);
            }
        }
Beispiel #6
0
 public void TestExecuteEntityList()
 {
     using (var command = new TestDataCommand())
     {
         command.ConnectionString = "sqlConnectionString";
         var ss = command.ExecuteEntityList <Student>(_Students[1]);
         Assert.Equal(_Students.Count, ss.Count);
         for (int i = 0; i < ss.Count; i++)
         {
             _Test(_Students[i], ss[i]);
         }
     }
 }
Beispiel #7
0
 public void TestExecuteScalarList()
 {
     using (var command = new TestDataCommand())
     {
         command.ConnectionString = "sqlConnectionString";
         var ss = command.ExecuteScalarList <DateTime?>(_Students[1]);
         Assert.Equal(_Students.Count, ss.Count);
         for (int i = 0; i < ss.Count; i++)
         {
             Assert.Equal(_Students[i].DateTime2, ss[i]);
         }
     }
 }
Beispiel #8
0
 public void TestExecuteNonQueryList()
 {
     using (var command = new TestDataCommand())
     {
         command.Text             = "update top(1) Name = @Name where Age = @Age";
         command.ConnectionString = "sqlConnectionString";
         var num = command.ExecuteNonQuerys(_Students);
         var com = command.Connection.Command;
         Assert.Equal("update top(1) Name = @Name0 where Age = @Age0;update top(1) Name = @Name1 where Age = @Age1;update top(1) Name = @Name2 where Age = @Age2;", com.CommandText);
         for (int i = 0; i < _Students.Count; i++)
         {
             Assert.Equal(_Students[i].Name, com.Parameters[$"@Name{i}"].Value);
             Assert.Equal(_Students[i].Age, com.Parameters[$"@Age{i}"].Value);
         }
     }
 }
Beispiel #9
0
 public void TestExecuteMultipleReader()
 {
     using (var command = new TestDataCommand())
     {
         command.ConnectionString = "sqlConnectionString";
         using (var reader = command.ExecuteMultiple(_Students[2]))
         {
             var s = reader.ExecuteEntity <Student>();
             _Test(_Students[0], s);
             var ss = reader.ExecuteEntityList <Student>();
             Assert.Equal(_Students.Count, ss.Count);
             for (int i = 0; i < ss.Count; i++)
             {
                 _Test(_Students[i], ss[i]);
             }
             var s1 = reader.ExecuteScalar <DateTime?>();
             Assert.Equal(_Students[0].DateTime2, s1);
         }
     }
 }
Beispiel #10
0
        public void TestAddPreParam()
        {
            var command = new TestDataCommand();
            var p       = new DataParameter()
            {
                ParameterName = "test"
            };

            command.PreParameters.Add(p);
            Assert.True(command.PreParameters.Contains(p));
            command.Text = "sql";
            Assert.Equal("sql", command.Text);
            command.ConnectionString = "sqlConnectionString";
            Assert.Equal("sqlConnectionString", command.ConnectionString);
            command.Timeout = 1003;
            Assert.Equal(1003, command.Timeout);
            Assert.Equal(CommandType.Text, command.Type);
            command.Type = CommandType.StoredProcedure;
            Assert.Equal(CommandType.StoredProcedure, command.Type);
        }