Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTime.Now returning incorrect value #38

Open
BermudaLamb opened this issue Oct 11, 2018 · 3 comments
Open

DateTime.Now returning incorrect value #38

BermudaLamb opened this issue Oct 11, 2018 · 3 comments

Comments

@BermudaLamb
Copy link

        var consoleShim = Shim.Replace(() => Console.WriteLine(Pose.Is.A<string>())).With(
            delegate (string s) { Console.WriteLine("Hijacked: {0}", s); });
        var shimDate = new DateTime(2014, 4, 4);
        Console.WriteLine(shimDate);
        var dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => shimDate);
        PoseContext.Isolate(() =>
        {
            Console.WriteLine("Hello World!");
            var dt = DateTime.Now;
            Console.WriteLine(dt);
            Console.WriteLine(DateTime.Now);
        }, consoleShim, dateTimeShim);

Test is returning: 4/18/D1935668524 3:40:45 AM

@devedse
Copy link

devedse commented Oct 11, 2018

You're mocking Console.WriteLine(string). However you're providing a DateTime to the Console.WriteLine class.
I expect this will call Console.WriteLine(object). It basically means you have to mock that one.

@BermudaLamb
Copy link
Author

This is a near direct copy of the README example on the primary page .. According to that:

  // Outputs "Hijacked: Hello World!"
   Console.WriteLine("Hello World!");

   // Outputs "4/4/04 12:00:00 AM"
   Console.WriteLine(DateTime.Now);

Even though it is within my PoseContext.Isolate() the string writing is working as expected. However, the shim for the DateTime is returning a junk date, rather than the expected "4/4/04 12:00:00 AM"

@Tarig0
Copy link

Tarig0 commented Oct 26, 2018

what happens if you construct the datetime in the shim? I think there may be a memory access issue when you use a variable from outside a shim.

Miista added a commit to Miista/pose that referenced this issue Jan 25, 2024
Release v2.0 to NuGet

Version 2.0 supports the following targets:
* .NET Standard 2.0
* .NET Core 2.0
* .NET Core 3.0
* .NET Framework 4.8
* .NET 7
* .NET 8

Version 2.0 fixes the following issues:
* tonerdo/pose#17
* tonerdo/pose#37
* tonerdo/pose#38
* tonerdo/pose#41
* tonerdo/pose#47
* tonerdo/pose#49
* tonerdo/pose#60
* tonerdo/pose#67
* tonerdo/pose#68
* tonerdo/pose#70
* tonerdo/pose#71
* tonerdo/pose#72
* tonerdo/pose#75
* tonerdo/pose#79
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants