Mole Framework:静态只读属性为null

Mole Framework:静态只读属性为null

问题描述:



为了删除外部依赖项以进行测试,我试图实现鼹鼠框架



一切正常直到我用静态只读属性来训练这个类。



创建该类的痣不是问题的根本原因但是只读属性正在创建问题



在我的实际方法中使用readonly属性,并且在创建mole实例之后该属性的值为null

因为没有setter,getter for这个属性所以鼹鼠类没有给这个属性覆盖



然而没有鼹鼠测试用例没有给出错误并从外部来源获取数据



请在这种情况下建议如何处理



提前致谢

Hi,
In order to remove external dependency for testing purpose i was trying to implement the mole framework

everything was working fine until i have moled the class with static readonly property.

Creating mole of that class is not the root cause of issue but that readonly property is creating the issue

in my actual method that readonly property is used and value of that property is coming null after creating mole instance
since there is not setter, getter for this property so mole class is not giving override for this property

However without mole testcase is not giving error and fetching the data from external sources

Please suggest how to proceed in this case

Thanks in advance

您可以尝试使用 MolesEraseStaticConstructor

更多相关信息 - http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf [ ^ ]。
You could try using the MolesEraseStaticConstructor.
More about it here - http://research.microsoft.com/en-us/projects/pex/molesmanual.pdf[^].


很抱歉迟到的回复...



但不适合我....

我刚刚对代码进行了重新考虑并更改了我的代码,以便它可以被移动。



但是我仍然找不到适合这个问题的解决方案...



谢谢...
Sorry for late reply...

but not working for me....
I just re factored the code and changed my code such that it can be moled.

But still i didn't find proper solution for this problem...

Thanks...


我已经去过很多文章和讨论,但没有找到任何完美的解决方案。

所以现在考虑到不可能覆盖密封类的私有只读静态属性。 (是的,在我的情况下,班级密封......)



所以我决定改变班级设计然后痛苦消失了。



感谢您的帮助。
I have gone for many articles and discussions but did not found any perfect solutions.
So for now considering that it is not possible to override the private read only static properties of a sealed class. (Yes in my case, class sealed...)

So i have decided to change the design of class and then pain was gone.

Thanks for your help.