刚刚遇到了一些有趣的行为 - Assert被Catch阻挡了.
List<Decimal> consArray = new List<decimal>();
try
{
Decimal d;
Assert.IsTrue(Decimal.TryParse(item.Value, out d));
consArray.Add(d);
}
catch (Exception e)
{
Console.WriteLine(item.Value);
Console.WriteLine(e);
}
Run Code Online (Sandbox Code Playgroud)
断言投掷AssertFailedException和被抓住catch.一直认为如果Assert失败则测试失败并且连续执行被中止.但在那种情况下 - 测试继续进行.如果以后没有发生任何错误 - 我得到绿色测试!从理论上讲 - 这是正确的行为吗?
编辑:我明白可能是.NET限制以及如何在MsTest中进行断言.断言抛出异常.因为catch- 捕获它捕获断言异常的一切.但理论上是正确的还是具体的MsTest?
假设我有一些使用伪ORM的伪代码(在我的情况下,它是Linq2Db).
static IEnumerable<A> GetA()
{
using (var db = ConnectionFactory.Current.GetDBConnection())
{
return from a in db.A
select a;
}
}
static B[] DoSmth()
{
var aItems = GetA();
if (!aItems.Any())
return null;
return aItems.Select(a => new B(a.prop1)).ToArray();
}
Run Code Online (Sandbox Code Playgroud)
Connection什么时候关闭db?在那种情况下它会被关闭吗?将关闭什么连接 - 使用语句或lambda表达式中的连接?.NET编译器正在为lambdas创建匿名类,因此它将复制到该类的连接.什么时候关闭?
不知怎的,我设法得到了Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.物化查询,异常消失了.但我想知道这件事是如何运作的.
我有Coded-UI测试项目,它引用了解决方案中的其他程序集.某些程序集不会被复制到TestResults/Out目录,而其他程序集则被复制.所有程序集都有Copy Local选项true(不知道它是否真的重要),并且在其他选项中绝对相同.当我从VS2010本地开始测试时,所有程序集都被复制,但在构建服务器上则没有.
如果我使用[DeploymentItem]属性来强制部署这些"顽皮"的程序集,那么它们就会成功部署.
我无法得到它 - 我一直认为,如果你引用程序集(在References部分Solution Explorer),程序集将被复制到TestResults/Out并[DeploymentItem]需要复制一些.xml和其他配置文件.
当引用存储在基类变量中时,这个问题与CLR如何调用派生类正确隐藏的方法有关?
在我的情况下,我正在使用callvirt 指令,而不是call
class BaseClass
{
public void Write()
{
Method();
}
protected virtual void Method()
{
Console.WriteLine("Base - Method");
}
}
class DerivedClass : BaseClass
{
private new void Method()
{
Console.WriteLine("Derived - Method");
}
}
static void Main(string[] args)
{
DerivedClass dc = new DerivedClass();
BaseClass bcdc = new DerivedClass();
dc.Write();
bcdc.Write();
Console.ReadKey(true);
}
Run Code Online (Sandbox Code Playgroud)
输出:
Base - Method
Base - Method
Run Code Online (Sandbox Code Playgroud)
IL代码Write方法:
.method public hidebysig instance void Write() cil managed
{
// …Run Code Online (Sandbox Code Playgroud) 我正在努力研究ngen和泛型集合.我已经在解决方案中使用了所有程序集,但是每当我的应用程序执行该代码时,仍会以某种方式进行jitting:
private Dictionary<int, bool> VerifyedFunc;
public SecurityProvider()
{
...
VerifyedFunc = new Dictionary<int, bool>();
...
}
Run Code Online (Sandbox Code Playgroud)
MDA消息:
Managed Debugging Assistant 'JitCompilationStart' has detected a problem in '*.exe'.
Additional Information:
<mda:msg xmlns:mda="http://schemas.microsoft.com/CLR/2004/10/mda">
<mda:jitCompilationStartMsg break="true">
<method name="mscorlib!System.Collections.Generic.Dictionary`2::.ctor"/>
</mda:jitCompilationStartMsg>
</mda:msg>
Run Code Online (Sandbox Code Playgroud)
NGen和泛型集合是否存在一些问题?