-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30fca26
commit ce84e08
Showing
11 changed files
with
192 additions
and
6 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
12 changes: 12 additions & 0 deletions
12
src/DotNet.Testcontainers.Tests/Fixtures/DefaultConsumerFixture.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,12 @@ | ||
namespace DotNet.Testcontainers.Tests.Fixtures | ||
{ | ||
using System.IO; | ||
using DotNet.Testcontainers.Diagnostics; | ||
|
||
public class DefaultConsumerFixture : DefaultConsumer | ||
{ | ||
public DefaultConsumerFixture() : base(new MemoryStream(), new MemoryStream()) | ||
{ | ||
} | ||
} | ||
} |
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
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
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
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,72 @@ | ||
namespace DotNet.Testcontainers.Diagnostics | ||
{ | ||
using System; | ||
using System.IO; | ||
|
||
public class DefaultConsumer : IOutputConsumer, IDisposable | ||
{ | ||
private readonly TextWriter defaultOut; | ||
|
||
private readonly TextWriter defaultErr; | ||
|
||
private readonly StreamWriter stdout; | ||
|
||
private readonly StreamWriter stderr; | ||
|
||
private bool disposed; | ||
|
||
public DefaultConsumer() : this(Console.OpenStandardOutput(), Console.OpenStandardError()) | ||
{ | ||
} | ||
|
||
protected DefaultConsumer(Stream stdout, Stream stderr) | ||
{ | ||
this.defaultOut = Console.Out; | ||
this.defaultErr = Console.Error; | ||
|
||
this.stdout = new StreamWriter(stdout) | ||
{ | ||
AutoFlush = true, | ||
}; | ||
|
||
this.stderr = new StreamWriter(stderr) | ||
{ | ||
AutoFlush = true, | ||
}; | ||
|
||
Console.SetOut(this.stdout); | ||
Console.SetError(this.stderr); | ||
} | ||
|
||
~DefaultConsumer() | ||
{ | ||
this.Dispose(false); | ||
} | ||
|
||
public Stream Stdout => this.stdout.BaseStream; | ||
|
||
public Stream Stderr => this.stderr.BaseStream; | ||
|
||
public void Dispose() | ||
{ | ||
this.Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (this.disposed) | ||
{ | ||
return; | ||
} | ||
|
||
Console.SetOut(this.defaultOut); | ||
Console.SetError(this.defaultErr); | ||
|
||
this.stdout.Dispose(); | ||
this.stderr.Dispose(); | ||
|
||
this.disposed = true; | ||
} | ||
} | ||
} |
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 @@ | ||
namespace DotNet.Testcontainers.Diagnostics | ||
{ | ||
using System.IO; | ||
|
||
public interface IOutputConsumer | ||
{ | ||
Stream Stdout { get; } | ||
|
||
Stream Stderr { get; } | ||
} | ||
} |