diff --git a/README.md b/README.md index 79fbb1f..8e3c55a 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/Logging.Assertions/ILoggerMockSetupSequence.cs b/src/Logging.Assertions/ILoggerMockSetupSequence.cs index 86baeec..e817363 100644 --- a/src/Logging.Assertions/ILoggerMockSetupSequence.cs +++ b/src/Logging.Assertions/ILoggerMockSetupSequence.cs @@ -35,15 +35,6 @@ public interface ILoggerMockSetupSequence /// The current which allows to continue the setup of the method calls. ILoggerMockSetupSequence Log(LogLevel logLevel, string message); - /// - /// Expect the call to the method - /// with a log level. - /// - /// Message of the call expected. - /// The current which allows to continue the setup of the method calls. - ILoggerMockSetupSequence LogDebug(string message) - => this.Log(LogLevel.Debug, message); - /// /// Expect the call to the method /// with a log level. @@ -52,32 +43,5 @@ ILoggerMockSetupSequence LogDebug(string message) /// The current which allows to continue the setup of the method calls /// and analyze also the instance related to the log error message. ILoggerMockSetupSequenceError LogError(string message); - - /// - /// Expect the call to the method - /// with a log level. - /// - /// Message of the call expected. - /// The current which allows to continue the setup of the method calls. - ILoggerMockSetupSequence LogInformation(string message) - => this.Log(LogLevel.Information, message); - - /// - /// Expect the call to the method - /// with a log level. - /// - /// Message of the call expected. - /// The current which allows to continue the setup of the method calls. - ILoggerMockSetupSequence LogTrace(string message) - => this.Log(LogLevel.Trace, message); - - /// - /// Expect the call to the method - /// with a log level. - /// - /// Message of the call expected. - /// The current which allows to continue the setup of the method calls. - ILoggerMockSetupSequence LogWarning(string message) - => this.Log(LogLevel.Warning, message); } } diff --git a/src/Logging.Assertions/ILoggerMockSetupSequenceError.cs b/src/Logging.Assertions/ILoggerMockSetupSequenceError.cs index 150570c..14cf8e2 100644 --- a/src/Logging.Assertions/ILoggerMockSetupSequenceError.cs +++ b/src/Logging.Assertions/ILoggerMockSetupSequenceError.cs @@ -21,13 +21,5 @@ public interface ILoggerMockSetupSequenceError : ILoggerMockSetupSequence /// Delegate which allows to analyze the content of the . /// An instance of which allows to continue the setup of the method calls. ILoggerMockSetupSequence WithException(Action exception); - - /// - /// Allows to check the passed in the argument of the . - /// - /// instance expected. - /// An instance of which allows to continue the setup of the method calls. - ILoggerMockSetupSequence WithException(Exception expectedException) - => this.WithException(actualException => actualException.Should().BeSameAs(expectedException)); } } diff --git a/src/Logging.Assertions/LoggerMockSetupSequenceErrorExtensions.cs b/src/Logging.Assertions/LoggerMockSetupSequenceErrorExtensions.cs new file mode 100644 index 0000000..05246f2 --- /dev/null +++ b/src/Logging.Assertions/LoggerMockSetupSequenceErrorExtensions.cs @@ -0,0 +1,28 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) P.O.S Informatique. All rights reserved. +// +//----------------------------------------------------------------------- + +namespace PosInformatique.Logging.Assertions +{ + using FluentAssertions; + using Microsoft.Extensions.Logging; + + /// + /// Extensions method of the interface to setup the log level. + /// + public static class LoggerMockSetupSequenceErrorExtensions + { + /// + /// Allows to check the passed in the argument of the . + /// + /// to setup the sequence. + /// instance expected. + /// An instance of which allows to continue the setup of the method calls. + public static ILoggerMockSetupSequence WithException(this ILoggerMockSetupSequenceError sequence, Exception expectedException) + { + return sequence.WithException(actualException => actualException.Should().BeSameAs(expectedException)); + } + } +} diff --git a/src/Logging.Assertions/LoggerMockSetupSequenceExtensions.cs b/src/Logging.Assertions/LoggerMockSetupSequenceExtensions.cs new file mode 100644 index 0000000..454c9aa --- /dev/null +++ b/src/Logging.Assertions/LoggerMockSetupSequenceExtensions.cs @@ -0,0 +1,64 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) P.O.S Informatique. All rights reserved. +// +//----------------------------------------------------------------------- + +namespace PosInformatique.Logging.Assertions +{ + using Microsoft.Extensions.Logging; + + /// + /// Extensions method of the interface to setup the sequence of the expected logs. + /// + public static class LoggerMockSetupSequenceExtensions + { + /// + /// Expect the call to the method + /// with a log level. + /// + /// to setup the sequence. + /// Message of the call expected. + /// The current which allows to continue the setup of the method calls. + public static ILoggerMockSetupSequence LogDebug(this ILoggerMockSetupSequence sequence, string message) + { + return sequence.Log(LogLevel.Debug, message); + } + + /// + /// Expect the call to the method + /// with a log level. + /// + /// to setup the sequence. + /// Message of the call expected. + /// The current which allows to continue the setup of the method calls. + public static ILoggerMockSetupSequence LogInformation(this ILoggerMockSetupSequence sequence, string message) + { + return sequence.Log(LogLevel.Information, message); + } + + /// + /// Expect the call to the method + /// with a log level. + /// + /// to setup the sequence. + /// Message of the call expected. + /// The current which allows to continue the setup of the method calls. + public static ILoggerMockSetupSequence LogTrace(this ILoggerMockSetupSequence sequence, string message) + { + return sequence.Log(LogLevel.Trace, message); + } + + /// + /// Expect the call to the method + /// with a log level. + /// + /// to setup the sequence. + /// Message of the call expected. + /// The current which allows to continue the setup of the method calls. + public static ILoggerMockSetupSequence LogWarning(this ILoggerMockSetupSequence sequence, string message) + { + return sequence.Log(LogLevel.Warning, message); + } + } +} diff --git a/src/Logging.Assertions/Logging.Assertions.csproj b/src/Logging.Assertions/Logging.Assertions.csproj index 672239a..9dd0872 100644 --- a/src/Logging.Assertions/Logging.Assertions.csproj +++ b/src/Logging.Assertions/Logging.Assertions.csproj @@ -1,7 +1,7 @@ - net6.0 + netstandard2.0 enable True PosInformatique.Logging.Assertions is a library to mock and assert easily the logs generated by the ILogger interface. @@ -10,6 +10,9 @@ https://github.com/PosInformatique/PosInformatique.Logging.Assertions README.md + 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. @@ -24,8 +27,8 @@ - - + +