Exemple #1
0
        public void ExecuteScalarTest()
        {
            string _sql = @"SELECT p.UserName
            FROM dbo.Person p
            WHERE p.Age = @Age;";

            Assert.IsNotNull(sqlHelper.ExecuteReader(_sql, new { Age = 1 }));
            Assert.IsNotNull(sqlHelper.ExecuteReader(_sql, new Person {
                Age = 1
            }));
            _sql = @"SELECT p.UserName
            FROM dbo.Person p
            WHERE p.Age = 1;";
            Assert.IsNotNull(sqlHelper.ExecuteReader(_sql));
        }
 public void ExecuteReaderTest()
 {
     using (IDataReader reader = sqlHelper.ExecuteReader("SELECT  [id],[username],[password],[age],[registerDate],[address] FROM [Person] where id=@id", new Person()
     {
         id = 5
     }))
     {
         while (reader.Read())
         {
             Assert.AreEqual(5, reader.GetInt32(0));
         }
     }
 }