Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6544835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:30:49+00:00 2026-05-25T11:30:49+00:00

I need this in few of my automation test cases. The major functionality is

  • 0

I need this in few of my automation test cases. The major functionality is time dependent and this causes test cases to fail if I run them during the day time for which there’s no record.

I know I have another but relatively tedious option of mocking the repository and generate the time dependent data at runtime, but – I just want to know whether I can do this in other way – by controling the DateTime for an application and/or thread such that DateTime.Now returns the value based on what I set somewhere at the start?

Is it really possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:30:50+00:00Added an answer on May 25, 2026 at 11:30 am

    TypeMock isolator claims to be able to do this. Personally, though, I would rather change my code to inject an IClock and use that. The production clock might use DateTime.Now (or UtcNow), but I can provide a mock simply and cleanly.

    If that affects too many things, maybe a static implementation, so you can use Current.Time or something (where Current is your class), but which allows indirection / spoofing for tests. Indeed, that could be done using the above, simply with:

    private static IClock clock = new DateTimeClock();
    public static void SetClock(IClock clock) { Current.clock = clock; }
    public static DateTime Time { get { return clock.Now; } }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm almost done with this, just a few last hiccups. I now need to
Did a lot of research on this. Saw several opinions, few say I need
I have a need to run some automation tasks in a web browser control
I need this up and running quick but I spent the last few hours
I have run into this issue too many times and need this to be
I have been working on Test Automation from last few months and have been
I have a few reasons that I need this to happen, but suffice it
I need this for getting data in a graph for week basis. This one
I need this logic to work: I want rewrite this string for users to
I need this library to access the new Windows 7 taskbar functions. However it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.