This repository was archived by the owner on Dec 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding unit tests for the console logger
- Loading branch information
Showing
9 changed files
with
385 additions
and
15 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace Microsoft.Framework.Logging.Console | ||
{ | ||
public interface IConsole | ||
{ | ||
ConsoleColor BackgroundColor { get; set; } | ||
ConsoleColor ForegroundColor { get; set; } | ||
void WriteLine(string format, object arg0, object arg1, object arg2); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
|
||
namespace Microsoft.Framework.Logging.Console | ||
{ | ||
public class LogConsole : IConsole | ||
{ | ||
public ConsoleColor BackgroundColor | ||
{ | ||
get | ||
{ | ||
return System.Console.BackgroundColor; | ||
} | ||
|
||
set | ||
{ | ||
System.Console.BackgroundColor = value; | ||
} | ||
} | ||
|
||
public ConsoleColor ForegroundColor | ||
{ | ||
get | ||
{ | ||
return System.Console.ForegroundColor; | ||
} | ||
|
||
set | ||
{ | ||
System.Console.ForegroundColor = value; | ||
} | ||
} | ||
|
||
public void WriteLine(string format, object arg0, object arg1, object arg2) | ||
{ | ||
System.Console.WriteLine(format, arg0, arg1, arg2); | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
test/Microsoft.Framework.Logging.Test/Console/ConsoleContext.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
|
||
namespace Microsoft.Framework.Logging.Test.Console | ||
{ | ||
public class ConsoleContext | ||
{ | ||
public ConsoleColor BackgroundColor { get; set; } | ||
|
||
public ConsoleColor ForegroundColor { get; set; } | ||
|
||
public string Message { get; set; } | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/Microsoft.Framework.Logging.Test/Console/ConsoleSink.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Framework.Logging.Test.Console | ||
{ | ||
public class ConsoleSink | ||
{ | ||
public ConsoleSink() | ||
{ | ||
Writes = new List<ConsoleContext>(); | ||
} | ||
|
||
public List<ConsoleContext> Writes { get; set; } | ||
|
||
public void Write(ConsoleContext context) | ||
{ | ||
Writes.Add(context); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
test/Microsoft.Framework.Logging.Test/Console/TestConsole.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using Microsoft.Framework.Logging.Console; | ||
|
||
namespace Microsoft.Framework.Logging.Test.Console | ||
{ | ||
public class TestConsole : IConsole | ||
{ | ||
private ConsoleColor _backgroundColor; | ||
private ConsoleColor _foregroundColor; | ||
private ConsoleSink _sink; | ||
|
||
public TestConsole(ConsoleSink sink) | ||
{ | ||
_sink = sink; | ||
} | ||
|
||
public ConsoleColor BackgroundColor | ||
{ | ||
get | ||
{ | ||
return _backgroundColor; | ||
} | ||
|
||
set | ||
{ | ||
_backgroundColor = value; | ||
} | ||
} | ||
|
||
public ConsoleColor ForegroundColor | ||
{ | ||
get | ||
{ | ||
return _foregroundColor; | ||
} | ||
|
||
set | ||
{ | ||
_foregroundColor = value; | ||
} | ||
} | ||
|
||
public void WriteLine(string format, object arg0, object arg1, object arg2) | ||
{ | ||
var message = string.Format(format, arg0, arg1, arg2); | ||
_sink.Write(new ConsoleContext() | ||
{ | ||
ForegroundColor = _foregroundColor, | ||
BackgroundColor = _backgroundColor, | ||
Message = message | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.