问题描述
是否存在Windows Phone 7的任何模拟框架,或者我需要手动创建伪造品?
Are there any mocking frameworks for Windows Phone 7 or do I need to create fakes manually?
我在google上没有找到任何内容,尽管我发现WP7资源页面上列出了Moq,但是我无法使它正常工作.
I've not found any on google, and although I found Moq listed on WP7 resources page, I couldn't get it working.
推荐答案
没有支持WP7的Mocking框架,我怀疑在WP7支持Reflection.Emit之前不会有.
There are no Mocking frameworks that support WP7 and I suspect there will never be any until WP7 supports Reflection.Emit.
在.net框架上,有创建模拟框架时存在的许多选项(Profiler API,CodeDem,Refleciton.Emit等).由于缺少很多BCL/CLR,因此大多数这些技术都无法在Silverlight本身上使用.所有现有的Silverlight模拟框架都使用Reflection.Emit. WP7不支持Reflection.Emit,因此任何Silverlight模拟框架都无法在WP7上运行.
On the .net framework there are many options that exist for the creation of a mocking framework (Profiler API, CodeDem, Refleciton.Emit, et al). The majority of these techniques won't work on Silverlight itself as it's missing quite a lot of the BCL/CLR. All existing Silverlight mocking frameworks use Reflection.Emit. WP7 does not support Reflection.Emit and thus no Silverlight mocking framework will work on WP7.
由于这个原因,我亲自在Silverlight运行时上测试WP7程序集.这远非最佳(很糟),但在这种情况下可以做到最好.
Because of that reason, I personally test WP7 assemblies on the Silverlight runtime. It's far from optimal (it sucks), but it's the best that can be done under the circumstances.
从理论上讲,可以构建一个使用Post-Build MSIL编织的Mocking框架,该框架应可在WP7上使用,但尚未完成.
One could theoretically build a Mocking framework that uses Post-Build MSIL weaving that should work on WP7, but it's yet to be done.
如果您希望WP7支持Reflection.Emit,请考虑就此uservoice问题进行投票: WP7应该支持Reflection.Emit for Mocking框架
If you'd like WP7 to support Reflection.Emit consider voting on this uservoice issue: WP7 should support Reflection.Emit for Mocking frameworks
编辑2/12/2011:芒果支持Refleciton.Emit.万岁!基于Reflection.Emit的模拟框架应该可以正常工作.
EDIT 2/12/2011: Refleciton.Emit is supported on Mango. Hooray! Reflection.Emit based Mocking frameworks should just work.
这篇关于Windows Phone 7模拟框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!