|
|
@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
using Shouldly.Configuration;
|
|
|
|
|
|
|
|
using Shouldly.ShouldlyExtensionMethods;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using AccessStudy.Core;
|
|
|
|
|
|
|
|
using System.Data.OleDb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace AccessStudy.CoreTest
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public class OleDbUtilTest:IDisposable
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly OledbUtil _dbUtil;
|
|
|
|
|
|
|
|
public OleDbUtilTest()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_dbUtil = new OledbUtil();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void DbUtil_NotNull_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Assert.NotNull(_dbUtil);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void DbConnet_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var con = _dbUtil.DbConnection;
|
|
|
|
|
|
|
|
Assert.NotNull(con);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Action action = () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
con.Open();
|
|
|
|
|
|
|
|
con.Close();
|
|
|
|
|
|
|
|
con.Dispose();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//throw new Exception("特意抛出的异常!");
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Should.NotThrow(action);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void DataSet_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var ds = _dbUtil.GetDataSet("Student");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(ds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(ds.Tables);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(ds.Tables.Count>0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void DataTable_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dt = _dbUtil.GetDataTable("Student");
|
|
|
|
|
|
|
|
Assert.NotNull(dt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void DataReader_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Action action = () =>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dataReader = _dbUtil.GetDataReader("Student");
|
|
|
|
|
|
|
|
while (dataReader.Read())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dataReader.Close();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Should.NotThrow(action);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void Scalar_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var sqlText = @"select count(*) as Total from Student where Age>@Age;";
|
|
|
|
|
|
|
|
List<OleDbParameter> paras = new List<OleDbParameter>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
new OleDbParameter("Age",1),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var total = (int)_dbUtil.GetScalar(sqlText, paras);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(total >= 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void NonQuery_Test()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var sqlText = @"update Student Set Age=Age+1 where Age>@Age and Name <>@Name;";
|
|
|
|
|
|
|
|
List<OleDbParameter> paras = new List<OleDbParameter>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
new OleDbParameter("Age",1),
|
|
|
|
|
|
|
|
new OleDbParameter("Name","王高峰"),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var total = _dbUtil.ExecuteNonQuery(sqlText, paras);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(total >= 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|