Skip to content

Commit

Permalink
Move code to Shared
Browse files Browse the repository at this point in the history
Move all of the C# for the libraries into a Shared folder and link to each project from there.
  • Loading branch information
martincostello committed Dec 20, 2024
1 parent 5ebe1ba commit 64a0647
Show file tree
Hide file tree
Showing 20 changed files with 1,622 additions and 1,636 deletions.
23 changes: 3 additions & 20 deletions src/Logging.XUnit.v3/MartinCostello.Logging.XUnit.v3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" Link="%(Link)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" VersionOverride="8.0.1" />
<PackageReference Include="xunit.v3.extensibility.core" />
Expand All @@ -36,24 +39,4 @@
<Using Include="Xunit.Sdk" />
<Using Include="Xunit.v3" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\Logging.XUnit\AmbientTestOutputHelperAccessor.cs" Link="AmbientTestOutputHelperAccessor.cs" />
<Compile Include="..\Logging.XUnit\IMessageSinkAccessor.cs" Link="IMessageSinkAccessor.cs" />
<Compile Include="..\Logging.XUnit\IMessageSinkExtensions.cs" Link="IMessageSinkExtensions.cs" />
<Compile Include="..\Logging.XUnit\ITestOutputHelperAccessor.cs" Link="ITestOutputHelperAccessor.cs" />
<Compile Include="..\Logging.XUnit\ITestOutputHelperExtensions.cs" Link="ITestOutputHelperExtensions.cs" />
<Compile Include="..\Logging.XUnit\MessageSinkAccessor.cs" Link="MessageSinkAccessor.cs" />
<Compile Include="..\Logging.XUnit\StringSyntaxAttribute.cs" Link="StringSyntaxAttribute.cs" />
<Compile Include="..\Logging.XUnit\TestOutputHelperAccessor.cs" Link="TestOutputHelperAccessor.cs" />
<Compile Include="..\Logging.XUnit\XUnitLogger.cs" Link="XUnitLogger.cs" />
<Compile Include="..\Logging.XUnit\XUnitLogger.IMessageSink.cs" Link="XUnitLogger.IMessageSink.cs" />
<Compile Include="..\Logging.XUnit\XUnitLogger.ITestOutputHelper.cs" Link="XUnitLogger.ITestOutputHelper.cs" />
<Compile Include="..\Logging.XUnit\XUnitLoggerExtensions.IMessageSink.cs" Link="XUnitLoggerExtensions.IMessageSink.cs" />
<Compile Include="..\Logging.XUnit\XUnitLoggerExtensions.ITestOutputHelper.cs" Link="XUnitLoggerExtensions.ITestOutputHelper.cs" />
<Compile Include="..\Logging.XUnit\XUnitLoggerOptions.cs" Link="XUnitLoggerOptions.cs" />
<Compile Include="..\Logging.XUnit\XUnitLoggerProvider.cs" Link="XUnitLoggerProvider.cs" />
<Compile Include="..\Logging.XUnit\XUnitLoggerProvider.IMessageSink.cs" Link="XUnitLoggerProvider.IMessageSink.cs" />
<Compile Include="..\Logging.XUnit\XUnitLoggerProvider.ITestOutputHelper.cs" Link="XUnitLoggerProvider.ITestOutputHelper.cs" />
<Compile Include="..\Logging.XUnit\XUnitLogScope.cs" Link="XUnitLogScope.cs" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/Logging.XUnit/MartinCostello.Logging.XUnit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\Shared\**\*.cs" Link="%(Link)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="xunit.abstractions" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// 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.

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();

/// <summary>
/// Gets or sets the current <see cref="ITestOutputHelper"/>.
/// </summary>
public ITestOutputHelper? OutputHelper
{
get { return _current.Value; }
set { _current.Value = value; }
}
}
// 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.

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();

