tonerdo / pose

Replace any .NET method (including static and non-virtual) with a delegate
MIT License
1.07k stars 75 forks source link

Issue with DateTime.Now #68

Open MelbourneDeveloper opened 2 years ago

MelbourneDeveloper commented 2 years ago

I'm trying to get a basic sample working and I'm having difficulties. So, I added this test case to the existing unit tests:

[TestMethod]
public void TestReplace2()
{
    var expected = new DateTime(1999, 12, 31, 23, 59, 59);
    DateTime? actual = null;
    PoseContext.Isolate(() =>
    actual = DateTime.Now, Shim.Replace(() => DateTime.Now).
            With(() => expected));
    Assert.AreEqual(expected, actual.Value);
}

This fails. Am I doing something wrong, or is this a bug?

Assert.AreEqual failed. Expected:<31/12/1999 11:59:59 PM>. Actual:<25/10/2021 7:41:25 AM>.

Miista commented 5 months ago

@MelbourneDeveloper What version of Pose were you using?

As mentioned in tonerdo/Pose#79 there is a bug in versions above 1.1.0. Please see my comment there.

Please see my comment on #63