2016-11-02 15:35:25 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2016-11-01 20:48:07 +08:00
|
|
|
|
using System.Data.Common;
|
2016-11-02 15:35:25 +08:00
|
|
|
|
using System.Data;
|
2016-10-28 16:57:27 +08:00
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class LogHelperTests
|
|
|
|
|
{
|
2016-11-01 20:48:07 +08:00
|
|
|
|
private Log Log { get; set; }
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Initialized()
|
|
|
|
|
{
|
2016-11-02 15:35:25 +08:00
|
|
|
|
Log = new Log() { OperationType = 1, UserName = "_测试用户名称_", OperationTime = System.DateTime.Now, OperationIp = "0.0.0.0",Remark="" };
|
2016-11-01 20:48:07 +08:00
|
|
|
|
}
|
|
|
|
|
[TestCleanup]
|
|
|
|
|
public void CleanUp()
|
|
|
|
|
{
|
2016-11-02 15:35:25 +08:00
|
|
|
|
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "delete from Logs where UserName='_测试用户名称_'"))
|
2016-11-01 20:48:07 +08:00
|
|
|
|
{
|
|
|
|
|
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-28 16:57:27 +08:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void RetrieveLogsTest()
|
|
|
|
|
{
|
2016-11-01 21:03:11 +08:00
|
|
|
|
Assert.IsTrue(LogHelper.RetrieveLogs().Count() >= 0, "带有参数的LogHelper.RetrieveLogs方法调用失败,请检查数据库连接或者数据库SQL语句");
|
2016-10-28 16:57:27 +08:00
|
|
|
|
}
|
|
|
|
|
[TestMethod]
|
2016-11-01 21:03:11 +08:00
|
|
|
|
public void SaveLogTest()
|
2016-10-28 16:57:27 +08:00
|
|
|
|
{
|
2016-11-02 15:35:25 +08:00
|
|
|
|
Assert.IsTrue(LogHelper.SaveLog(Log), "新增日志信息出错,请检查LogHelper的SaveLog 方法");
|
2016-11-01 20:48:07 +08:00
|
|
|
|
var logs = LogHelper.RetrieveLogs();
|
2016-11-02 15:35:25 +08:00
|
|
|
|
Assert.IsTrue(logs.Count() > 0, "新增日志信息出错,请检查LogHelper的SaveLog 方法");
|
2016-10-28 16:57:27 +08:00
|
|
|
|
}
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void DeleteLogTest()
|
|
|
|
|
{
|
2016-11-01 20:48:07 +08:00
|
|
|
|
// 先判断数据环境是否可以删除,没有数据先伪造数据
|
2016-11-02 15:35:25 +08:00
|
|
|
|
var log = LogHelper.RetrieveLogs().FirstOrDefault(l => l.UserName == Log.UserName);
|
2016-11-01 21:03:11 +08:00
|
|
|
|
if (log == null) LogHelper.SaveLog(Log);
|
2016-11-02 15:35:25 +08:00
|
|
|
|
log = LogHelper.RetrieveLogs().FirstOrDefault(l => l.UserName == Log.UserName);
|
2016-11-01 20:48:07 +08:00
|
|
|
|
Assert.IsTrue(LogHelper.DeleteLog(log.ID.ToString()), "删除日志信息出错");
|
2016-10-28 16:57:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|