/// <summary>
/// Gets or sets the current <see cref="ITestOutputHelper"/>.
/// </summary>
public ITestOutputHelper? OutputHelper
{
get { return _current.Value; }
set { _current.Value = value; }
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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.

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// Defines a property for accessing an <see cref="IMessageSink"/>.
/// </summary>
public interface IMessageSinkAccessor
{
/// <summary>
/// Gets or sets the <see cref="IMessageSink"/> to use.
/// </summary>
IMessageSink? MessageSink { get; set; }
}
// 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.

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// Defines a property for accessing an <see cref="IMessageSink"/>.
/// </summary>
public interface IMessageSinkAccessor
{
/// <summary>
/// Gets or sets the <see cref="IMessageSink"/> to use.
/// </summary>
IMessageSink? MessageSink { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
// 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.ComponentModel;
using Microsoft.Extensions.Logging;

#if XUNIT_V3
namespace Xunit;
#else
#pragma warning disable IDE0130
namespace Xunit.Abstractions;
#endif

/// <summary>
/// A class containing extension methods for the <see cref="IMessageSink"/> interface. This class cannot be inherited.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IMessageSinkExtensions
{
/// <summary>
/// Returns an <see cref="ILoggerFactory"/> that logs to the message sink.
/// </summary>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger factory from.</param>
/// <returns>
/// An <see cref="ILoggerFactory"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILoggerFactory ToLoggerFactory(this IMessageSink messageSink)
{
#if NET
ArgumentNullException.ThrowIfNull(messageSink);
#else
if (messageSink == null)
{
throw new ArgumentNullException(nameof(messageSink));
}
#endif

return new LoggerFactory().AddXUnit(messageSink);
}

/// <summary>
/// Returns an <see cref="ILogger{T}"/> that logs to the message sink.
/// </summary>
/// <typeparam name="T">The type of the logger to create.</typeparam>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger from.</param>
/// <returns>
/// An <see cref="ILogger{T}"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILogger<T> ToLogger<T>(this IMessageSink messageSink)
=> messageSink.ToLoggerFactory().CreateLogger<T>();
}
// 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.ComponentModel;
using Microsoft.Extensions.Logging;

#if XUNIT_V3
namespace Xunit;
#else
#pragma warning disable IDE0130
namespace Xunit.Abstractions;
#endif

/// <summary>
/// A class containing extension methods for the <see cref="IMessageSink"/> interface. This class cannot be inherited.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class IMessageSinkExtensions
{
/// <summary>
/// Returns an <see cref="ILoggerFactory"/> that logs to the message sink.
/// </summary>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger factory from.</param>
/// <returns>
/// An <see cref="ILoggerFactory"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILoggerFactory ToLoggerFactory(this IMessageSink messageSink)
{
#if NET
ArgumentNullException.ThrowIfNull(messageSink);
#else
if (messageSink == null)
{
throw new ArgumentNullException(nameof(messageSink));
}
#endif

return new LoggerFactory().AddXUnit(messageSink);
}

/// <summary>
/// Returns an <see cref="ILogger{T}"/> that logs to the message sink.
/// </summary>
/// <typeparam name="T">The type of the logger to create.</typeparam>
/// <param name="messageSink">The <see cref="IMessageSink"/> to create the logger from.</param>
/// <returns>
/// An <see cref="ILogger{T}"/> that writes messages to the message sink.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
public static ILogger<T> ToLogger<T>(this IMessageSink messageSink)
=> messageSink.ToLoggerFactory().CreateLogger<T>();
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// 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.

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// A class representing the default implementation of <see cref="IMessageSinkAccessor"/>. This class cannot be inherited.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="MessageSinkAccessor"/> class.
/// </remarks>
/// <param name="messageSink">The <see cref="IMessageSink"/> to use.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
internal sealed class MessageSinkAccessor(IMessageSink messageSink) : IMessageSinkAccessor
{
/// <summary>
/// Gets or sets the current <see cref="IMessageSink"/>.
/// </summary>
public IMessageSink? MessageSink { get; set; } = messageSink ?? throw new ArgumentNullException(nameof(messageSink));
}
// 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.

namespace MartinCostello.Logging.XUnit;

/// <summary>
/// A class representing the default implementation of <see cref="IMessageSinkAccessor"/>. This class cannot be inherited.
/// </summary>
/// <remarks>
/// Initializes a new instance of the <see cref="MessageSinkAccessor"/> class.
/// </remarks>
/// <param name="messageSink">The <see cref="IMessageSink"/> to use.</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="messageSink"/> is <see langword="null"/>.
/// </exception>
internal sealed class MessageSinkAccessor(IMessageSink messageSink) : IMessageSinkAccessor
{
/// <summary>
/// Gets or sets the current <see cref="IMessageSink"/>.
/// </summary>
public IMessageSink? MessageSink { get; set; } = messageSink ?? throw new ArgumentNullException(nameof(messageSink));
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 64a0647

Please sign in to comment.