Skip to content

Commit

Permalink
Use the .NET Standard 2.0 instead of .NET Core. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesTourreau authored Oct 13, 2023
1 parent 7cfa05a commit 69d35df
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 51 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,17 @@ try to make the assert fail messages the most easy to understand for the develop
![Assertion Missing Logs](https://raw.githubusercontent.com/PosInformatique/PosInformatique.Logging.Assertions/main/docs/AssertionMissingLogs.png)

## Library dependencies
The [PosInformatique.Logging.Assertions](https://www.nuget.org/packages/PosInformatique.Logging.Assertions/) library
is depend of the [FluentAssertions](https://github.com/fluentassertions/fluentassertions) library
for internal assertions which is more pretty to read in the exceptions message.
- The [PosInformatique.Logging.Assertions](https://www.nuget.org/packages/PosInformatique.Logging.Assertions/) target the .NET Standard 2.0
and the version 2.0.0 of the [Microsoft.Extensions.Logging.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Abstractions) NuGet package. So this library can be used with
different .NET architecture projects (.NET Framework, .NET Core, Xamarin,...) and also with old versions of the
[Microsoft.Extensions.Logging.Abstractions](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Abstractions) NuGet package.

- The [PosInformatique.Logging.Assertions](https://www.nuget.org/packages/PosInformatique.Logging.Assertions/) library
depends of the [FluentAssertions](https://github.com/fluentassertions/fluentassertions) library
for internal assertions which is more pretty to read in the exceptions message. It is use the version 5.0.0 and of course it is compatible
with the earlier version of it.

Also, the [PosInformatique.Logging.Assertions](https://www.nuget.org/packages/PosInformatique.Logging.Assertions/) library
- Also, the [PosInformatique.Logging.Assertions](https://www.nuget.org/packages/PosInformatique.Logging.Assertions/) library
use the internal [FluentAssertions](https://github.com/fluentassertions/fluentassertions) unit test
provider engine detection to throw an exception (when an assertion is false) depending of the engine used to execute
the unit test. For example, `XunitException` if the unit test engine used is `Xunit`.
36 changes: 0 additions & 36 deletions src/Logging.Assertions/ILoggerMockSetupSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ public interface ILoggerMockSetupSequence
/// <returns>The current <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
ILoggerMockSetupSequence Log(LogLevel logLevel, string message);

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Debug"/> log level.
/// </summary>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
ILoggerMockSetupSequence LogDebug(string message)
=> this.Log(LogLevel.Debug, message);

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Error"/> log level.
Expand All @@ -52,32 +43,5 @@ ILoggerMockSetupSequence LogDebug(string message)
/// <returns>The current <see cref="ILoggerMockSetupSequenceError"/> which allows to continue the setup of the <see cref="ILogger"/> method calls
/// and analyze also the <see cref="Exception"/> instance related to the log error message.</returns>
ILoggerMockSetupSequenceError LogError(string message);

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Information"/> log level.
/// </summary>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
ILoggerMockSetupSequence LogInformation(string message)
=> this.Log(LogLevel.Information, message);

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Trace"/> log level.
/// </summary>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
ILoggerMockSetupSequence LogTrace(string message)
=> this.Log(LogLevel.Trace, message);

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Warning"/> log level.
/// </summary>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
ILoggerMockSetupSequence LogWarning(string message)
=> this.Log(LogLevel.Warning, message);
}
}
8 changes: 0 additions & 8 deletions src/Logging.Assertions/ILoggerMockSetupSequenceError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,5 @@ public interface ILoggerMockSetupSequenceError : ILoggerMockSetupSequence
/// <param name="exception">Delegate which allows to analyze the content of the <see cref="Exception"/>.</param>
/// <returns>An instance of <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the method calls.</returns>
ILoggerMockSetupSequence WithException(Action<Exception> exception);

/// <summary>
/// Allows to check the <see cref="Exception"/> passed in the argument of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/>.
/// </summary>
/// <param name="expectedException"><see cref="Exception"/> instance expected.</param>
/// <returns>An instance of <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the method calls.</returns>
ILoggerMockSetupSequence WithException(Exception expectedException)
=> this.WithException(actualException => actualException.Should().BeSameAs(expectedException));
}
}
28 changes: 28 additions & 0 deletions src/Logging.Assertions/LoggerMockSetupSequenceErrorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//-----------------------------------------------------------------------
// <copyright file="LoggerMockSetupSequenceErrorExtensions.cs" company="P.O.S Informatique">
// Copyright (c) P.O.S Informatique. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace PosInformatique.Logging.Assertions
{
using FluentAssertions;
using Microsoft.Extensions.Logging;

/// <summary>
/// Extensions method of the <see cref="ILoggerMockSetupSequenceError"/> interface to setup the <see cref="LogLevel.Error"/> log level.
/// </summary>
public static class LoggerMockSetupSequenceErrorExtensions
{
/// <summary>
/// Allows to check the <see cref="Exception"/> passed in the argument of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/>.
/// </summary>
/// <param name="sequence"><see cref="ILoggerMockSetupSequence"/> to setup the sequence.</param>
/// <param name="expectedException"><see cref="Exception"/> instance expected.</param>
/// <returns>An instance of <see cref="ILoggerMockSetupSequence"/> which allows to continue the setup of the method calls.</returns>
public static ILoggerMockSetupSequence WithException(this ILoggerMockSetupSequenceError sequence, Exception expectedException)
{
return sequence.WithException(actualException => actualException.Should().BeSameAs(expectedException));
}
}
}
64 changes: 64 additions & 0 deletions src/Logging.Assertions/LoggerMockSetupSequenceExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//-----------------------------------------------------------------------
// <copyright file="LoggerMockSetupSequenceExtensions.cs" company="P.O.S Informatique">
// Copyright (c) P.O.S Informatique. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace PosInformatique.Logging.Assertions
{
using Microsoft.Extensions.Logging;

/// <summary>
/// Extensions method of the <see cref="ILoggerMockSetupSequence"/> interface to setup the sequence of the expected logs.
/// </summary>
public static class LoggerMockSetupSequenceExtensions
{
/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Debug"/> log level.
/// </summary>
/// <param name="sequence"><see cref="ILoggerMockSetupSequence"/> to setup the sequence.</param>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <paramref name="sequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
public static ILoggerMockSetupSequence LogDebug(this ILoggerMockSetupSequence sequence, string message)
{
return sequence.Log(LogLevel.Debug, message);
}

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Information"/> log level.
/// </summary>
/// <param name="sequence"><see cref="ILoggerMockSetupSequence"/> to setup the sequence.</param>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <paramref name="sequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
public static ILoggerMockSetupSequence LogInformation(this ILoggerMockSetupSequence sequence, string message)
{
return sequence.Log(LogLevel.Information, message);
}

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Trace"/> log level.
/// </summary>
/// <param name="sequence"><see cref="ILoggerMockSetupSequence"/> to setup the sequence.</param>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <paramref name="sequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
public static ILoggerMockSetupSequence LogTrace(this ILoggerMockSetupSequence sequence, string message)
{
return sequence.Log(LogLevel.Trace, message);
}

/// <summary>
/// Expect the call to the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> method
/// with a <see cref="LogLevel.Warning"/> log level.
/// </summary>
/// <param name="sequence"><see cref="ILoggerMockSetupSequence"/> to setup the sequence.</param>
/// <param name="message">Message of the <see cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/> call expected.</param>
/// <returns>The current <paramref name="sequence"/> which allows to continue the setup of the <see cref="ILogger"/> method calls.</returns>
public static ILoggerMockSetupSequence LogWarning(this ILoggerMockSetupSequence sequence, string message)
{
return sequence.Log(LogLevel.Warning, message);
}
}
}
9 changes: 6 additions & 3 deletions src/Logging.Assertions/Logging.Assertions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Description>PosInformatique.Logging.Assertions is a library to mock and assert easily the logs generated by the ILogger interface.</Description>
Expand All @@ -10,6 +10,9 @@
<PackageProjectUrl>https://github.com/PosInformatique/PosInformatique.Logging.Assertions</PackageProjectUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>
1.0.2
- The library target the .NET Standard 2.0 instead of .NET 6.0.

1.0.1
- Various fixes for the NuGet package description.

Expand All @@ -24,8 +27,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
<PackageReference Include="FluentAssertions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 69d35df

Please sign in to comment.