From 4fecf0c38ad964dbdd61add9701c220fe833b6bf Mon Sep 17 00:00:00 2001 From: David Driscoll Date: Wed, 1 May 2024 20:54:27 -0400 Subject: [PATCH] updated to the latest conventions (#1994) --- Directory.Packages.props | 14 ++-- LaunchPad.sln | 15 ----- .../Sample.Classic.Restful.csproj | 2 +- sample/Sample.Core/Domain/RocketDbContext.cs | 2 - sample/Sample.Graphql/Sample.Graphql.csproj | 6 +- sample/Sample.Pages/Sample.Pages.csproj | 2 - sample/Sample.Restful/Sample.Restful.csproj | 2 +- .../GraphqlMutationActionBodyGenerator.cs | 6 +- ...Rocket.Surgery.LaunchPad.AspNetCore.csproj | 1 + src/Foundation/FoundationOptions.cs | 13 +--- src/HotChocolate/AssemblyInfoQuery.cs | 15 ++--- src/Mapping/Profiles/NodaTimeProfile.cs | 67 ++++++++++--------- .../SerilogReadFromConfigurationConvention.cs | 2 - .../RocketSurgeryOpenTelemetryExtensions.cs | 4 +- .../Rocket.Surgery.LaunchPad.Testing.csproj | 3 - ...ocket.Surgery.LaunchPad.Web.Hosting.csproj | 14 ---- test/Analyzers.Tests/Analyzers.Tests.csproj | 3 - .../FakeClockConventionTests.cs | 4 +- test/Extensions.Tests/FeatureFactory.cs | 4 +- .../Mapping/LocalDateTests.cs | 2 - .../Mapping/LocalTimeTests.cs | 66 ++++++++---------- .../Mapping/TypeConverterTest.cs | 3 +- test/Extensions.Tests/ModuleInitializer.cs | 4 +- .../SerilogDestructuringTests.cs | 11 ++- .../HealthCheckOptionsValidationTests.cs | 4 +- .../Validation/OptionsValidationTests.cs | 11 +-- 26 files changed, 98 insertions(+), 182 deletions(-) delete mode 100644 src/Web.Hosting/Rocket.Surgery.LaunchPad.Web.Hosting.csproj diff --git a/Directory.Packages.props b/Directory.Packages.props index 42c5b061e..4a00b78d8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -94,15 +94,15 @@ - - - - - + + + + + - - + + diff --git a/LaunchPad.sln b/LaunchPad.sln index a2e9a05b9..ee035a723 100644 --- a/LaunchPad.sln +++ b/LaunchPad.sln @@ -138,8 +138,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.BlazorWasm", "sample EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.BlazorWasm.Tests", "test\Sample.BlazorWasm.Tests\Sample.BlazorWasm.Tests.csproj", "{A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rocket.Surgery.LaunchPad.Web.Hosting", "src\Web.Hosting\Rocket.Surgery.LaunchPad.Web.Hosting.csproj", "{10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Classic.Restful", "sample\Sample.Classic.Restful\Sample.Classic.Restful.csproj", "{2C09FAF6-434D-442F-94B2-02AB906B477C}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Classic.Restful.Tests", "test\Sample.Classic.Restful.Tests\Sample.Classic.Restful.Tests.csproj", "{2EF6A468-3689-4407-8A11-2E3F5DEDAC0A}" @@ -706,18 +704,6 @@ Global {A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}.Release|x64.Build.0 = Release|Any CPU {A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}.Release|x86.ActiveCfg = Release|Any CPU {A2C670CA-EFDD-468E-BEA1-D6D5A97270C4}.Release|x86.Build.0 = Release|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x64.ActiveCfg = Debug|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x64.Build.0 = Debug|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x86.ActiveCfg = Debug|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Debug|x86.Build.0 = Debug|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|Any CPU.Build.0 = Release|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x64.ActiveCfg = Release|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x64.Build.0 = Release|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x86.ActiveCfg = Release|Any CPU - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF}.Release|x86.Build.0 = Release|Any CPU {2C09FAF6-434D-442F-94B2-02AB906B477C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2C09FAF6-434D-442F-94B2-02AB906B477C}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C09FAF6-434D-442F-94B2-02AB906B477C}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -850,7 +836,6 @@ Global {A64647FF-BCBA-4B13-BC99-CDE23C1D3CE8} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3} {B786542C-3EE7-4B6C-9C5B-23E5CA4FE07C} = {5D11C19B-E8E4-4CE3-9C8A-1D368578EBCB} {A2C670CA-EFDD-468E-BEA1-D6D5A97270C4} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1} - {10D4A16B-F9F0-4D88-8705-7AB36E20D8EF} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3} {2C09FAF6-434D-442F-94B2-02AB906B477C} = {5D11C19B-E8E4-4CE3-9C8A-1D368578EBCB} {2EF6A468-3689-4407-8A11-2E3F5DEDAC0A} = {DF33E0FB-9790-4654-B60F-8AB22E0CC3D1} {9700269F-7954-49DE-8096-D5A941A2F4D0} = {8FFDF555-DB50-45F9-9A2D-6410F39151C3} diff --git a/sample/Sample.Classic.Restful/Sample.Classic.Restful.csproj b/sample/Sample.Classic.Restful/Sample.Classic.Restful.csproj index 21c54008e..6ee51ac1a 100644 --- a/sample/Sample.Classic.Restful/Sample.Classic.Restful.csproj +++ b/sample/Sample.Classic.Restful/Sample.Classic.Restful.csproj @@ -6,7 +6,7 @@ true - + Rockets { get; set; } = null!; public DbSet LaunchRecords { get; set; } = null!; - #if NET6_0_OR_GREATER protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) { configurationBuilder @@ -21,7 +20,6 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura .Properties() .HaveConversion(); } - #endif } public class StronglyTypedIdValueConverterSelector(ValueConverterSelectorDependencies dependencies) : ValueConverterSelector(dependencies) diff --git a/sample/Sample.Graphql/Sample.Graphql.csproj b/sample/Sample.Graphql/Sample.Graphql.csproj index 38bfcaeec..e0374f9ea 100644 --- a/sample/Sample.Graphql/Sample.Graphql.csproj +++ b/sample/Sample.Graphql/Sample.Graphql.csproj @@ -9,7 +9,7 @@ - + @@ -23,8 +23,4 @@ - - - - diff --git a/sample/Sample.Pages/Sample.Pages.csproj b/sample/Sample.Pages/Sample.Pages.csproj index 93f7aef6b..d024166fb 100644 --- a/sample/Sample.Pages/Sample.Pages.csproj +++ b/sample/Sample.Pages/Sample.Pages.csproj @@ -4,8 +4,6 @@ - - diff --git a/sample/Sample.Restful/Sample.Restful.csproj b/sample/Sample.Restful/Sample.Restful.csproj index aa5f17c01..b705e2f5a 100644 --- a/sample/Sample.Restful/Sample.Restful.csproj +++ b/sample/Sample.Restful/Sample.Restful.csproj @@ -6,7 +6,7 @@ true - + p.Type.AllInterfaces.Select( - static i => i is INamedTypeSymbol - { - MetadataName: "IOptionalTracking`1", TypeArguments: [var requestType,], - } + static i => i is + { MetadataName: "IOptionalTracking`1", TypeArguments: [var requestType,], } ? requestType : null ), diff --git a/src/AspNetCore/Rocket.Surgery.LaunchPad.AspNetCore.csproj b/src/AspNetCore/Rocket.Surgery.LaunchPad.AspNetCore.csproj index 980c40a4f..575ff2b27 100644 --- a/src/AspNetCore/Rocket.Surgery.LaunchPad.AspNetCore.csproj +++ b/src/AspNetCore/Rocket.Surgery.LaunchPad.AspNetCore.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Foundation/FoundationOptions.cs b/src/Foundation/FoundationOptions.cs index f0b7e44eb..42ea4bdac 100644 --- a/src/Foundation/FoundationOptions.cs +++ b/src/Foundation/FoundationOptions.cs @@ -1,5 +1,4 @@ -using System.Reflection; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection; using NodaTime.TimeZones; namespace Rocket.Surgery.LaunchPad.Foundation; @@ -10,14 +9,6 @@ namespace Rocket.Surgery.LaunchPad.Foundation; [PublicAPI] public class FoundationOptions { - /// - /// The executing assembly - /// - /// - /// Useful so that applications and conventions can know the "true" executing assembly when running in an environment like azure functions - /// - public Assembly? EntryAssembly { get; set; } - /// /// The NodaTime timezone source /// @@ -37,4 +28,4 @@ public class FoundationOptions /// Validation options are registered as health checks instead of throwing and stopping application startup /// public bool? RegisterValidationOptionsAsHealthChecks { get; set; } -} +} \ No newline at end of file diff --git a/src/HotChocolate/AssemblyInfoQuery.cs b/src/HotChocolate/AssemblyInfoQuery.cs index 91b90ff53..c67a0a163 100644 --- a/src/HotChocolate/AssemblyInfoQuery.cs +++ b/src/HotChocolate/AssemblyInfoQuery.cs @@ -1,16 +1,14 @@ using System.Reflection; using HotChocolate.Resolvers; using HotChocolate.Types; -using Microsoft.Extensions.DependencyInjection; -using Rocket.Surgery.LaunchPad.Foundation; namespace Rocket.Surgery.LaunchPad.HotChocolate; /// /// Returns assembly information for the given application /// -[ExtendObjectType(OperationTypeNames.Query)] [PublicAPI] +[ExtendObjectType(OperationTypeNames.Query)] public class AssemblyInfoQuery { /// @@ -19,12 +17,11 @@ public class AssemblyInfoQuery /// /// /// -#pragma warning disable CA1822 + #pragma warning disable CA1822 public AssemblyInfo Version(IResolverContext context, CancellationToken cancellationToken) -#pragma warning restore CA1822 + #pragma warning restore CA1822 { - return new AssemblyInfo( - context.Services.GetService()?.EntryAssembly ?? Assembly.GetEntryAssembly() ?? Assembly.GetCallingAssembly() - ); + // ReSharper disable once NullableWarningSuppressionIsUsed + return new(Assembly.GetEntryAssembly()!); } -} +} \ No newline at end of file diff --git a/src/Mapping/Profiles/NodaTimeProfile.cs b/src/Mapping/Profiles/NodaTimeProfile.cs index e4c5ec707..661fe49a9 100644 --- a/src/Mapping/Profiles/NodaTimeProfile.cs +++ b/src/Mapping/Profiles/NodaTimeProfile.cs @@ -35,24 +35,28 @@ public NodaTimeProfile() private void CreateMappingsForDurationConverter() { CreateMap().ConvertUsing(source => Duration.FromTicks((long)( source * NodaConstants.TicksPerMillisecond ))); - CreateMap().ConvertUsing( - source => source.HasValue ? Duration.FromTicks((long)( source.Value * NodaConstants.TicksPerMillisecond )) : default(Duration?) - ); + CreateMap() + .ConvertUsing( + source => source.HasValue ? Duration.FromTicks((long)( source.Value * NodaConstants.TicksPerMillisecond )) : default(Duration?) + ); CreateMap().ConvertUsing(source => Duration.FromTicks((long)( source * NodaConstants.TicksPerMillisecond ))); - CreateMap().ConvertUsing( - source => source.HasValue ? Duration.FromTicks((long)( source.Value * NodaConstants.TicksPerMillisecond )) : default(Duration?) - ); + CreateMap() + .ConvertUsing( + source => source.HasValue ? Duration.FromTicks((long)( source.Value * NodaConstants.TicksPerMillisecond )) : default(Duration?) + ); CreateMap().ConvertUsing(source => (decimal)source.BclCompatibleTicks / NodaConstants.TicksPerMillisecond); CreateMap().ConvertUsing(source => (double)source.BclCompatibleTicks / NodaConstants.TicksPerMillisecond); CreateMap().ConvertUsing(source => (int)( source.BclCompatibleTicks / NodaConstants.TicksPerSecond )); CreateMap().ConvertUsing(source => source.BclCompatibleTicks / NodaConstants.TicksPerMillisecond); CreateMap().ConvertUsing(source => source.ToTimeSpan()); - CreateMap().ConvertUsing( - source => source.HasValue ? (decimal)source.Value.BclCompatibleTicks / NodaConstants.TicksPerMillisecond : default(decimal?) - ); - CreateMap().ConvertUsing( - source => source.HasValue ? (double)source.Value.BclCompatibleTicks / NodaConstants.TicksPerMillisecond : default(double?) - ); + CreateMap() + .ConvertUsing( + source => source.HasValue ? (decimal)source.Value.BclCompatibleTicks / NodaConstants.TicksPerMillisecond : default(decimal?) + ); + CreateMap() + .ConvertUsing( + source => source.HasValue ? (double)source.Value.BclCompatibleTicks / NodaConstants.TicksPerMillisecond : default(double?) + ); CreateMap() .ConvertUsing(source => source.HasValue ? (int)( source.Value.BclCompatibleTicks / NodaConstants.TicksPerSecond ) : default(int?)); CreateMap() @@ -62,27 +66,30 @@ private void CreateMappingsForDurationConverter() CreateMap() .ConvertUsing(source => source.HasValue ? Duration.FromTicks(source.Value * NodaConstants.TicksPerSecond) : default(Duration?)); CreateMap().ConvertUsing(source => Duration.FromTicks(source * NodaConstants.TicksPerMillisecond)); - CreateMap().ConvertUsing( - source => source.HasValue ? Duration.FromTicks(source.Value * NodaConstants.TicksPerMillisecond) : default(Duration?) - ); + CreateMap() + .ConvertUsing( + source => source.HasValue ? Duration.FromTicks(source.Value * NodaConstants.TicksPerMillisecond) : default(Duration?) + ); CreateMap().ConvertUsing(source => Duration.FromTimeSpan(source)); CreateMap().ConvertUsing(source => source.HasValue ? Duration.FromTimeSpan(source.Value) : default(Duration?)); } private void CreateMappingsForInstantConvertor() { - CreateMap().ConvertUsing( - source => Instant.FromDateTimeUtc( - source.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(source, DateTimeKind.Utc) : source.ToUniversalTime() - ) - ); - CreateMap().ConvertUsing( - source => source.HasValue - ? Instant.FromDateTimeUtc( - source.Value.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(source.Value, DateTimeKind.Utc) : source.Value.ToUniversalTime() + CreateMap() + .ConvertUsing( + source => Instant.FromDateTimeUtc( + source.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(source, DateTimeKind.Utc) : source.ToUniversalTime() ) - : default - ); + ); + CreateMap() + .ConvertUsing( + source => source.HasValue + ? Instant.FromDateTimeUtc( + source.Value.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(source.Value, DateTimeKind.Utc) : source.Value.ToUniversalTime() + ) + : default + ); CreateMap().ConvertUsing(source => Instant.FromDateTimeOffset(source)); CreateMap().ConvertUsing(source => source.HasValue ? Instant.FromDateTimeOffset(source.Value) : default(Instant?)); CreateMap().ConvertUsing(source => source.ToDateTimeUtc()); @@ -97,12 +104,10 @@ private void CreateMappingsForLocalDateConverter() CreateMap().ConvertUsing(source => source.HasValue ? LocalDate.FromDateTime(source.Value) : default(LocalDate?)); CreateMap().ConvertUsing(source => source.AtMidnight().ToDateTimeUnspecified()); CreateMap().ConvertUsing(source => source.HasValue ? source.Value.AtMidnight().ToDateTimeUnspecified() : default(DateTime?)); -#if NET6_0_OR_GREATER CreateMap().ConvertUsing(source => LocalDate.FromDateOnly(source)); CreateMap().ConvertUsing(source => source.HasValue ? LocalDate.FromDateOnly(source.Value) : default(LocalDate?)); CreateMap().ConvertUsing(source => source.ToDateOnly()); CreateMap().ConvertUsing(source => source.HasValue ? source.Value.ToDateOnly() : default(DateOnly?)); -#endif } private void CreateMappingsForLocalDateTimeConverter() @@ -113,13 +118,11 @@ private void CreateMappingsForLocalDateTimeConverter() private void CreateMappingsForLocalTimeConverter() { -#if NET6_0_OR_GREATER CreateMap().ConvertUsing(source => LocalTime.FromTimeOnly(source)); CreateMap().ConvertUsing(source => source.HasValue ? LocalTime.FromTimeOnly(source.Value) : default(LocalTime?)); CreateMap().ConvertUsing(source => source.ToTimeOnly()); CreateMap().ConvertUsing(source => source.HasValue ? source.Value.ToTimeOnly() : default(TimeOnly?)); -#endif - CreateMap().ConvertUsing(source => new TimeSpan(source.TickOfDay)); + CreateMap().ConvertUsing(source => new(source.TickOfDay)); CreateMap().ConvertUsing(source => source.HasValue ? new TimeSpan(source.Value.TickOfDay) : default(TimeSpan?)); CreateMap().ConvertUsing(source => LocalTime.FromTicksSinceMidnight(source.Ticks)); CreateMap().ConvertUsing(source => source.HasValue ? LocalTime.FromTicksSinceMidnight(source.Value.Ticks) : default(LocalTime?)); @@ -147,4 +150,4 @@ private void CreateMappingsForPeriodConverter() CreateMap().ConvertUsing(source => source == default ? default : source.ToString()); CreateMap().ConvertUsing(source => ( source == default ? default : PeriodPattern.Roundtrip.Parse(source).Value ) ?? default(Period?)); } -} +} \ No newline at end of file diff --git a/src/Serilog/Conventions/SerilogReadFromConfigurationConvention.cs b/src/Serilog/Conventions/SerilogReadFromConfigurationConvention.cs index 2657e3b4d..43316f6e6 100644 --- a/src/Serilog/Conventions/SerilogReadFromConfigurationConvention.cs +++ b/src/Serilog/Conventions/SerilogReadFromConfigurationConvention.cs @@ -18,7 +18,6 @@ namespace Rocket.Surgery.LaunchPad.Serilog.Conventions; public class SerilogReadFromConfigurationConvention : ISerilogConvention, IConfigurationConvention { /// - #if NET6_0_OR_GREATER [UnconditionalSuppressMessage( "Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", @@ -29,7 +28,6 @@ public class SerilogReadFromConfigurationConvention : ISerilogConvention, IConfi "IL2066:The generic parameter of type or method has a DynamicallyAccessedMembersAttribute, but the value used for it can not be statically analyzed.", Justification = "The type is an enum value" )] - #endif public void Register(IConventionContext context, IConfiguration configuration, IConfigurationBuilder builder) { ArgumentNullException.ThrowIfNull(context); diff --git a/src/Telemetry/RocketSurgeryOpenTelemetryExtensions.cs b/src/Telemetry/RocketSurgeryOpenTelemetryExtensions.cs index 8458d2093..5a3d4e841 100644 --- a/src/Telemetry/RocketSurgeryOpenTelemetryExtensions.cs +++ b/src/Telemetry/RocketSurgeryOpenTelemetryExtensions.cs @@ -23,8 +23,8 @@ public static async ValueTask ApplyConventionsAsync( CancellationToken cancellationToken = default ) { - var configuration = conventionContext.Get() - ?? throw new ArgumentException("Configuration was not found in context", nameof(conventionContext)); + // If we don't get configuration, we're probably not needing telemetry + if (conventionContext.Get() is not { } configuration) return builder; foreach (var item in conventionContext.Conventions .Get - - - diff --git a/src/Web.Hosting/Rocket.Surgery.LaunchPad.Web.Hosting.csproj b/src/Web.Hosting/Rocket.Surgery.LaunchPad.Web.Hosting.csproj deleted file mode 100644 index 423ae61cc..000000000 --- a/src/Web.Hosting/Rocket.Surgery.LaunchPad.Web.Hosting.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - net8.0 - - $(PackageTags) - - - - - - - - - diff --git a/test/Analyzers.Tests/Analyzers.Tests.csproj b/test/Analyzers.Tests/Analyzers.Tests.csproj index d085ea6f6..9ea1d2eea 100644 --- a/test/Analyzers.Tests/Analyzers.Tests.csproj +++ b/test/Analyzers.Tests/Analyzers.Tests.csproj @@ -17,8 +17,5 @@ - - - diff --git a/test/Extensions.Tests/FakeClockConventionTests.cs b/test/Extensions.Tests/FakeClockConventionTests.cs index 4cf63ebf6..1f3fc286b 100644 --- a/test/Extensions.Tests/FakeClockConventionTests.cs +++ b/test/Extensions.Tests/FakeClockConventionTests.cs @@ -47,13 +47,13 @@ public async Task Should_Register_Options() [PublicAPI] private class OptionsA { - public string A { get; set; } + public required string A { get; set; } } [RegisterOptionsConfiguration("OptionsB")] [PublicAPI] private class OptionsB { - public string B { get; set; } + public required string B { get; set; } } } \ No newline at end of file diff --git a/test/Extensions.Tests/FeatureFactory.cs b/test/Extensions.Tests/FeatureFactory.cs index 768e521ac..ef1638cb6 100644 --- a/test/Extensions.Tests/FeatureFactory.cs +++ b/test/Extensions.Tests/FeatureFactory.cs @@ -1,5 +1,4 @@ #pragma warning disable CA5394 -#if NET6_0_OR_GREATER using NetTopologySuite.Features; using NetTopologySuite.Geometries; using NetTopologySuite.Mathematics; @@ -258,5 +257,4 @@ private double[] CreatePositions(int num) tmp.Sort(); return tmp.ToArray(); } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/LocalDateTests.cs b/test/Extensions.Tests/Mapping/LocalDateTests.cs index 61fab4057..99cdad3f1 100644 --- a/test/Extensions.Tests/Mapping/LocalDateTests.cs +++ b/test/Extensions.Tests/Mapping/LocalDateTests.cs @@ -85,12 +85,10 @@ public override IEnumerable GetTypeConverters() yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); - #if NET6_0_OR_GREATER yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); - #endif } } } \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/LocalTimeTests.cs b/test/Extensions.Tests/Mapping/LocalTimeTests.cs index 78b1f85b2..2f35da67a 100644 --- a/test/Extensions.Tests/Mapping/LocalTimeTests.cs +++ b/test/Extensions.Tests/Mapping/LocalTimeTests.cs @@ -1,9 +1,7 @@ using System.Reflection; using AutoMapper; using NodaTime; -#if NET6_0_OR_GREATER using NodaTime.Extensions; -#endif namespace Extensions.Tests.Mapping; @@ -43,6 +41,34 @@ public void MapsTo_DateTime() result.Should().Be(new(502 / 60, 502 % 60)); } + [Fact] + public void MapsFrom_DateTimeOffset() + { + var mapper = Config.CreateMapper(); + + var foo = new Foo1 + { + Bar = LocalTime.FromTicksSinceMidnight(10000), + }; + + var result = mapper.Map(foo).Bar; + result.Should().Be(foo.Bar.ToTimeOnly()); + } + + [Fact] + public void MapsTo_DateTimeOffset() + { + var mapper = Config.CreateMapper(); + + var foo = new Foo5 + { + Bar = TimeOnly.FromDateTime(DateTime.Now), + }; + + var result = mapper.Map(foo).Bar; + result.Should().Be(foo.Bar.ToLocalTime()); + } + [Theory] [ClassData(typeof(TypeConverterData))] public void AutomatedTests(Type source, Type destination, object? sourceValue) @@ -68,9 +94,7 @@ protected override void Configure(IMapperConfigurationExpression expression) ArgumentNullException.ThrowIfNull(expression); expression.CreateMap().ReverseMap(); - #if NET6_0_OR_GREATER expression.CreateMap().ReverseMap(); - #endif } private class Foo1 @@ -83,12 +107,10 @@ private class Foo3 public TimeSpan Bar { get; set; } } - #if NET6_0_OR_GREATER private class Foo5 { public TimeOnly Bar { get; set; } } - #endif public class Converters : TypeConverterFactory { @@ -98,42 +120,10 @@ public override IEnumerable GetTypeConverters() yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); - #if NET6_0_OR_GREATER yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); yield return typeof(ITypeConverter); - #endif } } - - #if NET6_0_OR_GREATER - [Fact] - public void MapsFrom_DateTimeOffset() - { - var mapper = Config.CreateMapper(); - - var foo = new Foo1 - { - Bar = LocalTime.FromTicksSinceMidnight(10000), - }; - - var result = mapper.Map(foo).Bar; - result.Should().Be(foo.Bar.ToTimeOnly()); - } - - [Fact] - public void MapsTo_DateTimeOffset() - { - var mapper = Config.CreateMapper(); - - var foo = new Foo5 - { - Bar = TimeOnly.FromDateTime(DateTime.Now), - }; - - var result = mapper.Map(foo).Bar; - result.Should().Be(foo.Bar.ToLocalTime()); - } - #endif } \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/TypeConverterTest.cs b/test/Extensions.Tests/Mapping/TypeConverterTest.cs index 33c1a600f..e6a597a38 100644 --- a/test/Extensions.Tests/Mapping/TypeConverterTest.cs +++ b/test/Extensions.Tests/Mapping/TypeConverterTest.cs @@ -68,11 +68,10 @@ private static object GetRandomValue(Type type) if (type == typeof(DateTime)) return Faker.Date.Recent(); if (type == typeof(DateTimeOffset)) return Faker.Date.RecentOffset(); - #if NET6_0_OR_GREATER + if (type == typeof(DateOnly)) return Faker.Date.RecentDateOnly(); if (type == typeof(TimeOnly)) return Faker.Date.RecentTimeOnly(); - #endif throw new NotSupportedException($"type {type.FullName} is not supported"); } diff --git a/test/Extensions.Tests/ModuleInitializer.cs b/test/Extensions.Tests/ModuleInitializer.cs index 07bdc25c2..17537942a 100644 --- a/test/Extensions.Tests/ModuleInitializer.cs +++ b/test/Extensions.Tests/ModuleInitializer.cs @@ -1,4 +1,3 @@ -#if NET6_0_OR_GREATER using System.Runtime.CompilerServices; using DiffEngine; @@ -24,5 +23,4 @@ static string GetTypeName(Type type) } ); } -} -#endif +} \ No newline at end of file diff --git a/test/Extensions.Tests/SerilogDestructuringTests.cs b/test/Extensions.Tests/SerilogDestructuringTests.cs index f2f45abb3..9e94f0a52 100644 --- a/test/Extensions.Tests/SerilogDestructuringTests.cs +++ b/test/Extensions.Tests/SerilogDestructuringTests.cs @@ -1,4 +1,3 @@ -#if NET6_0_OR_GREATER using System.Text.Json; using Microsoft.Extensions.Logging; using NetTopologySuite.Features; @@ -65,9 +64,9 @@ public async Task Should_Destructure_NewtonsoftJson_JArray() public async Task Should_Destructure_NewtonsoftJson_JValue() { var faker = new Faker - { - Random = new(17), - }; + { + Random = new(17), + }; using var _ = CaptureLogs(out var logs); Logger.LogInformation("This is just a test {@Data}", new JValue(faker.Random.Guid())); @@ -267,6 +266,4 @@ public async Task Should_Destructure_NetTopologySuite_Geometry(OgcGeometryType t Logger.LogInformation("This is just a test {@Data}", geometry); await Verify(logs.Select(z => z.RenderMessage())).UseParameters(type, threeD); } -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/test/Extensions.Tests/Validation/HealthCheckOptionsValidationTests.cs b/test/Extensions.Tests/Validation/HealthCheckOptionsValidationTests.cs index 203252675..6f8a53b49 100644 --- a/test/Extensions.Tests/Validation/HealthCheckOptionsValidationTests.cs +++ b/test/Extensions.Tests/Validation/HealthCheckOptionsValidationTests.cs @@ -1,4 +1,3 @@ -#if NET6_0_OR_GREATER using DryIoc; using FluentValidation; using Microsoft.Extensions.DependencyInjection; @@ -162,5 +161,4 @@ public Task DisposeAsync() { return Task.CompletedTask; } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/test/Extensions.Tests/Validation/OptionsValidationTests.cs b/test/Extensions.Tests/Validation/OptionsValidationTests.cs index 09d91d0a1..e89b329d3 100644 --- a/test/Extensions.Tests/Validation/OptionsValidationTests.cs +++ b/test/Extensions.Tests/Validation/OptionsValidationTests.cs @@ -1,4 +1,3 @@ -#if NET6_0_OR_GREATER using DryIoc; using FluentValidation; using Microsoft.Extensions.DependencyInjection; @@ -92,12 +91,7 @@ public async Task InitializeAsync() var conventionContextBuilder = ConventionContextBuilder .Create() .ForTesting(Imports.Instance, LoggerFactory) - .Set( - new FoundationOptions - { - RegisterValidationOptionsAsHealthChecks = false, - } - ) + .Set(new FoundationOptions { RegisterValidationOptionsAsHealthChecks = false, }) .WithLogger(Logger); var context = await ConventionContext.FromAsync(conventionContextBuilder); @@ -108,5 +102,4 @@ public Task DisposeAsync() { return Task.CompletedTask; } -} -#endif \ No newline at end of file +} \ No newline at end of file