我经常可以识别出很多很好的封装区域和容易进行单元测试的区域,但我也发现很多代码在单元测试中看起来并不是很好 - 通常是数据访问和用户界面.无论我尝试使用哪种单元测试"技术",我都倾向于发现在这些地方创建功能单元测试不仅需要付出很多努力,而且这些测试往往非常脆弱,并且没有真正测试过.
您在什么时候停下来并决定单元测试的好处不值得花费?
我见过System.Transactions命名空间,并且想知道,我是否可以使用此命名空间使用实际生成RDMBS?
但是当我看到一些例子时,我不明白System.Transactions如何做除了简单的try catch以及获得成功/失败结果之外的任何事情?
这是MSDN网站上的示例,我知道它可能非常简单,但我无法理解此示例中的好处,有人可以告诉我以下示例中的简单try/catch和Transaction范围之间有什么区别.
如果我应该创建一个RDBMS(创建我自己的RDMBS),我知道我们必须将大量日志写入我们执行的操作的磁盘,最后我们在回滚的情况下撤消这些操作,但这里什么也没有关于撤消任何事情.
// This function takes arguments for 2 connection strings and commands to create a transaction
// involving two SQL Servers. It returns a value > 0 if the transaction is committed, 0 if the
// transaction is rolled back. To test this code, you can connect to two different databases
// on the same server by altering the connection string, or to another 3rd party RDBMS by
// altering the code in the …Run Code Online (Sandbox Code Playgroud) 我需要根据项目的配置将C#项目构建为WinExe或Library.
我试过这两种方法都没有运气:
1)在一般PropertyGroup中:
<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType>
<OutputType Condition=" '$(Configuration)' == 'Debug' ">Library</OutputType>
2)在条件PropertyGroup中:
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputType>WinExe</OutputType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputType>Library</OutputType>
</PropertyGroup>
这两种方法都不起作用,OutputType始终是WinExe.奇怪的是,如果我将WinExe的所有实例更改为库,那么它总是库.这让我觉得它正在成功地阅读它们,但要么是以奇怪的顺序,要么WinExe优先于图书馆.
有任何想法吗?
我需要实现SessionSecurityTokenCache才能在负载均衡的Web场中使用WIF.我可以使用这个类适合(例如基于SQL)的Web服务器实现,还是我真的需要创建自己的?
考虑一下,我有以下3个类/接口:
class MyClass<T> { }
interface IMyInterface { }
class Derived : IMyInterface { }
Run Code Online (Sandbox Code Playgroud)
我希望能够MyClass<Derived>投入一个MyClass<IMyInterface>或反之亦然:
MyClass<Derived> a = new MyClass<Derived>();
MyClass<IMyInterface> b = (MyClass<IMyInterface>)a;
Run Code Online (Sandbox Code Playgroud)
但是如果我尝试,我会遇到编译错误:
Cannot convert type 'MyClass<Derived>' to 'MyClass<IMyInterface>'
Run Code Online (Sandbox Code Playgroud)
我确信有一个很好的理由我不能这样做,但我想不出一个.
至于为什么我想这样做 - 我想象的场景是你理想地想要使用一个实例MyClass<Derived>以避免许多讨厌的演员,但是你需要将你的实例传递给接受的接口MyClass<IMyInterface>.
所以我的问题是双重的:
MyClass<Derived>同时仍然能够将其转换为MyClass<IMyInterface>?我正在尝试使用xslt生成一些C#代码 - 它工作得很好,直到我得到泛型并需要输出这样的文本:
MyClass<Type>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我发现发出此信息的唯一方法是执行以下操作:
MyClass<xsl:text disable-output-escaping="yes"><</xsl:text>Type<xsl:text disable-output-escaping="yes">></xsl:text>
Run Code Online (Sandbox Code Playgroud)
哪里:
<xsl:text />,但通常类型Type由其他模板给出,例如:<xsl:value-of select="@type" />
我不介意写<很多东西,但我想避免<xsl:text disable-output-escaping="yes"><</xsl:text>只为一个角色写作!
disable-output-escaping="yes"对整个文档有什么办法吗?
当我执行以下...
EXEC 'DROP TABLE bkp_anish_test'
Run Code Online (Sandbox Code Playgroud)
('DROP TABLE bkp_anish_test'是一个动态构建的SQL查询)
我收到了以下错误
找不到存储过程'DROP TABLE bkp_anish_test'.
我正在寻找一个可以在C#应用程序中使用的公式解释器.它需要能够解释这样的字符串:
max(1+2, 4) * x
Run Code Online (Sandbox Code Playgroud)
我发现编写一个快速的公式解释器(codeproject.com)几乎可以满足我的需要,但它不允许具有多个参数的函数.我可以添加它的功能,但我只是想知道这样的事情是否已经存在.
谢谢
我正在创建一个公开工具窗口的Visual Studio包,我正在尝试确保在首次加载包时它显示为停靠在Visual Studio主窗口的左边缘.
[ProvideToolWindow(typeof(MyToolWindow), Orientation = ToolWindowOrientation.Left,
Style=VsDockStyle.Linked, Window=EnvDTE.Constants.vsWindowKindLinkedWindowFrame)])]
[ProvideToolWindowVisibility(typeof(MyToolWindow), VSConstants.UICONTEXT.NoSolution_string)]
public class MyPackage : Package
{
...
Run Code Online (Sandbox Code Playgroud)
我已经尝试了上述的许多变体,但我设法实现的最好的是将窗口停靠在底部 - 即使这样,每次重新加载包时它都会继续重新对接而不是持久化用户窗口位置.
如何指定我的窗格最初显示为停靠在主窗口的左侧?
在VB.NET上我可以做这样的事情来写出缓存中的所有密钥:
Dim oc As HttpContext = HttpContext.Current
For Each c As Object In oc.Cache
oc.Response.Write(c.Key.ToString())
Next
Run Code Online (Sandbox Code Playgroud)
尽管.Key没有出现在Intellisense中,但代码运行得很好.
我如何在c#中做同样的事情?
HttpContext oc = HttpContext.Current;
foreach (object c in oc.Cache)
{
oc.Response.Write(c.key.ToString());
}
Run Code Online (Sandbox Code Playgroud)
它不喜欢.key.位.我在这里不知所措.有任何想法如何以这种方式访问密钥?
.net ×4
c# ×4
asp.net ×1
casting ×1
covariance ×1
csproj ×1
docking ×1
exec ×1
expression ×1
formula ×1
generics ×1
interpreter ×1
msbuild ×1
sql ×1
sql-server ×1
transactions ×1
unit-testing ×1
vb.net-to-c# ×1
vsx ×1
web-farm ×1
wif ×1
xslt ×1