Hello,
I need to mock the DateTime.Now static method in mscorlib. I've got it to work if it is in a non-static class.
(EXAMPLE CLASS)
(EXAMPLE WORKING TEST)
But, I need it to work on static class
(ANOTHER EXAMPLE)
But this time, JustMock complains:
That it cannot access static method "CheckForY2K" in non-static context.
What would the correct syntax be? I cannot find an example.
Lee
I need to mock the DateTime.Now static method in mscorlib. I've got it to work if it is in a non-static class.
(EXAMPLE CLASS)
class Program{ static void Main() { var results = new Program().CheckForY2K(); Console.WriteLine(results); Console.Read(); } internal bool CheckForY2K() { return DateTime.Now == new DateTime(2000, 1, 1); }}(EXAMPLE WORKING TEST)
[TestFixture]public class NuintTest{ static NuintTest() { Mock.Replace(() => DateTime.Now).In<Program>(x => x.CheckForY2K()); } [Test] public void TestY2K() { Mock.Arrange(() => DateTime.Now).Returns(new DateTime(2000, 1, 1)); var results = new Program().CheckForY2K(); Assert.IsTrue(results); }}But, I need it to work on static class
(ANOTHER EXAMPLE)
class Program{ static void Main() { var results = CheckForY2K(); Console.WriteLine(results); Console.Read(); } internal static bool CheckForY2K() { return DateTime.Now == new DateTime(2000, 1, 1); }}But this time, JustMock complains:
Mock.Replace(() => DateTime.Now).In<Program>(x => x.CheckForY2K());That it cannot access static method "CheckForY2K" in non-static context.
What would the correct syntax be? I cannot find an example.
Lee
