diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index c3010a103..adfe120df 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -17,8 +17,8 @@ - - + + @@ -33,7 +33,7 @@ - + @@ -53,8 +53,7 @@ - - + @@ -66,20 +65,23 @@ - + - + + + + + - - \ No newline at end of file + diff --git a/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs b/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs index 302f95e2c..14910ba87 100644 --- a/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs +++ b/src/ReactiveUI.DI.Tests/AutoFacReactiveUIDependencyTests.cs @@ -66,7 +66,7 @@ public void AutoFacWhenAnyTest() var builder = new ContainerBuilder(); var autofacResolver = builder.UseAutofacDependencyResolver(); - Locator.CurrentMutable.RegisterConstant(new ActivatingViewFetcher(), typeof(IActivationForViewFetcher)); + Locator.CurrentMutable.RegisterConstant(new ActivatingViewFetcher()); autofacResolver.InitializeSplat(); autofacResolver.InitializeReactiveUI(); _ = builder.Build(); diff --git a/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj b/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj index 11afd7322..488f1a66d 100644 --- a/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj +++ b/src/ReactiveUI.DI.Tests/ReactiveUI.DI.Tests.csproj @@ -1,7 +1,7 @@ net472;net8.0;net9.0 - $(NoWarn);1591;CA1707;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1633;CA2000;CA1515 false enable diff --git a/src/Splat.Autofac.Tests/DependencyResolverTests.cs b/src/Splat.Autofac.Tests/DependencyResolverTests.cs index 3818e5c24..c4475f9b9 100644 --- a/src/Splat.Autofac.Tests/DependencyResolverTests.cs +++ b/src/Splat.Autofac.Tests/DependencyResolverTests.cs @@ -163,9 +163,7 @@ public void AutofacDependencyResolver_Should_ReturnRegisteredLogger() var autofacResolver = builder.UseAutofacDependencyResolver(); - Locator.CurrentMutable.RegisterConstant( - new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), - typeof(ILogManager)); + Locator.CurrentMutable.RegisterConstant(new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); autofacResolver.SetLifetimeScope(builder.Build()); diff --git a/src/Splat.Avalonia.DryIoc1.Tests/Splat.Avalonia.DryIoc1.Tests.csproj b/src/Splat.Avalonia.DryIoc1.Tests/Splat.Avalonia.DryIoc1.Tests.csproj index 4d941632b..553a0fd61 100644 --- a/src/Splat.Avalonia.DryIoc1.Tests/Splat.Avalonia.DryIoc1.Tests.csproj +++ b/src/Splat.Avalonia.DryIoc1.Tests/Splat.Avalonia.DryIoc1.Tests.csproj @@ -3,7 +3,7 @@ net8.0;net9.0 enable enable - $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000;CA1515 false true $(DefineConstants);DRYIOC1 diff --git a/src/Splat.Avalonia.DryIoc2.Tests/Splat.Avalonia.DryIoc2.Tests.csproj b/src/Splat.Avalonia.DryIoc2.Tests/Splat.Avalonia.DryIoc2.Tests.csproj index 1b4852ded..d299d044a 100644 --- a/src/Splat.Avalonia.DryIoc2.Tests/Splat.Avalonia.DryIoc2.Tests.csproj +++ b/src/Splat.Avalonia.DryIoc2.Tests/Splat.Avalonia.DryIoc2.Tests.csproj @@ -3,7 +3,7 @@ net8.0;net9.0 enable enable - $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000;CA1515 false true $(DefineConstants);DRYIOC2 diff --git a/src/Splat.Avalonia.Microsoft1.Tests/Splat.Avalonia.Microsoft1.Tests.csproj b/src/Splat.Avalonia.Microsoft1.Tests/Splat.Avalonia.Microsoft1.Tests.csproj index d91114cdd..971f6f644 100644 --- a/src/Splat.Avalonia.Microsoft1.Tests/Splat.Avalonia.Microsoft1.Tests.csproj +++ b/src/Splat.Avalonia.Microsoft1.Tests/Splat.Avalonia.Microsoft1.Tests.csproj @@ -3,7 +3,7 @@ net8.0;net9.0 enable enable - $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000;CA1515 false true $(DefineConstants);MICROSOFT1 diff --git a/src/Splat.Avalonia.Microsoft2.Tests/Splat.Avalonia.Microsoft2.Tests.csproj b/src/Splat.Avalonia.Microsoft2.Tests/Splat.Avalonia.Microsoft2.Tests.csproj index 9add5b3a5..e4e2d43ac 100644 --- a/src/Splat.Avalonia.Microsoft2.Tests/Splat.Avalonia.Microsoft2.Tests.csproj +++ b/src/Splat.Avalonia.Microsoft2.Tests/Splat.Avalonia.Microsoft2.Tests.csproj @@ -3,7 +3,7 @@ net8.0;net9.0 enable enable - $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000;CA1515 false true $(DefineConstants);MICROSOFT2 diff --git a/src/Splat.Avalonia.Tests/Splat.Avalonia.Tests.csproj b/src/Splat.Avalonia.Tests/Splat.Avalonia.Tests.csproj index 0a04e2730..100a6ff16 100644 --- a/src/Splat.Avalonia.Tests/Splat.Avalonia.Tests.csproj +++ b/src/Splat.Avalonia.Tests/Splat.Avalonia.Tests.csproj @@ -3,7 +3,7 @@ net8.0;net9.0 enable enable - $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000 + $(NoWarn);1591;CA1707;SA1600;SA1601;SA1633;CA2000;CA1515 false true $(DefineConstants);MAIN diff --git a/src/Splat.Drawing.Tests/Splat.Drawing.Tests.csproj b/src/Splat.Drawing.Tests/Splat.Drawing.Tests.csproj index 1ed795b26..7d3b32ff3 100644 --- a/src/Splat.Drawing.Tests/Splat.Drawing.Tests.csproj +++ b/src/Splat.Drawing.Tests/Splat.Drawing.Tests.csproj @@ -3,7 +3,7 @@ net8.0-windows10.0.17763.0;net9.0-windows10.0.17763.0 false - $(NoWarn);1591;CA1707;SA1633;CA2000;CA1034 + $(NoWarn);1591;CA1707;SA1633;CA2000;CA1034;CA1515 enable true true diff --git a/src/Splat.Drawing/Platforms/ReflectionStubs.cs b/src/Splat.Drawing/Platforms/ReflectionStubs.cs index 2d5e614f0..9701ef8f7 100644 --- a/src/Splat.Drawing/Platforms/ReflectionStubs.cs +++ b/src/Splat.Drawing/Platforms/ReflectionStubs.cs @@ -3,12 +3,17 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace Splat; internal static class ReflectionStubs { +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetField() may be trimmed.")] + [RequiresDynamicCode("Type.GetField() may be trimmed.")] +#endif public static FieldInfo? GetField(this Type value, string name, BindingFlags flags = default) { var ti = value.GetTypeInfo(); @@ -18,6 +23,10 @@ internal static class ReflectionStubs : ti.BaseType.GetField(name, flags); } +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetMethod() may be trimmed.")] + [RequiresDynamicCode("Type.GetMethod() may be trimmed.")] +#endif public static MethodInfo? GetMethod(this Type value, string name, BindingFlags flags = default) { var ti = value.GetTypeInfo(); @@ -27,6 +36,10 @@ internal static class ReflectionStubs : ti.BaseType.GetMethod(name, flags); } +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetProperty() may be trimmed.")] + [RequiresDynamicCode("Type.GetProperty() may be trimmed.")] +#endif public static PropertyInfo? GetProperty(this Type value, string name, BindingFlags flags = default) { var ti = value.GetTypeInfo(); @@ -36,6 +49,10 @@ internal static class ReflectionStubs : ti.BaseType.GetProperty(name, flags); } +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetEvent() may be trimmed.")] + [RequiresDynamicCode("Type.GetEvent() may be trimmed.")] +#endif public static EventInfo? GetEvent(this Type value, string name, BindingFlags flags = default) { var ti = value.GetTypeInfo(); @@ -45,10 +62,22 @@ internal static class ReflectionStubs : ti.BaseType.GetEvent(name, flags); } +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetProperties() may be trimmed.")] + [RequiresDynamicCode("Type.GetProperties() may be trimmed.")] +#endif public static IEnumerable GetProperties(this Type value) => value.GetTypeInfo().DeclaredProperties; +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetFields() may be trimmed.")] + [RequiresDynamicCode("Type.GetFields() may be trimmed.")] +#endif public static IEnumerable GetFields(this Type value) => value.GetTypeInfo().DeclaredFields; +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetMethod() may be trimmed.")] + [RequiresDynamicCode("Type.GetMethod() may be trimmed.")] +#endif public static MethodInfo? GetMethod(this Type value, string methodName, Type[] paramTypes, BindingFlags flags = default) { var ti = value.GetTypeInfo(); @@ -60,6 +89,10 @@ internal static class ReflectionStubs : ti.BaseType.GetMethod(methodName, paramTypes, flags); } +#if NET6_0_OR_GREATER + [RequiresUnreferencedCode("Type.GetMethods() may be trimmed.")] + [RequiresDynamicCode("Type.GetMethods() may be trimmed.")] +#endif public static IEnumerable GetMethods(this Type value) => value.GetTypeInfo().DeclaredMethods; public static IEnumerable GetCustomAttributes(this Type value, Type attributeType, bool inherit) => value.GetTypeInfo().GetCustomAttributes(attributeType, inherit); diff --git a/src/Splat.DryIoc.Tests/DependencyResolverTests.cs b/src/Splat.DryIoc.Tests/DependencyResolverTests.cs index c7b1062f8..410aaad41 100644 --- a/src/Splat.DryIoc.Tests/DependencyResolverTests.cs +++ b/src/Splat.DryIoc.Tests/DependencyResolverTests.cs @@ -254,9 +254,7 @@ public void DryIocDependencyResolver_Should_ReturnRegisteredLogger() var c = new Container(); c.UseDryIocDependencyResolver(); c.Register(ifAlreadyRegistered: IfAlreadyRegistered.Replace); - Locator.CurrentMutable.RegisterConstant( - new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), - typeof(ILogManager)); + Locator.CurrentMutable.RegisterConstant(new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); var d = Splat.Locator.Current.GetService(); Assert.IsType(d); @@ -272,7 +270,7 @@ public void DryIocDependencyResolver_Should_ReturnRegisteredLogger() public void DryIocDependencyResolver_PreInit_Should_ReturnRegisteredLogger() { var c = new Container(); - c.RegisterInstance(typeof(ILogManager), new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); + c.RegisterInstance(new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); c.UseDryIocDependencyResolver(); var d = Splat.Locator.Current.GetService(); diff --git a/src/Splat.Prism.Tests/DependencyResolverTests.cs b/src/Splat.Prism.Tests/DependencyResolverTests.cs index cbd71e154..cd6d91612 100644 --- a/src/Splat.Prism.Tests/DependencyResolverTests.cs +++ b/src/Splat.Prism.Tests/DependencyResolverTests.cs @@ -258,9 +258,7 @@ public void PrismDependencyResolver_Should_ReturnRegisteredLogger() { using var c = new SplatContainerExtension(); c.Register(typeof(ILogger), typeof(ConsoleLogger)); - Locator.CurrentMutable.RegisterConstant( - new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger())), - typeof(ILogManager)); + Locator.CurrentMutable.RegisterConstant(new FuncLogManager(type => new WrappingFullLogger(new ConsoleLogger()))); var d = Splat.Locator.Current.GetService(); Assert.IsType(d); diff --git a/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs b/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs index 17580b9b2..f9794461d 100644 --- a/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs +++ b/src/Splat.Tests/ApplicationPerformanceMonitoring/EnableFeatureUsageTrackingExtensionsTests.cs @@ -16,9 +16,7 @@ public static class EnableFeatureUsageTrackingExtensionsTests /// /// Dummy object for testing IEnableFeatureUsageTracking. /// - public sealed class TestObjectThatSupportsFeatureUsageTracking : IEnableFeatureUsageTracking - { - } + public sealed class TestObjectThatSupportsFeatureUsageTracking : IEnableFeatureUsageTracking; /// /// Unit tests for the FeatureUsageTrackingExtensionMethod. diff --git a/src/Splat.Tests/LocatorSerialRegisterTests.cs b/src/Splat.Tests/LocatorSerialRegisterTests.cs index fc548b0f4..f1f80f3d8 100644 --- a/src/Splat.Tests/LocatorSerialRegisterTests.cs +++ b/src/Splat.Tests/LocatorSerialRegisterTests.cs @@ -321,13 +321,13 @@ public void FuncDependencyResolver_UnregisterAll() }); currentMutable.UnregisterAll(); - type.Should().Be(typeof(IDummyInterface)); + type.Should().Be(); contract.Should().BeNull(); unregisterAllCalled.Should().BeTrue(); unregisterAllCalled = false; currentMutable.UnregisterAll("test"); - type.Should().Be(typeof(IEnableLogger)); + type.Should().Be(); contract.Should().Be("test"); unregisterAllCalled.Should().BeTrue(); } @@ -353,13 +353,13 @@ public void FuncDependencyResolver_UnregisterCurrent() }); currentMutable.UnregisterCurrent(); - type.Should().Be(typeof(IDummyInterface)); + type.Should().Be(); contract.Should().BeNull(); unregisterAllCalled.Should().BeTrue(); unregisterAllCalled = false; currentMutable.UnregisterCurrent("test"); - type.Should().Be(typeof(IEnableLogger)); + type.Should().Be(); contract.Should().Be("test"); unregisterAllCalled.Should().BeTrue(); } diff --git a/src/Splat.Tests/LocatorTests.cs b/src/Splat.Tests/LocatorTests.cs index 298193b93..e356fb414 100644 --- a/src/Splat.Tests/LocatorTests.cs +++ b/src/Splat.Tests/LocatorTests.cs @@ -403,13 +403,13 @@ public void FuncDependencyResolver_UnregisterAll() }); currentMutable.UnregisterAll(); - type.Should().Be(typeof(IDummyInterface)); + type.Should().Be(); contract.Should().BeNull(); unregisterAllCalled.Should().BeTrue(); unregisterAllCalled = false; currentMutable.UnregisterAll("test"); - type.Should().Be(typeof(IEnableLogger)); + type.Should().Be(); contract.Should().Be("test"); unregisterAllCalled.Should().BeTrue(); } @@ -435,13 +435,13 @@ public void FuncDependencyResolver_UnregisterCurrent() }); currentMutable.UnregisterCurrent(); - type.Should().Be(typeof(IDummyInterface)); + type.Should().Be(); contract.Should().BeNull(); unregisterAllCalled.Should().BeTrue(); unregisterAllCalled = false; currentMutable.UnregisterCurrent("test"); - type.Should().Be(typeof(IEnableLogger)); + type.Should().Be(); contract.Should().Be("test"); unregisterAllCalled.Should().BeTrue(); } diff --git a/src/Splat.Tests/Logging/StaticLoggerTests.cs b/src/Splat.Tests/Logging/StaticLoggerTests.cs index 4fa7e990a..04062781c 100644 --- a/src/Splat.Tests/Logging/StaticLoggerTests.cs +++ b/src/Splat.Tests/Logging/StaticLoggerTests.cs @@ -8,145 +8,10 @@ namespace Splat.Tests.Logging; /// Unit Tests for the Static Logging wrapper implementation. /// [ExcludeFromCodeCoverage] -public sealed class StaticLoggerTests +internal sealed class StaticLoggerTests { private static char[] NewLine => Environment.NewLine.ToCharArray(); - /// - /// Unit tests focusing on the debug logging in the static logger. - /// - public class DebugStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() => LogLevel.Debug; - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Debug(message); - - /// - protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Debug(s); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Debug(formatProvider, message, arg1); - - /// - protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Debug(exception, message); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Debug(formatProvider, message, arg1, arg2); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Debug(formatProvider, message, arg1, arg2, arg3); - } - - /// - /// Unit tests focusing on the info logging in the static logger. - /// - public class InfoStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() => LogLevel.Info; - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Info(message); - - /// - protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Info(s); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Info(formatProvider, message, arg1); - - /// - protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Info(exception, message); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Info(formatProvider, message, arg1, arg2); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Info(formatProvider, message, arg1, arg2, arg3); - } - - /// - /// Unit tests focusing on the warning logging in the static logger. - /// - public class WarningStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() => LogLevel.Warn; - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Warn(message); - - /// - protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Warn(s); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Warn(formatProvider, message, arg1); - - /// - protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Warn(exception, message); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Warn(formatProvider, message, arg1, arg2); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Warn(formatProvider, message, arg1, arg2, arg3); - } - - /// - /// Unit tests focusing on the error logging in the static logger. - /// - public class ErrorStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() => LogLevel.Error; - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Error(message); - - /// - protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Error(s); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Error(formatProvider, message, arg1); - - /// - protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Error(exception, message); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Error(formatProvider, message, arg1, arg2); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Error(formatProvider, message, arg1, arg2, arg3); - } - - /// - /// Unit tests focusing on the fatal logging in the static logger. - /// - public class FatalStaticLoggerTests : BaseStaticLoggerTests - { - /// - protected override LogLevel GetLogLevel() => LogLevel.Fatal; - - /// - protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Fatal(message); - - /// - protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Fatal(s); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Fatal(formatProvider, message, arg1); - - /// - protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Fatal(exception, message); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Fatal(formatProvider, message, arg1, arg2); - - /// - protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Fatal(formatProvider, message, arg1, arg2, arg3); - } - /// /// Base tests for the static logger. /// @@ -341,4 +206,139 @@ private static void Test_Write_Message(Action testMethodFunc) Assert.True(endOfCallerMemberSuffix > startOfCallerMemberSuffix + 1); } } + + /// + /// Unit tests focusing on the debug logging in the static logger. + /// + internal class DebugStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() => LogLevel.Debug; + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Debug(message); + + /// + protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Debug(s); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Debug(formatProvider, message, arg1); + + /// + protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Debug(exception, message); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Debug(formatProvider, message, arg1, arg2); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Debug(formatProvider, message, arg1, arg2, arg3); + } + + /// + /// Unit tests focusing on the info logging in the static logger. + /// + internal class InfoStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() => LogLevel.Info; + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Info(message); + + /// + protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Info(s); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Info(formatProvider, message, arg1); + + /// + protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Info(exception, message); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Info(formatProvider, message, arg1, arg2); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Info(formatProvider, message, arg1, arg2, arg3); + } + + /// + /// Unit tests focusing on the warning logging in the static logger. + /// + internal class WarningStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() => LogLevel.Warn; + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Warn(message); + + /// + protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Warn(s); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Warn(formatProvider, message, arg1); + + /// + protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Warn(exception, message); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Warn(formatProvider, message, arg1, arg2); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Warn(formatProvider, message, arg1, arg2, arg3); + } + + /// + /// Unit tests focusing on the error logging in the static logger. + /// + internal class ErrorStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() => LogLevel.Error; + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Error(message); + + /// + protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Error(s); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Error(formatProvider, message, arg1); + + /// + protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Error(exception, message); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Error(formatProvider, message, arg1, arg2); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Error(formatProvider, message, arg1, arg2, arg3); + } + + /// + /// Unit tests focusing on the fatal logging in the static logger. + /// + internal class FatalStaticLoggerTests : BaseStaticLoggerTests + { + /// + protected override LogLevel GetLogLevel() => LogLevel.Fatal; + + /// + protected override Action GetMethodWithGenericTypeShouldWriteMessageAndType() => (logger, message) => logger.Fatal(message); + + /// + protected override Action GetMethodToWriteMessage() => (logger, s) => logger.Fatal(s); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCulture() => (logger, formatProvider, message, arg1) => logger.Fatal(formatProvider, message, arg1); + + /// + protected override Action GetMethodToWriteExceptionAndMessage() => (logger, exception, message) => logger.Fatal(exception, message); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithTwoGenericArgs() => (logger, formatProvider, message, arg1, arg2) => logger.Fatal(formatProvider, message, arg1, arg2); + + /// + protected override Action GetMethodToWriteMessageWithInvariantCultureWithThreeGenericArgs() => (logger, formatProvider, message, arg1, arg2, arg3) => logger.Fatal(formatProvider, message, arg1, arg2, arg3); + } } diff --git a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs index 27152da4a..253ac8d51 100644 --- a/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs +++ b/src/Splat.Tests/Logging/WrappingFullLoggers/ConsoleLoggerTests.cs @@ -12,7 +12,7 @@ namespace Splat.Tests.Logging; /// /// Tests that verify the class. /// -public class ConsoleLoggerTests : FullLoggerTestBase +internal class ConsoleLoggerTests : FullLoggerTestBase { /// protected override (IFullLogger logger, IMockLogTarget mockTarget) GetLogger(LogLevel minimumLogLevel) @@ -33,7 +33,7 @@ private sealed class ConsoleWriter : TextWriter, IMockLogTarget public override void WriteLine(string? value) { var colonIndex = value!.IndexOf(':', StringComparison.InvariantCulture); - var level = (LogLevel)Enum.Parse(typeof(LogLevel), value.AsSpan(0, colonIndex)); + var level = Enum.Parse(value.AsSpan(0, colonIndex)); var message = value.Substring(colonIndex + 1).Trim(); _logs.Add((level, message)); base.WriteLine(value); diff --git a/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs b/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs index bde98d986..6ff2594af 100644 --- a/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs +++ b/src/Splat.Tests/ServiceLocation/BaseDependencyResolverTests.cs @@ -194,7 +194,7 @@ public void NullResolverTests() Assert.Throws(() => resolver1.RegisterAnd(() => new ViewModelOne())); Assert.Throws(() => resolver1.Register()); Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne())); - Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne(), typeof(ViewModelOne))); + Assert.Throws(() => resolver1.RegisterConstantAnd(new ViewModelOne())); Assert.Throws(() => resolver1.RegisterConstantAnd()); #pragma warning restore CS8604 // Possible null reference argument. } @@ -212,7 +212,7 @@ public void RegisterAndTests() .RegisterAnd(() => new DefaultLogManager(), "three") .RegisterAnd(() => new ViewModelOne(), "four") .RegisterConstantAnd("five") - .RegisterConstantAnd(new ViewModelOne(), typeof(ViewModelOne), "six") + .RegisterConstantAnd(new ViewModelOne(), "six") .RegisterLazySingletonAnd(() => new DefaultLogManager(), typeof(ILogManager), "seven") .RegisterLazySingletonAnd("eight") .RegisterLazySingletonAnd(() => new(), "seven") diff --git a/src/Splat.Tests/Splat.Tests.csproj b/src/Splat.Tests/Splat.Tests.csproj index 7d97eceb8..7707f8d9d 100644 --- a/src/Splat.Tests/Splat.Tests.csproj +++ b/src/Splat.Tests/Splat.Tests.csproj @@ -1,7 +1,7 @@ - + net8.0-windows10.0.17763.0;net9.0-windows10.0.17763.0 - $(NoWarn);1591;CA1707;SA1633;CA2000;CA1034 + $(NoWarn);1591;CA1707;SA1633;CA2000;CA1034;CA1515;CA1812;CA1852 enable