我们有单元测试来测试我们的数据库安装和卸载功能是否成功运行.单元测试使用SqlClient.SqlConnection类检查之前,期间和之后的数据库内容.
我们的问题是在使用SqlClient.SqlConnection之后,卸载的drop login部分失败,因为它声称用户当前已登录.即使我们调用了SqlConnection.Close(),登录似乎仍然是打开的.
我们的代码看起来有点像这样:
InstallTables(); // function uses smo to create tables in a database.
string connString = CreateLogin("userName", "password"); // create login with smo
// Test the returned connection string connects to the database
using (SqlConnection con = new SqlConnection(connString))
{
con.Open();
//test code to read the DB version out of a table
//Dispose calls con.Close() - I have also tried calling it explicitly
}
DropTables(); // uses smo to drop tables from the database …Run Code Online (Sandbox Code Playgroud) 我们数据库中的架构名称是动态的。为什么以下不起作用?
public void ReadVersion(string connString, string schemaName)
{
string selectCommand = "SELECT major FROM [@SchemaName].[version]");
using (SqlConnection sqlConn = new SqlConnection(connString))
{
using (SqlCommand cmd = new SqlCommand(selectCommand, sqlConn))
{
sqlConn.Open();
cmd.Parameters.AddWithValue("@SchemaName", schemaName);
object result = cmd.ExecuteScalar();
}
}
}
Run Code Online (Sandbox Code Playgroud)
执行命令时,参数值不被替换。这是 SqlCommand 参数的限制吗?
背景:
我们有一个Windows安装程序,只需安装并启动我们的自定义WinForms安装程序.此自定义安装程序执行实际安装:创建IIS Web应用程序,复制dll,安装数据库等...
我们现在想要编写一些自动验收测试,其中包括使用与我们在生产中使用相同的安装程序来安装软件.我们希望每天晚上在专用机器上运行验收测试,然后作为持续集成管道的一部分.
问题:
事实证明,自动化WinForms安装程序很困难.我们不需要特殊的安装代码进行验收测试.
题:
您有多聪明的建议将部署过程集成到自动化测试中?
我怀疑使用WinForms作为安装程序的决定是一个糟糕的选择 - 特别是因为生成的应用程序没有明确地将UI代码与真正的安装代码分开.
installer continuous-integration windows-installer winforms continuous-deployment
我使用字典类实现了一个简单的缓存:
private Dictionary<int, byte[]> cache = new Dictionary<int, byte>();
public void SetPicture(int id, byte[] bytes)
{
cache[id] = bytes;
}
public byte[] GetPicture(int id)
{
if (cache.Contains(id)) {
return cache[id];
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
SetPicture仅从单个后台线程调用.(此后台线程正在从活动目录查询更新用户配置文件图片).
从多个其他线程(处理http请求的线程)调用GetPicture.
永远不会从缓存中删除项目.
这段代码线程安全吗?或者我是否需要在SetPicture中写入内部词典时阻止访问内部词典?