chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi, mocking DateTime.Now doesn't work for me.

Here's the code
class Timer
{
    public void Tick()
    {
        if (DateTime.Now == DateTime.MaxValue)
            throw new Exception("End of time!");
    }
}

[TestFixture]
public class MyTests
{
    [Test, Isolated]
    public void TestTimer()
    {
        Isolate.WhenCalled(() => DateTime.Now).WillReturn(DateTime.MaxValue);

        var timer = new Timer();
        timer.Tick();//should throw
    }
}


And here's the exception:
------------------------------------------
TypeMock.TypeMockException :
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake mscorlib type?
------------------------------------------

I'm using Typemock 5.3.5
asked by andreister (3.4k points)

9 Answers

0 votes
Hi,

I run the test you posted and got the expected results.

Can you give me more details about your system?
Did you have a previous version of the Isolator installed?
Are you running on 64 bit machine?
answered by ohad (35.5k points)
0 votes
Hi Ohad, thanks for the quick answer.

I use 32x Vista, no other Isolator versions installed. Run tests via R#
answered by andreister (3.4k points)
0 votes
What is the of your test assembly? does it begins with "nunit" ?
answered by dhelper (11.9k points)
0 votes
Assembly name is IsolatorTests.

Do you want me to send the project so that you can check if it works for you? Is it possible something I have installed breaks Isolator?
answered by andreister (3.4k points)
0 votes
Doh!

Running via tmockrunner works as expected. Such a relief!

Is it something you would fix or should I contact R#? :)
answered by andreister (3.4k points)
0 votes
Unfortunately, more details on that.

Even with tmockrunner, first time the test works as expected, but if I rebuild the project and re-run the test (from Nunit GUI, without restarting the GUI), I'm still getting

IsolatorTests.ComplicatedTests.TestTimer:
An unexpected exception type was thrown
Expected: System.Exception
but was: TypeMock.TypeMockException :
*** No method calls found in recording block. Please check:
* Are you trying to fake a field instead of a property?
* Are you are trying to fake mscorlib type?
answered by andreister (3.4k points)
0 votes
I would like to investigate this issue and I can really use a reproduction of the issue - let's take it offline
answered by dhelper (11.9k points)
0 votes
I'm having a similar issue running previously-working tests after upgrading from 5.4.2 to 5.4.3 (evaluation). Any idea what is causing this?

I would like to investigate this issue and I can really use a reproduction of the issue - let's take it offline
answered by mikebridge (760 points)
0 votes
Aha, traced the problem to out-of-date dlls in my project.

I'm having a similar issue running previously-working tests after upgrading from 5.4.2 to 5.4.3 (evaluation). Any idea what is causing this?

I would like to investigate this issue and I can really use a reproduction of the issue - let's take it offline
answered by mikebridge (760 points)
...