Created
May 11, 2012 14:23
-
-
Save AnthonyMastrean/2660000 to your computer and use it in GitHub Desktop.
Public static funcs wrapping system calls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System | |
{ | |
public static class SystemDate | |
{ | |
public static Func<DateTime> UtcNow { get; private set; } | |
static SystemDate() | |
{ | |
Reset(); | |
} | |
private static void Reset() | |
{ | |
UtcNow = () => DateTime.UtcNow; | |
} | |
public static IDisposable SetUtcNow(Func<DateTime> replacement) | |
{ | |
UtcNow = replacement; | |
return new DisposableAction(Reset); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace System.Threading | |
{ | |
public static class SystemThread | |
{ | |
public static Action<TimeSpan> Sleep { get; private set; } | |
static SystemThread() | |
{ | |
Reset(); | |
} | |
private static void Reset() | |
{ | |
Sleep = timespan => Thread.Sleep(timespan); | |
} | |
public static IDisposable SetSleep(Action<TimeSpan> replacement) | |
{ | |
Sleep = replacement; | |
return new DisposableAction(Reset); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using Machine.Specifications; | |
namespace Omnyx.Scanner.Specifications.Infrastructure | |
{ | |
public class TestSystemThread : IAssemblyContext | |
{ | |
public static TimeSpan Slept { get; private set; } | |
private IDisposable _reset; | |
public void OnAssemblyStart() | |
{ | |
// Disable sleeping and stash off the timespan for easy assertions. | |
_reset = SystemThread.SetSleep(timespan => { Slept = timespan; }); | |
} | |
public void OnAssemblyComplete() | |
{ | |
_reset.Dispose(); | |
Slept = TimeSpan.MinValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment