Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //obviously not thread safe and lots of other things. But this illustrates the point that
- //Dispatcher can be stubbed and tested against to ensure a log entry was made.
- public static class Logger
- {
- public static ILoggerDispatcher Dispatcher { get; set; }
- public static void Log(string message, Exception exception)
- {
- if (Dispatcher != null)
- {
- Dispatcher.Log(message, exception);
- }
- }
- public static void Log(LogLevel level, string message)
- {
- if (Dispatcher != null)
- {
- Dispatcher.Log(message);
- }
- }
- }
- //MSpec test example
- protected ILoggerDispatcher fakeLogDispatcher;
- Establish context = () =>
- {
- fakeLogDispatcher = A.Fake<ILoggerDispatcher>();
- Automation.Logger.Dispatcher = fakeLogDispatcher;
- };
- //An assertion somewhere
- It should_log_that_the_attempt_failed = () => A.CallTo(() => fakeLogDispatcher.Log(A<string>._)).MustHaveHappened();
Add Comment
Please, Sign In to add comment