//没表数据库测试 public void DBDataControllerCheckTableTest() { DBDataController DBC = new DBDataController("user5", Environment.CurrentDirectory + "\\TestDB\\noTable.db"); DB_ERROR DBE = DBC.GetLastError(); Assert.AreEqual(DB_ERROR.DB_DATA_NOT_EXISTS, DBE);//返回数据不存在 }
//crack数据库测试 public void DBDataControllerCheckCrackTest() { DBDataController DBC = new DBDataController("user3", Environment.CurrentDirectory + "\\TestDB\\crack.db"); DB_ERROR DBE = DBC.GetLastError(); Assert.AreEqual(DB_ERROR.DB_TABLE_CRACK_FIX, DBE);//返回损坏并修复状态 }
//错误路径的构造方式 public void DBDataControllerCheckConnectTest() { DBDataController DBC = new DBDataController("user2", "/r/n"); DB_ERROR DBE = DBC.GetLastError(); Assert.AreEqual(DB_ERROR.DB_CANT_CONNECT, DBE);//数据库无法连接 }
//数据库StockHold读测试 public void DBDataControllerStockHoldTest() { File.Delete(Environment.CurrentDirectory + "\\Stock4.db"); DBDataController DBC = new DBDataController("user9", Environment.CurrentDirectory + "\\Stock4.db"); DB_ERROR DBE = DBC.GetLastError(); DealListEntity DLE = new DealListEntity(); DLE.id = "600001"; DLE.name = "邯郸钢铁"; DLE.money = 10.11; DLE.number = 400; DLE.type = "买入"; DBC.DealListAdd(DLE);//存入一条数据 DLE.id = "600001"; DLE.name = "邯郸钢铁"; DLE.money = 5.11; DLE.number = 200; DLE.type = "卖出"; DBC.DealListAdd(DLE);//再存入一条数据 List <StockHoldEntity> SHEL; DBC.StockHoldReadAll(out SHEL); Assert.AreEqual(1, SHEL.Count); Assert.AreEqual(DLE.id, SHEL[0].id); //判断读取与存入的数据是否一致 Assert.AreEqual(DLE.name, SHEL[0].name); Assert.AreEqual(200, SHEL[0].hold); //运算结果 Assert.AreEqual(3022, SHEL[0].money); //运算结果 }
//默认创建方式 检测数据库是否出现 public void DBDataControllerCreateTest() { File.Delete(Environment.CurrentDirectory + "\\Stock.db");//先移除默认数据库 DBDataController DBC = new DBDataController("user1", Environment.CurrentDirectory + "\\Stock.db"); DB_ERROR DBE = DBC.GetLastError(); Assert.AreEqual(DB_ERROR.DB_DATA_NOT_EXISTS, DBE); //正常返回数据不存在 Assert.IsTrue(File.Exists(Environment.CurrentDirectory + "\\Stock.db")); //检测数据库是否生成 }
//数据库Principal读写测试 public void DBDataControllerPrincipalTest() { File.Delete(Environment.CurrentDirectory + "\\Stock2.db"); DBDataController DBC = new DBDataController("user7", Environment.CurrentDirectory + "\\Stock2.db"); DB_ERROR DBE = DBC.GetLastError(); DBC.PrincipalCreate(100000000000000.00); Assert.AreEqual(100000000000000.00, DBC.PrincipalRead()); for (int i = 0; i < 100; i++) { double a = DBC.PrincipalRead(); double m = 12.34 * i; DBC.PrincipalChange(m); Assert.AreEqual((a + m).ToString(), DBC.PrincipalRead().ToString()); } }
//数据库DealList读写测试 public void DBDataControllerDealListTest() { File.Delete(Environment.CurrentDirectory + "\\Stock1.db"); DBDataController DBC = new DBDataController("user6", Environment.CurrentDirectory + "\\Stock1.db"); DB_ERROR DBE = DBC.GetLastError(); DealListEntity DLE = new DealListEntity(); DLE.id = "600001"; DLE.name = "邯郸钢铁"; DBC.DealListAdd(DLE);//存入一条数据 List <DealListEntity> DLEL; DBC.DealListReadAll(out DLEL); //读取 Assert.AreEqual(1, DLEL.Count); Assert.AreEqual(DLE.id, DLEL[0].id); //判断读取与存入的数据是否一致 Assert.AreEqual(DLE.name, DLEL[0].name); }
//数据库Log读写测试 public void DBDataControllerLogTest() { File.Delete(Environment.CurrentDirectory + "\\Stock3.db"); DBDataController DBC = new DBDataController("user8", Environment.CurrentDirectory + "\\Stock3.db"); DB_ERROR DBE = DBC.GetLastError(); LogEntity LE = new LogEntity(); LE.state = "状态"; LE.context = "错误内容"; DBC.LogSave(LE);//存入一条数据 List <LogEntity> LEL; DBC.LogRead(out LEL); //读取 Assert.AreEqual(1, LEL.Count); Assert.AreEqual(LE.state, LEL[0].state); //判断读取与存入的数据是否一致 Assert.AreEqual(LE.context, LEL[0].context); }