我有以下课程:
internal class House
{
public SafeHouse SafeHouseHandler { get; private set; }
internal House()
{
IntPtr nativP = NativeMethods.UnitType();
SafeHouseHandler = new SafeHouse(nativP);
}
}
和
public class SafeHouse : SafeHandleZeroOrMinusOneIsInvalid
{
public SafeHouse(IntPtr ownsHandle)
: base(true)
{
SetHandle(ownsHandle);
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
NativeMeth.Delete(handle);
return true;
}
}
我想编写一个测试来确保调用ReleaseHandle
:
测试:
[TestMethod]
public void SafeHouseTest()
{
var house = new House();
SafeHouse safeHouse = house.SafeHouseHandler;
Assert.AreNotEqual(IntPtr.Zero, safeHouse.DangerousGetHandle());
house = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.AreEqual(IntPtr.Zero, safeHouse.DangerousGetHandle());
}
结果:
Assert.AreEqual failed. Expected:<0>. Actual:<489437772>.
safeHouse
为什么0
在house = null
时没有返回$(function () {
$('.TEST').click(function () {
console.log($('.TEST').index(this));
});
});
?
如果我的测试方法是错误的,那么任何测试此类课程的建议都将受到赞赏。