-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from martincostello/ITestOutputHandlerAccessor
Add ITestOutputHelperAccessor
- Loading branch information
Showing
22 changed files
with
660 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,31 @@ | ||
// Copyright (c) Martin Costello, 2018. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
using System.Threading; | ||
using Xunit.Abstractions; | ||
|
||
namespace MartinCostello.Logging.XUnit | ||
{ | ||
/// <summary> | ||
/// A class representing an implementation of <see cref="ITestOutputHelperAccessor"/> that | ||
/// stores the <see cref="ITestOutputHelper"/> as an asynchronous local value. This class cannot be inherited. | ||
/// </summary> | ||
internal sealed class AmbientTestOutputHelperAccessor : ITestOutputHelperAccessor | ||
{ | ||
/// <summary> | ||
/// A backing field for the <see cref="ITestOutputHelper"/> for the current thread. | ||
/// </summary> | ||
private static readonly AsyncLocal<ITestOutputHelper> _current = new AsyncLocal<ITestOutputHelper>(); | ||
|
||
#pragma warning disable CA1822 | ||
/// <summary> | ||
/// Gets or sets the current <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
public ITestOutputHelper OutputHelper | ||
{ | ||
get { return _current.Value; } | ||
set { _current.Value = value; } | ||
} | ||
#pragma warning restore CA1822 | ||
} | ||
} |
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,18 @@ | ||
// Copyright (c) Martin Costello, 2018. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
using Xunit.Abstractions; | ||
|
||
namespace MartinCostello.Logging.XUnit | ||
{ | ||
/// <summary> | ||
/// Defines a property for accessing an <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
public interface ITestOutputHelperAccessor | ||
{ | ||
/// <summary> | ||
/// Gets or sets the <see cref="ITestOutputHelper"/> to use. | ||
/// </summary> | ||
ITestOutputHelper OutputHelper { get; set; } | ||
} | ||
} |
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,31 @@ | ||
// Copyright (c) Martin Costello, 2018. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using Xunit.Abstractions; | ||
|
||
namespace MartinCostello.Logging.XUnit | ||
{ | ||
/// <summary> | ||
/// A class representing the default implementation of <see cref="ITestOutputHelperAccessor"/>. This class cannot be inherited. | ||
/// </summary> | ||
internal sealed class TestOutputHelperAccessor : ITestOutputHelperAccessor | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TestOutputHelperAccessor"/> class. | ||
/// </summary> | ||
/// <param name="outputHelper">The <see cref="ITestOutputHelper"/> to use.</param> | ||
/// <exception cref="ArgumentNullException"> | ||
/// <paramref name="outputHelper"/> is <see langword="null"/>. | ||
/// </exception> | ||
internal TestOutputHelperAccessor(ITestOutputHelper outputHelper) | ||
{ | ||
OutputHelper = outputHelper ?? throw new ArgumentNullException(nameof(outputHelper)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the current <see cref="ITestOutputHelper"/>. | ||
/// </summary> | ||
public ITestOutputHelper OutputHelper { get; set; } | ||
} | ||
} |
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
Oops, something went wrong.