Microsoft Moles sample won't work
-
Tuesday, December 13, 2011 1:17 PM
HI,
I'm using VS2010, .Net 4.0 on a Windows 7 x64bit version.
I have downloaded the sample Y2kMoles from here (http://research.microsoft.com/en-us/projects/pex/y2kmoles.zip), but i can't get it to work.
[TestMethod] [HostType("Moles")] public void Y2k() { MDateTime.NowGet = () => new DateTime(2000,1,1); if(DateTime.Now == new DateTime(2000,1,1)) throw new Exception("y2k bug!!!!"); }
I keep getting the following error: "Skipping test with HostType attribute.".Any idea??
/Peter
(I understand that this isn't just straightforward to answer, but I believe I have read somewhere, that MS staff would answer/comment on any post (if no other do) within 2 days ?)
- Edited by Peter Larsen [CPH] Monday, December 19, 2011 10:25 AM
All Replies
-
Thursday, December 22, 2011 9:01 PMI'm not an expert on this sample, but I will go find one. Could someone else take a crack at this question? Thanks!
Ed Price a.k.a User Ed, Microsoft Experience Program Manager (Blog, Twitter, Wiki)
- Edited by Ed Price - MSFTMicrosoft Employee Friday, January 06, 2012 6:36 PM
-
Friday, December 23, 2011 3:41 AM
Might want to try this link.
-
Friday, December 23, 2011 8:35 AM
Might want to try this link.
Thanks for your comment - unfortunately this link is related to loading from the app.config.
Maybe this is not about Moles, but about the HostType attribute. What does the error (Skipping test with HostType attribute) mean and what is the reason for this to happening - and finally - why does the error occur when using Moles ?
Thank you in advance.
-
Thursday, December 29, 2011 7:44 AM
I tried the sample, when run it in VS 2010, it prompt me to add “[assembly: MoledType(typeof(System.DateTime))]”, however, below code works well on my side, the Y2k() method get executed successfully.
using System;
using System.Moles;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Moles.Framework;
[assembly: MoledType(typeof(System.DateTime))]
namespace Y2kMoles
{
[TestClass]
public class Y2kTest
{
[TestMethod]
[HostType("Moles")] // add this attribute
public void Y2k()
{
MDateTime.NowGet = () => new DateTime(2000,1,1);
if(DateTime.Now == new DateTime(2000,1,1))
throw new Exception("y2k bug!!!!");
}
}
}
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Regards,
Eric Yang
Microsoft Online Community Support- Marked As Answer by Forrest GuoModerator Wednesday, January 11, 2012 3:57 AM
-
Thursday, December 29, 2011 9:17 AM
I tried the sample, when run it in VS 2010, it prompt me to add “[assembly: MoledType(typeof(System.DateTime))]”, however, below code works well on my side, the Y2k() method get executed successfully.
Hi Eric,
Thanks for your comment, but I have just downloaded the sample and run it - no changes, no nothing, but it doesn't work.
Is it the way I have installed moles or what is it that cause the method to be skipped because HostType is added ??
/Peter
-
Friday, January 06, 2012 6:51 AM
Hi Peter,
Did you try "ASP.NET" host type? as the example in this document: http://msdn.microsoft.com/en-us/library/ms243351.aspx
The constructor of HostTypeAttribute class cannot be used by partially trusted code, you can use below method to check the trust level of the executing assembly:
[TestMethod]
public void TestTrustLevel()
{
bool isFullTrusted = Assembly.GetExecutingAssembly().IsFullyTrusted;
if (isFullTrusted == false)
{
throw new Exception(Assembly.GetExecutingAssembly().FullName + " ==> is partially trusted.");
}
}
You may also create a new test project, and use [HostType("Moles")] in a test method, will same error occur?
By the way, I’m using Moles of version 0.94.51023.0.
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Regards,
Eric Yang
Microsoft Online Community Support -
Monday, January 09, 2012 8:26 AM
Hi Erik,
The versions i have is: mscorlib.Moles.dll = 4.0.30319.239, mscorlib.Behaviors.dll = 0.94.51023.0.
Using APS.NET host type, doesn't change anything, I still get the "Skipping test with HostType attribute" error - But since setting the host type always fail,i guess it hasn't anything to do with moles, right ??
IsFullTrusted return true.
Thanks
BR
Peter
-
Tuesday, January 10, 2012 2:17 AM
Hi Peter,
Did you try the project on another machine? will the same issue reproduce?
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Regards,
Eric Yang
Microsoft Online Community Support -
Tuesday, January 10, 2012 12:12 PM
Hi Eric,
I have got it to work by reinstalling Moles .... (?)
This also fixed the problem running Moles with NUnit.
This work with MSTest:
[TestMethod] [HostType("Moles")] public void Y2k() { MDateTime.NowGet = () => new DateTime(2000, 1, 1); if (DateTime.Now == new DateTime(2000, 1, 1)) throw new Exception("y2k bug!!!!"); }and this work on NUNIT:
[Test] public void Y2kWithNunit() { using (MolesContext.Create()) { MDateTime.NowGet = () => new DateTime(2000, 1, 1); if (DateTime.Now == new DateTime(2000, 1, 1)) throw new Exception("y2k bug!!!!"); } }For both tests, "[assembly: MoledType(typeof(DateTime))]" is required - as you said earlier.I Appreciate your help.
BR
Peter
- Marked As Answer by Forrest GuoModerator Wednesday, January 11, 2012 3:56 AM
-
Wednesday, January 11, 2012 3:43 AM
Hi Peter,
Glad to hear the you got it resolved! seems the installation of Moles is corrupted, anyway, congratulations:)
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Regards,
Eric Yang
Microsoft Online Community Support

