@@ -7,7 +7,7 @@ namespace CodeLineCounter.Tests
77{
88 public abstract class TestBase : IDisposable
99 {
10- private static readonly object _consoleLock = new object ( ) ;
10+ private static readonly Lock _consoleLock = new ( ) ;
1111 private readonly ThreadLocal < StringWriter > _stringWriter = new ThreadLocal < StringWriter > ( ( ) => new StringWriter ( ) ) ;
1212 private readonly ThreadLocal < StringReader > _stringReader = new ThreadLocal < StringReader > ( ( ) => new StringReader ( string . Empty ) ) ;
1313 private readonly ThreadLocal < TextWriter > _originalConsoleOut = new ThreadLocal < TextWriter > ( ) ;
@@ -22,7 +22,7 @@ protected TestBase()
2222
2323 protected void initialization ( )
2424 {
25- lock ( _consoleLock )
25+ using ( _consoleLock . EnterScope ( ) )
2626 {
2727 _originalConsoleOut . Value = Console . Out ;
2828 _originalConsoleIn . Value = Console . In ;
@@ -32,7 +32,7 @@ protected void initialization()
3232
3333 protected void RedirectConsoleInputOutput ( )
3434 {
35- lock ( _consoleLock )
35+ using ( _consoleLock . EnterScope ( ) )
3636 {
3737 if ( _stringWriter . Value != null )
3838 {
@@ -47,7 +47,7 @@ protected void RedirectConsoleInputOutput()
4747
4848 protected string GetConsoleOutput ( )
4949 {
50- lock ( _consoleLock )
50+ using ( _consoleLock . EnterScope ( ) )
5151 {
5252 if ( _stringWriter . Value != null )
5353 {
@@ -57,17 +57,10 @@ protected string GetConsoleOutput()
5757 }
5858 }
5959
60- protected void SetConsoleInput ( string input )
61- {
62- lock ( _consoleLock )
63- {
64- _stringReader . Value = new StringReader ( input ) ;
65- }
66- }
6760
6861 protected void ResetConsoleInputOutput ( )
6962 {
70- lock ( _consoleLock )
63+ using ( _consoleLock . EnterScope ( ) )
7164 {
7265 if ( _originalConsoleOut != null && _originalConsoleOut . Value != null )
7366 {
0 commit comments