六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

單元測試輔助類

[摘要]下面是數據文本文件的格式 “#”號是注釋“T:”是加入“D:”是刪除表里面的數據“C:”是檢查數據數據與數據之間用TAB隔開(可以從企業管理器直接把數據拷貝出來作為數據源)加入數據的事列如下:#插入用戶表# null為插入空T:UsersJohn <TAB>John chanCake&...
  下面是數據文本文件的格式

“#”號是注釋

“T:”是加入

“D:”是刪除表里面的數據

“C:”是檢查數據

數據與數據之間用TAB隔開(可以從企業管理器直接把數據拷貝出來作為數據源)

加入數據的事列如下:

#插入用戶表
# null為插入空
T:Users
John <TAB>John chan
Cake<TAB>Cake.lu
jeff<TAB>jeff.hu

# CheckTable's Data
#null為檢查是否為空,skip掉過不檢查,notnull檢查他是否不為空
C:Users
John <TAB>John chan
Cake<TAB>Cake.lu
jeff<TAB>jeff.hu

#Delete All Data
D:TAbleName

調用代碼:
參數1:文本文件的路徑
參數2:是Helper里面的兩個常量(其實可以是個Enum,不過寫的時候沒有注意)
Helper.ExecuteAction("Data.txt",Helper.INSERT);

參數3:是指定對那個對象操作(T:D:C:后面的名稱,如T:Users,那么就填Users)
Helper.ExecuteACtion("Data.txt",Helper.Insert,"Users")

代碼如下:

using System;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using NUnit.Framework;

namespace TestCore
{
 
 public class Helper
 {
  public const string DELETE="D";
  public const string INSERT="T";
  public const string CHECK="C";
  public const string ANNOTATE="#";
  
  public static string ConnectionString
  {
   //這里要寫返回的連接字符串
   get{return null;}
  }
  public static void ExecuteAction(string path,string action)
  {
   ExecuteAction(path,action,null);
  }
   
  public static void ExecuteAction(string path,string action,string inputTable)
  {
   Console.WriteLine("----------------"+action+" action is Start--------------------");
   
   StreamReader reader=new StreamReader(path);
   string line;
   string table=null;
   try
   {
    while(true)
    {
     line =reader.ReadLine();
     if(line==null)
      break;
     
     if(line.Length==0)
      continue;
     string Key=line.Substring(0,1);
     if(Key==action)
     {
      table=line.Substring(2);
      if(action==DELETE)
      {
       if(CheckTable(inputTable,table))
       {
        Delete(table);
       }
       table=null;
      }
      else
      {
       continue;
      }
     }
     else if(table!=null)
     {
      switch(action)
      {
       case INSERT:
        if(CheckTable(inputTable,table))
        {
         string[] datas=line.Split('\t');
         AddData(datas,table);
        }
        break;
       case CHECK:
        if(CheckTable(inputTable,table))
        {
         string[] checkDatas=line.Split('\t');
         Check(checkDatas,table);
         
        }
        break;
      }
      table =null;
     }
     else
     {
      continue;
     }
    }
   }
   finally
   {
    Console.WriteLine("----------------"+action+" action is End--------------------");
    reader.Close();
   }
  }
  private static bool CheckTable(string inputTable,string SettingTable)
  {
   if(inputTable==null)
    return true;
   return (inputTable==SettingTable);
  }
 
  private static void Delete(string table)
  {
   string sql=" delete from "+table;
   Console.WriteLine(sql);
   try
   {
    SqlHelper.ExecuteNonQuery(ConnectionString,CommandType.Text,sql);
   }
   catch(Exception e)
   {
    throw new ApplicationException("刪除錯誤:Sql是"+sql,e);
   }
  }
  private static void AddData(string[] data,string table)
  {
   SqlConnection conn=new SqlConnection(ConnectionString);
   string sql="insert into "+table+" values ";
   string temp="('"+data[0]+"'";
   for(int i=1;i<data.Length;i++)
   {
    if(data[i]!="null")
     temp+=",'"+data[i]+"'";
    else
     temp+=",null";
   }
   sql+=temp+")";
   conn.Open();
   try
   {

    Console.WriteLine(sql);
    SqlCommand comm =new SqlCommand(sql,conn);
    comm.ExecuteNonQuery();
   }
   catch(Exception e)
   {
    throw new ApplicationException(table+":"+sql,e);
   }
   finally
   {
    conn.Close();
   }
  }
  private static void Check(string[] data,string table)
  {
   string sql="select * from "+table;
   Console.WriteLine(sql);
   DataSet ds = SqlHelper.ExecuteDataset(Helper.ConnectionString,CommandType.Text,sql);
   DataTable dt=ds.Tables[0];
   
   if(dt.Rows.Count==0)
    throw new ArgumentOutOfRangeException( sql+" 返回結構為空");

   foreach(DataRow dr in dt.Rows)
   {
    for(int i=0;i<data.Length;i++)
    {
     if(data[i].ToLower()=="skip")
      continue;
     if(data[i].ToLower()=="null")
     {
      Assert.IsTrue(dr[i].Equals(DBNull.Value),"expect is null ,but it's not null actualy");
      continue;
     }
     if(data[i].ToLower()=="notnull")
     {
      Assert.IsFalse(dr[i].Equals(DBNull.Value),"expect isn't null but it's null actualy");
      continue;
     }
     if(data[i].Length>=4 && data[i].Substring(0,4).ToLower()=="not:")
     {
      string txtValue=data[i].Substring(4).ToLower().Trim();
      string dbValue=dr[i].ToString().ToLower().Trim();
      Assert.IsTrue(txtValue!=dbValue,"db value is the same as data in text file,text file value is "+txtValue);
      continue;
     }

     if(dr[i].ToString().Length!=0 dr[i].Equals(DBNull.Value))
     {
      Assert.IsTrue(dr[i].ToString()==data[i],table+":Check Value Is "+data[i]+",but DB is "+dr[i]);
      continue;
     }
    }
   }
  }
 }
}





主站蜘蛛池模板: 人碰人操 | 亚洲a在线播放 | 亚洲国产成人久久一区www | 亚洲精品免费观看 | 日韩中文字幕久久精品 | 欧美特黄特色aaa大片免费看 | 欧美特黄一级大黄录像 | 日本韩国三级在线 | 色综合天天综合中文网 | 中文天堂最新版www官网在线 | 一级毛片女学护士 | 中文字幕福利片 | 欧美在线视频你懂的 | 日本成人小视频 | 欧美午夜色大片在线观看免费 | 欧美在线看片 | 午夜视频高清在线aaa | 亚洲爱婷婷色婷婷五月 | 一级毛片a女人刺激视频免费 | 亚洲香蕉中文网 | 日韩精品成人a在线观看 | 色黄网站| 日韩在线观看一区二区三区 | 亚洲天堂免费视频 | 日本高清视频不卡 | 在线视频一区二区 | 日韩一区二三区无 | 性欧美一级 | 日韩欧美高清 | 四虎永久在线精品2022 | 日本免费在线视频 | 三级黄色免费片 | 亚洲欧洲日本在线 | 日日干干 | 亚洲欧美第一 | 天天晚上干白天干 | 思思久久96热在精品国产免费 | 日本一本在线 | 亚洲伊人成综合人影院小说 | 五月综合激情视频在线观看 | 日本一本在线播放 |