Using Moles with DateTime

痞子三分冷 提交于 2019-11-30 22:01:08
Jeco

For Moles of mscorlib, you need to right-click directly on the References of your test project. You will have Add Moles Assembly for mscorlib. Then, add using System.Moles;to your test class because you want Moles of System.DateTime (actually, you need a little more).

[TestMethod()]
[HostType("Moles")]
public void DateTimeMolesTest()
{
    DateTime date = new System.DateTime(2000, 1, 1, 2, 3, 4, 5);
    MDateTime.NowGet = () => date;
    Assert.AreEqual(date, DateTime.Now);
}

If you run this test, it will fail because you need to add:

using Microsoft.Moles.Framework;
[assembly: MoledType(typeof(System.DateTime))]

Then, your test will succeed. Don't forget that Moles cannot be used with some special types of mscorlib.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!