开发者

Windows Phone 7.1, Silverlight NUnit Project -template and Moq: TypeLoadException

it's time to do some unit testing with MVVM Light ViewModels.

Setup:

  • Visual Studio 2010 SP 1
  • Windows Phone 7.1 SDK Release Candidate
  • Silverlight NUnit Project -template
  • Moq (4.0.10827 Final)

Steps:

  1. Create a new MvvmLight (WP7) -project
  2. Convert project to WP7.1
  3. Create a new Silverlight NUnit -project
  4. Reference WP7-project to Silverlight NUnit -project
  5. Add a dummy method to the MainViewModel (f.ex. public string DoSomething())
  6. Add a test that instantiates MainViewModel, calls the dummy method and asserts.
  7. Run tests -> everything should work as expected
  8. Add reference to Moq
  9. Add second test method with some Moq. I simply copy-pasted this demo code from Moq's site:

    var mock = new Mock();

    // WOW! No record/replay weirdness?! :) mock.Setup(framework => framework.DownloadExists("2.0.0.0")) .Returns(true) .AtMostOnce();

    // Hand mock.Object as a collaborator and exercise it, // like calling methods on it... ILoveThisFramework lovable = mock.Object; bool download = lovable.DownloadExists("2.0.0.0");

    // Verify that the given method was indeed called with the expected value mock.Verify(framework => framewo开发者_JAVA技巧rk.DownloadExists("2.0.0.0"));

  10. Run tests.

This is what i get via NUnit runner at step 9:

SilverlightNUnitProject2.SilverlightTests.TestSomething:
System.TypeLoadException : Could not load type 'System.Action' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Question:

What is going on here? Which part of my setup is failing and why?

Update!

I found a blog post related to this problem here. This inspired me to download and try the exactly same version of Moq (3.1.416.3) used in that article. And whaddayouknow? It works.

I'm not going to put this up as an answer, because i still don't know what's going on here. Original question still stands, i think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