diff --git a/Directory.Packages.props b/Directory.Packages.props index ad5fcd1ee..a064fa720 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -1,4 +1,4 @@ - + @@ -162,5 +162,8 @@ - + diff --git a/sample/Sample.BlazorServer/Pages/Rockets/Edit.razor.cs b/sample/Sample.BlazorServer/Pages/Rockets/Edit.razor.cs index e29c4a070..e44b14bf7 100644 --- a/sample/Sample.BlazorServer/Pages/Rockets/Edit.razor.cs +++ b/sample/Sample.BlazorServer/Pages/Rockets/Edit.razor.cs @@ -7,22 +7,25 @@ namespace Sample.BlazorServer.Pages.Rockets; public partial class Edit : ComponentBase { - [Parameter] public RocketId Id { get; set; } + [Parameter] + public RocketId Id { get; set; } public EditRocket.Request Model { get; set; } = new(); - [Inject] private NavigationManager NavigationManager { get; set; } = null!; + [Inject] + private NavigationManager NavigationManager { get; set; } = null!; - [Inject] private IMediator Mediator { get; set; } = null!; + [Inject] + private IMediator Mediator { get; set; } = null!; protected override async Task OnInitializedAsync() { - Model = EditRocket.MapRequest(await Mediator.Send(new GetRocket.Request { Id = Id })); + Model = EditRocket.MapRequest(await Mediator.Send(new GetRocket.Request { Id = Id, })); } public async Task Save() { - await Mediator.Send(Model with { Id = Id }); + await Mediator.Send(Model with { Id = Id, }); NavigationManager.NavigateTo("/rockets"); } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Models/LaunchRecordModel.cs b/sample/Sample.Core/Models/LaunchRecordModel.cs index 805a1e5d9..f43d9a7b7 100644 --- a/sample/Sample.Core/Models/LaunchRecordModel.cs +++ b/sample/Sample.Core/Models/LaunchRecordModel.cs @@ -66,5 +66,6 @@ internal static partial class ModelMapper { [MapperIgnoreSource(nameof(LaunchRecord.RocketId))] public static partial LaunchRecordModel Map(LaunchRecord launchRecord); + public static partial IQueryable ProjectTo(IQueryable rocket); -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Models/ModelMapper.cs b/sample/Sample.Core/Models/ModelMapper.cs index aec212b09..c473d9c77 100644 --- a/sample/Sample.Core/Models/ModelMapper.cs +++ b/sample/Sample.Core/Models/ModelMapper.cs @@ -1,12 +1,9 @@ using Riok.Mapperly.Abstractions; using Rocket.Surgery.LaunchPad.Mapping.Profiles; -using Sample.Core.Domain; namespace Sample.Core.Models; [Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Target)] [UseStaticMapper(typeof(StandardMapper))] [UseStaticMapper(typeof(NodaTimeMapper))] -internal static partial class ModelMapper -{ -} +internal static partial class ModelMapper { } \ No newline at end of file diff --git a/sample/Sample.Core/Models/RocketModel.cs b/sample/Sample.Core/Models/RocketModel.cs index 7f87b2e4a..575c6174e 100644 --- a/sample/Sample.Core/Models/RocketModel.cs +++ b/sample/Sample.Core/Models/RocketModel.cs @@ -1,5 +1,4 @@ using Riok.Mapperly.Abstractions; -using Rocket.Surgery.LaunchPad.Mapping.Profiles; using Sample.Core.Domain; using StronglyTypedIds; @@ -36,7 +35,8 @@ public record RocketModel internal static partial class ModelMapper { - [MapProperty(nameof(@ReadyRocket.SerialNumber), nameof(@RocketModel.Sn))] + [MapProperty(nameof(ReadyRocket.SerialNumber), nameof(RocketModel.Sn))] public static partial RocketModel Map(ReadyRocket rocket); + public static partial IQueryable ProjectTo(IQueryable rocket); -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Models/StandardMapper.cs b/sample/Sample.Core/Models/StandardMapper.cs index 489f23810..d6ae017ec 100644 --- a/sample/Sample.Core/Models/StandardMapper.cs +++ b/sample/Sample.Core/Models/StandardMapper.cs @@ -5,6 +5,13 @@ namespace Sample.Core; [Mapper] internal static partial class StandardMapper { - public static long LongToDouble(double value) => Convert.ToInt64(value); - public static double DoubleToLong(long value) => Convert.ToDouble(value); -} + public static long LongToDouble(double value) + { + return Convert.ToInt64(value); + } + + public static double DoubleToLong(long value) + { + return Convert.ToDouble(value); + } +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/LaunchRecords/CreateLaunchRecord.cs b/sample/Sample.Core/Operations/LaunchRecords/CreateLaunchRecord.cs index c90b39b1f..613679ce6 100644 --- a/sample/Sample.Core/Operations/LaunchRecords/CreateLaunchRecord.cs +++ b/sample/Sample.Core/Operations/LaunchRecords/CreateLaunchRecord.cs @@ -9,12 +9,15 @@ namespace Sample.Core.Operations.LaunchRecords; -[PublicAPI, Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Source)] +[PublicAPI] +[Mapper(RequiredMappingStrategy = RequiredMappingStrategy.Source)] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(ModelMapper))] [UseStaticMapper(typeof(StandardMapper))] public static partial class CreateLaunchRecord { + private static partial LaunchRecord Map(Request request); + /// /// Create a launch record /// @@ -83,8 +86,6 @@ public Validator() } } - private static partial LaunchRecord Map(Request request); - private class Handler(RocketDbContext dbContext) : IRequestHandler { public async Task Handle(Request request, CancellationToken cancellationToken) @@ -105,4 +106,4 @@ public async Task Handle(Request request, CancellationToken cancellati }; } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/LaunchRecords/DeleteLaunchRecord.cs b/sample/Sample.Core/Operations/LaunchRecords/DeleteLaunchRecord.cs index 3b2882d57..9fe647542 100644 --- a/sample/Sample.Core/Operations/LaunchRecords/DeleteLaunchRecord.cs +++ b/sample/Sample.Core/Operations/LaunchRecords/DeleteLaunchRecord.cs @@ -8,7 +8,8 @@ namespace Sample.Core.Operations.LaunchRecords; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class DeleteLaunchRecord { @@ -50,4 +51,4 @@ public async Task Handle(Request request, CancellationToken cancellationToken) await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/LaunchRecords/EditLaunchRecord.cs b/sample/Sample.Core/Operations/LaunchRecords/EditLaunchRecord.cs index 083c092f9..ec460961f 100644 --- a/sample/Sample.Core/Operations/LaunchRecords/EditLaunchRecord.cs +++ b/sample/Sample.Core/Operations/LaunchRecords/EditLaunchRecord.cs @@ -10,12 +10,27 @@ namespace Sample.Core.Operations.LaunchRecords; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(ModelMapper))] [UseStaticMapper(typeof(StandardMapper))] public static partial class EditLaunchRecord { + [MapperIgnoreTarget(nameof(LaunchRecord.Rocket))] + private static partial LaunchRecord Map(Request request); + + [MapperIgnoreSource(nameof(LaunchRecord.Rocket))] + private static partial Request Map(LaunchRecord model); + + [MapperIgnoreTarget(nameof(LaunchRecord.Rocket))] + private static partial void Map(Request request, LaunchRecord record); + + private static Request Map(PatchRequest request, LaunchRecord record) + { + return request.ApplyChanges(Map(record)); + } + /// /// The launch record update request /// @@ -93,28 +108,23 @@ public Validator() } } - [MapperIgnoreTarget(nameof(@LaunchRecord.Rocket))] - private static partial LaunchRecord Map(Request request); - - [MapperIgnoreSource(nameof(@LaunchRecord.Rocket))] - private static partial Request Map(LaunchRecord model); - - [MapperIgnoreTarget(nameof(@LaunchRecord.Rocket))] - private static partial void Map(Request request, LaunchRecord record); - private static Request Map(PatchRequest request, LaunchRecord record) => request.ApplyChanges(Map(record)); - private class Handler(RocketDbContext dbContext, IMediator mediator) : PatchRequestHandler(mediator), IRequestHandler { - private async Task GetLaunchRecord(LaunchRecordId id, CancellationToken cancellationToken) => await dbContext - .LaunchRecords - .Include(z => z.Rocket) - .FirstOrDefaultAsync(z => z.Id == id, cancellationToken) - .ConfigureAwait(false) - ?? throw new NotFoundException(); + private async Task GetLaunchRecord(LaunchRecordId id, CancellationToken cancellationToken) + { + return await dbContext + .LaunchRecords + .Include(z => z.Rocket) + .FirstOrDefaultAsync(z => z.Id == id, cancellationToken) + .ConfigureAwait(false) + ?? throw new NotFoundException(); + } protected override async Task GetRequest(PatchRequest patchRequest, CancellationToken cancellationToken) - => Map(patchRequest, await GetLaunchRecord(patchRequest.Id, cancellationToken)); + { + return Map(patchRequest, await GetLaunchRecord(patchRequest.Id, cancellationToken)); + } public async Task Handle(Request request, CancellationToken cancellationToken) { @@ -127,4 +137,4 @@ public async Task Handle(Request request, CancellationToken c return ModelMapper.Map(rocket); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/LaunchRecords/GetLaunchRecord.cs b/sample/Sample.Core/Operations/LaunchRecords/GetLaunchRecord.cs index ba951a5d6..87eeff864 100644 --- a/sample/Sample.Core/Operations/LaunchRecords/GetLaunchRecord.cs +++ b/sample/Sample.Core/Operations/LaunchRecords/GetLaunchRecord.cs @@ -9,7 +9,8 @@ namespace Sample.Core.Operations.LaunchRecords; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class GetLaunchRecord { @@ -47,4 +48,4 @@ public async Task Handle(Request request, CancellationToken c return ModelMapper.Map(rocket); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/LaunchRecords/ListLaunchRecords.cs b/sample/Sample.Core/Operations/LaunchRecords/ListLaunchRecords.cs index c53e8b48b..d0e1dd25e 100644 --- a/sample/Sample.Core/Operations/LaunchRecords/ListLaunchRecords.cs +++ b/sample/Sample.Core/Operations/LaunchRecords/ListLaunchRecords.cs @@ -8,12 +8,15 @@ namespace Sample.Core.Operations.LaunchRecords; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(ModelMapper))] [UseStaticMapper(typeof(StandardMapper))] public static partial class ListLaunchRecords { + private static partial IQueryable Project(IQueryable queryable); + /// /// The launch record search /// @@ -23,7 +26,6 @@ public record Request(RocketType? RocketType) : IStreamRequest; - private static partial IQueryable Project(IQueryable queryable); private class Handler(RocketDbContext dbContext) : IStreamRequestHandler { public IAsyncEnumerable Handle(Request request, CancellationToken cancellationToken) @@ -37,4 +39,4 @@ public IAsyncEnumerable Handle(Request request, CancellationT return Project(query).ToAsyncEnumerable(); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/CreateRocket.cs b/sample/Sample.Core/Operations/Rockets/CreateRocket.cs index d537b7a41..0c94d220d 100644 --- a/sample/Sample.Core/Operations/Rockets/CreateRocket.cs +++ b/sample/Sample.Core/Operations/Rockets/CreateRocket.cs @@ -9,12 +9,16 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(ModelMapper))] [UseStaticMapper(typeof(StandardMapper))] public static partial class CreateRocket { + [MapperRequiredMapping(RequiredMappingStrategy.Source)] + private static partial ReadyRocket Map(Request request); + /// /// The operation to create a new rocket record /// @@ -56,8 +60,6 @@ public Validator() } } - [MapperRequiredMapping(RequiredMappingStrategy.Source)] - private static partial ReadyRocket Map(Request request); private class Handler(RocketDbContext dbContext) : IRequestHandler { public async Task Handle(Request request, CancellationToken cancellationToken) @@ -90,4 +92,4 @@ public async Task Handle(Request request, CancellationToken cancellati }; } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/DeleteRocket.cs b/sample/Sample.Core/Operations/Rockets/DeleteRocket.cs index 9e6b6a24b..9920edf9c 100644 --- a/sample/Sample.Core/Operations/Rockets/DeleteRocket.cs +++ b/sample/Sample.Core/Operations/Rockets/DeleteRocket.cs @@ -8,7 +8,8 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class DeleteRocket { @@ -44,4 +45,4 @@ public async Task Handle(Request request, CancellationToken cancellationToken) await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/EditRocket.cs b/sample/Sample.Core/Operations/Rockets/EditRocket.cs index da99ca808..828f250d1 100644 --- a/sample/Sample.Core/Operations/Rockets/EditRocket.cs +++ b/sample/Sample.Core/Operations/Rockets/EditRocket.cs @@ -8,12 +8,32 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(ModelMapper))] [UseStaticMapper(typeof(StandardMapper))] public static partial class EditRocket { + [MapperRequiredMapping(RequiredMappingStrategy.Target)] + public static partial Request MapRequest(ReadyRocket model); + + [MapperRequiredMapping(RequiredMappingStrategy.Target)] + [MapProperty(nameof(RocketModel.Sn), nameof(Request.SerialNumber))] + public static partial Request MapRequest(RocketModel model); + + [MapperRequiredMapping(RequiredMappingStrategy.Source)] + private static partial ReadyRocket Map(Request request); + + [MapperRequiredMapping(RequiredMappingStrategy.Source)] + private static partial void Map(Request request, ReadyRocket record); + + [MapperRequiredMapping(RequiredMappingStrategy.Source)] + private static Request Map(PatchRequest request, ReadyRocket rocket) + { + return request.ApplyChanges(MapRequest(rocket)); + } + /// /// The edit operation to update a rocket /// @@ -62,19 +82,6 @@ public RequestValidator() } } - [MapperRequiredMapping(RequiredMappingStrategy.Source)] - private static partial ReadyRocket Map(Request request); - [MapperRequiredMapping(RequiredMappingStrategy.Target)] - public static partial Request MapRequest(ReadyRocket model); - [MapperRequiredMapping(RequiredMappingStrategy.Target)] - [MapProperty(nameof(@RocketModel.Sn), nameof(@Request.SerialNumber))] - public static partial Request MapRequest(RocketModel model); - [MapperRequiredMapping(RequiredMappingStrategy.Source)] - private static partial void Map(Request request, ReadyRocket record); - - [MapperRequiredMapping(RequiredMappingStrategy.Source)] - private static Request Map(PatchRequest request, ReadyRocket rocket) => request.ApplyChanges(MapRequest(rocket)); - private class RequestHandler(RocketDbContext dbContext, IMediator mediator) : PatchRequestHandler(mediator), IRequestHandler { @@ -87,7 +94,9 @@ private async Task GetRocket(RocketId id, CancellationToken cancell } protected override async Task GetRequest(PatchRequest patchRequest, CancellationToken cancellationToken) - => Map(patchRequest, await GetRocket(patchRequest.Id, cancellationToken)); + { + return Map(patchRequest, await GetRocket(patchRequest.Id, cancellationToken)); + } public async Task Handle(Request request, CancellationToken cancellationToken) { @@ -101,4 +110,4 @@ public async Task Handle(Request request, CancellationToken cancell return ModelMapper.Map(rocket); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/GetRocket.cs b/sample/Sample.Core/Operations/Rockets/GetRocket.cs index a991bd372..af0625453 100644 --- a/sample/Sample.Core/Operations/Rockets/GetRocket.cs +++ b/sample/Sample.Core/Operations/Rockets/GetRocket.cs @@ -8,7 +8,8 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class GetRocket { @@ -36,6 +37,8 @@ public Validator() private class Handler(RocketDbContext dbContext) : IRequestHandler { public async Task Handle(Request request, CancellationToken cancellationToken) - => ModelMapper.Map(await dbContext.Rockets.FindAsync([request.Id,], cancellationToken).ConfigureAwait(false) ?? throw new NotFoundException()); + { + return ModelMapper.Map(await dbContext.Rockets.FindAsync([request.Id,], cancellationToken).ConfigureAwait(false) ?? throw new NotFoundException()); + } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecord.cs b/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecord.cs index bca4de664..fcd3fb5e2 100644 --- a/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecord.cs +++ b/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecord.cs @@ -8,7 +8,8 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class GetRocketLaunchRecord { @@ -45,4 +46,4 @@ public async Task Handle(Request request, CancellationToken c return ModelMapper.Map(await dbContext.LaunchRecords.FindAsync([request.LaunchRecordId,], cancellationToken) ?? throw new NotFoundException()); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecords.cs b/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecords.cs index f923dab59..9bd52fb72 100644 --- a/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecords.cs +++ b/sample/Sample.Core/Operations/Rockets/GetRocketLaunchRecords.cs @@ -10,7 +10,8 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class GetRocketLaunchRecords { @@ -46,4 +47,4 @@ public async IAsyncEnumerable Handle(Request request, [Enumer } } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Operations/Rockets/ListRockets.cs b/sample/Sample.Core/Operations/Rockets/ListRockets.cs index b9bef3611..aa5a99716 100644 --- a/sample/Sample.Core/Operations/Rockets/ListRockets.cs +++ b/sample/Sample.Core/Operations/Rockets/ListRockets.cs @@ -8,7 +8,8 @@ namespace Sample.Core.Operations.Rockets; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public static partial class ListRockets { @@ -30,4 +31,4 @@ public IAsyncEnumerable Handle(Request request, CancellationToken c return ModelMapper.ProjectTo(query).AsAsyncEnumerable(); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Core/Properties/Mapping.cs b/sample/Sample.Core/Properties/Mapping.cs index 525d60072..149e35db1 100644 --- a/sample/Sample.Core/Properties/Mapping.cs +++ b/sample/Sample.Core/Properties/Mapping.cs @@ -1,2 +1,7 @@ using Riok.Mapperly.Abstractions; -[assembly: MapperDefaults(EnumMappingIgnoreCase = true, EnabledConversions = MappingConversionType.All ^ MappingConversionType.ImplicitCast ^ MappingConversionType.ExplicitCast)] + +[assembly: + MapperDefaults( + EnumMappingIgnoreCase = true, + EnabledConversions = MappingConversionType.All ^ MappingConversionType.ImplicitCast ^ MappingConversionType.ExplicitCast + )] \ No newline at end of file diff --git a/sample/Sample.Grpc/Services/LaunchRecordsService.cs b/sample/Sample.Grpc/Services/LaunchRecordsService.cs index a4b4d8457..089ba2cd3 100644 --- a/sample/Sample.Grpc/Services/LaunchRecordsService.cs +++ b/sample/Sample.Grpc/Services/LaunchRecordsService.cs @@ -13,11 +13,23 @@ namespace Sample.Grpc.Services; [UseStaticMapper(typeof(WellKnownGrpcTypesMapper))] public partial class LaunchRecordsService(IMediator mediator) : LaunchRecords.LaunchRecordsBase { + public static partial CreateLaunchRecord.Request Map(CreateLaunchRecordRequest request); + public static partial CreateLaunchRecordResponse Map(CreateLaunchRecord.Response request); + public static partial GetLaunchRecord.Request Map(GetLaunchRecordRequest request); + public static partial EditLaunchRecord.Request Map(UpdateLaunchRecordRequest request); + public static partial ListLaunchRecords.Request Map(ListLaunchRecordsRequest request); + public static partial DeleteLaunchRecord.Request Map(DeleteLaunchRecordRequest request); + public static partial LaunchRecordModel Map(Core.Models.LaunchRecordModel request); + public override async Task CreateLaunchRecord(CreateLaunchRecordRequest request, ServerCallContext context) - => Map(await mediator.Send(Map(request), context.CancellationToken)); + { + return Map(await mediator.Send(Map(request), context.CancellationToken)); + } public override async Task EditLaunchRecord(UpdateLaunchRecordRequest request, ServerCallContext context) - => Map(await mediator.Send(Map(request), context.CancellationToken)); + { + return Map(await mediator.Send(Map(request), context.CancellationToken)); + } public override async Task DeleteLaunchRecord(DeleteLaunchRecordRequest request, ServerCallContext context) { @@ -26,7 +38,9 @@ public override async Task DeleteLaunchRecord(DeleteLaunchRecordRequest r } public override async Task GetLaunchRecords(GetLaunchRecordRequest request, ServerCallContext context) - => Map(await mediator.Send(Map(request), context.CancellationToken)); + { + return Map(await mediator.Send(Map(request), context.CancellationToken)); + } public override async Task ListLaunchRecords( ListLaunchRecordsRequest request, @@ -40,14 +54,6 @@ ServerCallContext context } } - public static partial CreateLaunchRecord.Request Map(CreateLaunchRecordRequest request); - public static partial CreateLaunchRecordResponse Map(CreateLaunchRecord.Response request); - public static partial GetLaunchRecord.Request Map(GetLaunchRecordRequest request); - public static partial EditLaunchRecord.Request Map(UpdateLaunchRecordRequest request); - public static partial ListLaunchRecords.Request Map(ListLaunchRecordsRequest request); - public static partial DeleteLaunchRecord.Request Map(DeleteLaunchRecordRequest request); - public static partial LaunchRecordModel Map(Core.Models.LaunchRecordModel request); - [UsedImplicitly] private class CreateLaunchRecordRequestValidator : AbstractValidator { @@ -119,4 +125,4 @@ public DeleteLaunchRecordRequestValidator() .NotNull(); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Grpc/Services/RocketsService.cs b/sample/Sample.Grpc/Services/RocketsService.cs index 3de402ccf..1cf26745b 100644 --- a/sample/Sample.Grpc/Services/RocketsService.cs +++ b/sample/Sample.Grpc/Services/RocketsService.cs @@ -4,7 +4,6 @@ using MediatR; using Riok.Mapperly.Abstractions; using Rocket.Surgery.LaunchPad.Mapping.Profiles; -using Sample.Core.Models; using Sample.Core.Operations.Rockets; namespace Sample.Grpc.Services; @@ -14,11 +13,23 @@ namespace Sample.Grpc.Services; [UseStaticMapper(typeof(WellKnownGrpcTypesMapper))] public partial class RocketsService(IMediator mediator) : Rockets.RocketsBase { + public static partial CreateRocket.Request Map(CreateRocketRequest request); + public static partial CreateRocketResponse Map(CreateRocket.Response request); + public static partial GetRocket.Request Map(GetRocketRequest request); + public static partial EditRocket.Request Map(UpdateRocketRequest request); + public static partial ListRockets.Request Map(ListRocketsRequest request); + public static partial DeleteRocket.Request Map(DeleteRocketRequest request); + public static partial RocketModel Map(Core.Models.RocketModel request); + public override async Task CreateRocket(CreateRocketRequest request, ServerCallContext context) - => Map(await mediator.Send(Map(request), context.CancellationToken)); + { + return Map(await mediator.Send(Map(request), context.CancellationToken)); + } public override async Task EditRocket(UpdateRocketRequest request, ServerCallContext context) - => Map(await mediator.Send(Map(request), context.CancellationToken)); + { + return Map(await mediator.Send(Map(request), context.CancellationToken)); + } public override async Task DeleteRocket(DeleteRocketRequest request, ServerCallContext context) { @@ -27,7 +38,9 @@ public override async Task DeleteRocket(DeleteRocketRequest request, Serv } public override async Task GetRockets(GetRocketRequest request, ServerCallContext context) - => Map(await mediator.Send(Map(request), context.CancellationToken)); + { + return Map(await mediator.Send(Map(request), context.CancellationToken)); + } public override async Task ListRockets(ListRocketsRequest request, IServerStreamWriter responseStream, ServerCallContext context) { @@ -37,14 +50,6 @@ public override async Task ListRockets(ListRocketsRequest request, IServerStream } } - public static partial CreateRocket.Request Map(CreateRocketRequest request); - public static partial CreateRocketResponse Map(CreateRocket.Response request); - public static partial GetRocket.Request Map(GetRocketRequest request); - public static partial EditRocket.Request Map(UpdateRocketRequest request); - public static partial ListRockets.Request Map(ListRocketsRequest request); - public static partial DeleteRocket.Request Map(DeleteRocketRequest request); - public static partial RocketModel Map(Core.Models.RocketModel request); - [UsedImplicitly] private class CreateRocketRequestValidator : AbstractValidator { @@ -104,4 +109,4 @@ public DeleteRocketRequestValidator() .NotNull(); } } -} +} \ No newline at end of file diff --git a/sample/Sample.Grpc/WellKnownGrpcTypesMapper.cs b/sample/Sample.Grpc/WellKnownGrpcTypesMapper.cs index 12425ed57..e3074e2c0 100644 --- a/sample/Sample.Grpc/WellKnownGrpcTypesMapper.cs +++ b/sample/Sample.Grpc/WellKnownGrpcTypesMapper.cs @@ -7,42 +7,87 @@ namespace Sample.Grpc; -[PublicAPI, Mapper] +[PublicAPI] +[Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] public partial class WellKnownGrpcTypesMapper { - public static Instant ConvertToInstant(Timestamp ts) => Instant.FromDateTimeOffset(ts.ToDateTimeOffset()); - public static Timestamp ConvertToTimestamp(Instant ts) => Timestamp.FromDateTimeOffset(ts.ToDateTimeOffset()); + public static Instant ConvertToInstant(Timestamp ts) + { + return Instant.FromDateTimeOffset(ts.ToDateTimeOffset()); + } - public static Instant? ConvertToNullableInstant(NullableTimestamp ts) => - ts.KindCase == NullableTimestamp.KindOneofCase.Data + public static Timestamp ConvertToTimestamp(Instant ts) + { + return Timestamp.FromDateTimeOffset(ts.ToDateTimeOffset()); + } + + public static Instant? ConvertToNullableInstant(NullableTimestamp ts) + { + return ts.KindCase == NullableTimestamp.KindOneofCase.Data ? Instant.FromDateTimeOffset(ts.Data.ToDateTimeOffset()) : default; + } + + public static NullableTimestamp ConvertFromNullableInstant(Instant? ts) + { + return ts.HasValue + ? new() { Data = Timestamp.FromDateTimeOffset(ts.Value.ToDateTimeOffset()), } + : new() { Null = NullValue.NullValue, }; + } + + public static NullableTimestamp ConvertFromInstant(Instant ts) + { + return new() { Data = Timestamp.FromDateTimeOffset(ts.ToDateTimeOffset()), }; + } - public static NullableTimestamp ConvertFromNullableInstant(Instant? ts) => ts.HasValue - ? new() { Data = Timestamp.FromDateTimeOffset(ts.Value.ToDateTimeOffset()) } - : new() { Null = NullValue.NullValue }; + public static Instant ConvertFromInstant(NullableTimestamp ts) + { + return Instant.FromDateTimeOffset(ts.Data.ToDateTimeOffset()); + } - public static NullableTimestamp ConvertFromInstant(Instant ts) => new() { Data = Timestamp.FromDateTimeOffset(ts.ToDateTimeOffset()) }; - public static Instant ConvertFromInstant(NullableTimestamp ts) => Instant.FromDateTimeOffset(ts.Data.ToDateTimeOffset()); + public static Duration ConvertToDuration(WktDuration ts) + { + return Duration.FromTimeSpan(ts.ToTimeSpan()); + } - public static Duration ConvertToDuration(WktDuration ts) => Duration.FromTimeSpan(ts.ToTimeSpan()); - public static WktDuration ConvertToWktDuration(Duration ts) => WktDuration.FromTimeSpan(ts.ToTimeSpan()); + public static WktDuration ConvertToWktDuration(Duration ts) + { + return WktDuration.FromTimeSpan(ts.ToTimeSpan()); + } - public static TimeSpan ConvertToTimeSpan(WktDuration ts) => ts.ToTimeSpan(); - public static WktDuration ConvertToWktDuration(TimeSpan ts) => WktDuration.FromTimeSpan(ts); + public static TimeSpan ConvertToTimeSpan(WktDuration ts) + { + return ts.ToTimeSpan(); + } + + public static WktDuration ConvertToWktDuration(TimeSpan ts) + { + return WktDuration.FromTimeSpan(ts); + } public static partial RocketType MapRocketType(Core.Domain.RocketType request); public static partial Core.Domain.RocketType MapRocketType(RocketType request); - public static NullableRocketType MapNullableRocketType(Core.Domain.RocketType request) => new() { Data = (RocketType)request }; - public static Core.Domain.RocketType MapNullableRocketType(NullableRocketType request) => (Core.Domain.RocketType)request.Data; + public static NullableRocketType MapNullableRocketType(Core.Domain.RocketType request) + { + return new() { Data = (RocketType)request, }; + } + + public static Core.Domain.RocketType MapNullableRocketType(NullableRocketType request) + { + return (Core.Domain.RocketType)request.Data; + } - public static NullableRocketType MapRocketType(Core.Domain.RocketType? request) => - request.HasValue ? new() { Data = (RocketType)request.Value } : new() { Null = NullValue.NullValue }; + public static NullableRocketType MapRocketType(Core.Domain.RocketType? request) + { + return request.HasValue ? new() { Data = (RocketType)request.Value, } : new() { Null = NullValue.NullValue, }; + } - public static Core.Domain.RocketType? MapRocketType(NullableRocketType request) => - request.KindCase == NullableRocketType.KindOneofCase.Data + public static Core.Domain.RocketType? MapRocketType(NullableRocketType request) + { + return request.KindCase == NullableRocketType.KindOneofCase.Data ? (Core.Domain.RocketType)request.Data : default; -} + } +} \ No newline at end of file diff --git a/sample/Sample.Pages/Pages/Rockets/Edit.cshtml.cs b/sample/Sample.Pages/Pages/Rockets/Edit.cshtml.cs index b62612560..cab4d0261 100644 --- a/sample/Sample.Pages/Pages/Rockets/Edit.cshtml.cs +++ b/sample/Sample.Pages/Pages/Rockets/Edit.cshtml.cs @@ -5,7 +5,8 @@ namespace Sample.Pages.Pages.Rockets; public class RocketEditModel : RocketViewModel { - [BindProperty] public EditRocket.Request Model { get; set; } = new(); + [BindProperty] + public EditRocket.Request Model { get; set; } = new(); public override async Task OnGet() { @@ -21,7 +22,7 @@ public async Task OnPost() return Page(); } - await Send(Model with { Id = Id }); + await Send(Model with { Id = Id, }); return RedirectToPage("Index"); } -} +} \ No newline at end of file diff --git a/src/Foundation/Conventions/SystemTextJsonConvention.cs b/src/Foundation/Conventions/SystemTextJsonConvention.cs index 64754308e..b7acf4c61 100644 --- a/src/Foundation/Conventions/SystemTextJsonConvention.cs +++ b/src/Foundation/Conventions/SystemTextJsonConvention.cs @@ -49,4 +49,4 @@ public void Register(IConventionContext context, IConfiguration configuration, I ) ); } -} +} \ No newline at end of file diff --git a/src/Mapping.NewtonsoftJson/NewtonsoftJsonMapper.cs b/src/Mapping.NewtonsoftJson/NewtonsoftJsonMapper.cs index 89bd6b315..4e3ac679c 100644 --- a/src/Mapping.NewtonsoftJson/NewtonsoftJsonMapper.cs +++ b/src/Mapping.NewtonsoftJson/NewtonsoftJsonMapper.cs @@ -8,56 +8,84 @@ namespace Rocket.Surgery.LaunchPad.Mapping; /// -/// Configures methods for handling well-known conversions for Newtonsoft.Json +/// Configures methods for handling well-known conversions for Newtonsoft.Json /// -[Mapper, PublicAPI] +[Mapper] +[PublicAPI] public partial class NewtonsoftJsonMapper(IOptionsMonitor jsonSerializerOptions) { /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// A representation of the , or the default if the is null. - public JsonElement FromJObject(JObject? source) => source == null ? default : JsonDocument.Parse(WriteToBytes(source)).RootElement.Clone(); + /// The to convert. + /// + /// A representation of the , or the default if the is + /// null. + /// + public JsonElement FromJObject(JObject? source) + { + return source == null ? default : JsonDocument.Parse(WriteToBytes(source)).RootElement.Clone(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// A representation of the , or null if the is undefined. - public JObject? ToJObject(JsonElement source) => source.ValueKind == JsonValueKind.Undefined - ? default - : JObject.Parse(JsonSerializer.Serialize(source, jsonSerializerOptions.CurrentValue)); + /// The to convert. + /// A representation of the , or null if the is undefined. + public JObject? ToJObject(JsonElement source) + { + return source.ValueKind == JsonValueKind.Undefined + ? default + : JObject.Parse(JsonSerializer.Serialize(source, jsonSerializerOptions.CurrentValue)); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// A representation of the , or the default if the is null. - public JsonElement FromJArray(JArray? source) => source == default ? default : JsonDocument.Parse(WriteToBytes(source)).RootElement.Clone(); + /// The to convert. + /// + /// A representation of the , or the default if the is + /// null. + /// + public JsonElement FromJArray(JArray? source) + { + return source == default ? default : JsonDocument.Parse(WriteToBytes(source)).RootElement.Clone(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// A representation of the , or null if the is undefined. - public JArray? ToJArray(JsonElement source) => source.ValueKind == JsonValueKind.Undefined - ? default - : JArray.Parse(JsonSerializer.Serialize(source, jsonSerializerOptions.CurrentValue)); + /// The to convert. + /// A representation of the , or null if the is undefined. + public JArray? ToJArray(JsonElement source) + { + return source.ValueKind == JsonValueKind.Undefined + ? default + : JArray.Parse(JsonSerializer.Serialize(source, jsonSerializerOptions.CurrentValue)); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// A representation of the , or the default if the is null. - public JsonElement FromJToken(JToken? source) => source == null ? default : JsonDocument.Parse(WriteToBytes(source)).RootElement.Clone(); + /// The to convert. + /// + /// A representation of the , or the default if the is + /// null. + /// + public JsonElement FromJToken(JToken? source) + { + return source == null ? default : JsonDocument.Parse(WriteToBytes(source)).RootElement.Clone(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// A representation of the , or null if the is undefined. - public JToken? ToJToken(JsonElement source) => source.ValueKind == JsonValueKind.Undefined - ? default - : JToken.Parse(JsonSerializer.Serialize(source, jsonSerializerOptions.CurrentValue)); -} + /// The to convert. + /// A representation of the , or null if the is undefined. + public JToken? ToJToken(JsonElement source) + { + return source.ValueKind == JsonValueKind.Undefined + ? default + : JToken.Parse(JsonSerializer.Serialize(source, jsonSerializerOptions.CurrentValue)); + } +} \ No newline at end of file diff --git a/src/Mapping/DateTimeMapper.cs b/src/Mapping/DateTimeMapper.cs index 9c1b3cd99..5407e11d0 100644 --- a/src/Mapping/DateTimeMapper.cs +++ b/src/Mapping/DateTimeMapper.cs @@ -3,29 +3,36 @@ namespace Rocket.Surgery.LaunchPad.Mapping; /// -/// A mapper used to map between and +/// A mapper used to map between and /// /// -/// If you're using this type... you know what you're doing or you're doing it wrong. +/// If you're using this type... you know what you're doing or you're doing it wrong. /// -[Mapper, PublicAPI] +[Mapper] +[PublicAPI] public partial class DateTimeMapper { /// - /// Converts a to a . + /// Converts a to a . /// /// /// - public static DateTime FromDateTimeOffset(DateTimeOffset source) => source.UtcDateTime; -/// -/// Converts a to a . -/// -/// -/// - public static DateTimeOffset ToDateTimeOffset(DateTime source) => - source switch - { - { Kind: DateTimeKind.Unspecified or DateTimeKind.Local } => new(source.ToUniversalTime(), TimeSpan.Zero), - { Kind: DateTimeKind.Utc } => new(source, TimeSpan.Zero), - }; -} + public static DateTime FromDateTimeOffset(DateTimeOffset source) + { + return source.UtcDateTime; + } + + /// + /// Converts a to a . + /// + /// + /// + public static DateTimeOffset ToDateTimeOffset(DateTime source) + { + return source switch + { + { Kind: DateTimeKind.Unspecified or DateTimeKind.Local, } => new(source.ToUniversalTime(), TimeSpan.Zero), + { Kind: DateTimeKind.Utc, } => new(source, TimeSpan.Zero), + }; + } +} \ No newline at end of file diff --git a/src/Mapping/NodaTimeDateTimeMapper.cs b/src/Mapping/NodaTimeDateTimeMapper.cs index fcb5388b5..07b083ecb 100644 --- a/src/Mapping/NodaTimeDateTimeMapper.cs +++ b/src/Mapping/NodaTimeDateTimeMapper.cs @@ -4,72 +4,96 @@ namespace Rocket.Surgery.LaunchPad.Mapping; /// -/// A mapper used to map between NodaTime and +/// A mapper used to map between NodaTime and /// /// -/// If you're using this type... you know what you're doing or you're doing it wrong. +/// If you're using this type... you know what you're doing or you're doing it wrong. /// -[Mapper, PublicAPI] +[Mapper] +[PublicAPI] public partial class NodaTimeDateTimeMapper { /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static Instant ToInstant(DateTime source) => - Instant.FromDateTimeUtc( + /// The to convert. + /// The equivalent . + public static Instant ToInstant(DateTime source) + { + return Instant.FromDateTimeUtc( source.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(source, DateTimeKind.Utc) : source.ToUniversalTime() ); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static DateTime FromInstant(Instant source) => source.ToDateTimeUtc(); + /// The to convert. + /// The equivalent . + public static DateTime FromInstant(Instant source) + { + return source.ToDateTimeUtc(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static LocalDate ToLocalDate(DateTime source) => LocalDate.FromDateTime(source); + /// The to convert. + /// The equivalent . + public static LocalDate ToLocalDate(DateTime source) + { + return LocalDate.FromDateTime(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static DateTime FromLocalDate(LocalDate source) => source.AtMidnight().ToDateTimeUnspecified(); + /// The to convert. + /// The equivalent . + public static DateTime FromLocalDate(LocalDate source) + { + return source.AtMidnight().ToDateTimeUnspecified(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static LocalDateTime ToLocalDateTime(DateTime source) => LocalDateTime.FromDateTime(source); + /// The to convert. + /// The equivalent . + public static LocalDateTime ToLocalDateTime(DateTime source) + { + return LocalDateTime.FromDateTime(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static DateTime FromLocalDateTime(LocalDateTime source) => source.ToDateTimeUnspecified(); + /// The to convert. + /// The equivalent . + public static DateTime FromLocalDateTime(LocalDateTime source) + { + return source.ToDateTimeUnspecified(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static LocalTime ToLocalTime(TimeSpan source) => LocalTime.FromTicksSinceMidnight(source.Ticks); + /// The to convert. + /// The equivalent . + public static LocalTime ToLocalTime(TimeSpan source) + { + return LocalTime.FromTicksSinceMidnight(source.Ticks); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static TimeSpan FromLocalTime(LocalTime source) => new(source.TickOfDay); -} + /// The to convert. + /// The equivalent . + public static TimeSpan FromLocalTime(LocalTime source) + { + return new(source.TickOfDay); + } +} \ No newline at end of file diff --git a/src/Mapping/NodaTimeMapper.cs b/src/Mapping/NodaTimeMapper.cs index 80e9a6987..89fce7f6f 100644 --- a/src/Mapping/NodaTimeMapper.cs +++ b/src/Mapping/NodaTimeMapper.cs @@ -5,106 +5,149 @@ namespace Rocket.Surgery.LaunchPad.Mapping.Profiles; /// -/// A mapper used to map between NodaTime and , , and +/// A mapper used to map between NodaTime and , , and /// -[Mapper, PublicAPI] +[Mapper] +[PublicAPI] public static partial class NodaTimeMapper { /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static Duration ToDuration(TimeSpan source) => Duration.FromTimeSpan(source); + /// The to convert. + /// The equivalent . + public static Duration ToDuration(TimeSpan source) + { + return Duration.FromTimeSpan(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static TimeSpan FromDuration(Duration source) => source.ToTimeSpan(); + /// The to convert. + /// The equivalent . + public static TimeSpan FromDuration(Duration source) + { + return source.ToTimeSpan(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static Instant ToInstant(DateTimeOffset source) => Instant.FromDateTimeOffset(source); + /// The to convert. + /// The equivalent . + public static Instant ToInstant(DateTimeOffset source) + { + return Instant.FromDateTimeOffset(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static DateTimeOffset FromInstant(Instant source) => source.ToDateTimeOffset(); + /// The to convert. + /// The equivalent . + public static DateTimeOffset FromInstant(Instant source) + { + return source.ToDateTimeOffset(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static LocalDate ToLocalDate(DateOnly source) => LocalDate.FromDateOnly(source); + /// The to convert. + /// The equivalent . + public static LocalDate ToLocalDate(DateOnly source) + { + return LocalDate.FromDateOnly(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static DateOnly FromLocalDate(LocalDate source) => source.ToDateOnly(); + /// The to convert. + /// The equivalent . + public static DateOnly FromLocalDate(LocalDate source) + { + return source.ToDateOnly(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static LocalTime ToLocalTime(TimeOnly source) => LocalTime.FromTimeOnly(source); + /// The to convert. + /// The equivalent . + public static LocalTime ToLocalTime(TimeOnly source) + { + return LocalTime.FromTimeOnly(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static TimeOnly FromLocalTime(LocalTime source) => source.ToTimeOnly(); + /// The to convert. + /// The equivalent . + public static TimeOnly FromLocalTime(LocalTime source) + { + return source.ToTimeOnly(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static Offset ToOffset(TimeSpan source) => Offset.FromTicks(source.Ticks); + /// The to convert. + /// The equivalent . + public static Offset ToOffset(TimeSpan source) + { + return Offset.FromTicks(source.Ticks); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static TimeSpan FromOffset(Offset source) => source.ToTimeSpan(); + /// The to convert. + /// The equivalent . + public static TimeSpan FromOffset(Offset source) + { + return source.ToTimeSpan(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static OffsetDateTime ToOffsetDateTime(DateTimeOffset source) => OffsetDateTime.FromDateTimeOffset(source); + /// The to convert. + /// The equivalent . + public static OffsetDateTime ToOffsetDateTime(DateTimeOffset source) + { + return OffsetDateTime.FromDateTimeOffset(source); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static DateTimeOffset FromOffsetDateTime(OffsetDateTime source) => source.ToDateTimeOffset(); + /// The to convert. + /// The equivalent . + public static DateTimeOffset FromOffsetDateTime(OffsetDateTime source) + { + return source.ToDateTimeOffset(); + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static Period ToPeriod(string source) => PeriodPattern.Roundtrip.Parse(source).Value; + /// The to convert. + /// The equivalent . + public static Period ToPeriod(string source) + { + return PeriodPattern.Roundtrip.Parse(source).Value; + } /// - /// Converts a to a . + /// Converts a to a . /// - /// The to convert. - /// The equivalent . - public static string FromPeriod(Period source) => source.ToString(); -} + /// The to convert. + /// The equivalent . + public static string FromPeriod(Period source) + { + return source.ToString(); + } +} \ No newline at end of file diff --git a/src/Mapping/SystemTextJsonMapper.cs b/src/Mapping/SystemTextJsonMapper.cs index da8a6256c..6c565da0e 100644 --- a/src/Mapping/SystemTextJsonMapper.cs +++ b/src/Mapping/SystemTextJsonMapper.cs @@ -5,107 +5,106 @@ namespace Rocket.Surgery.LaunchPad.Mapping; /// -/// Configures methods for well-known conversions with STJ +/// Configures methods for well-known conversions with STJ /// -/// The to use for serialization. -[Mapper, PublicAPI] +/// The to use for serialization. +[Mapper] +[PublicAPI] public partial class SystemTextJsonMapper(IOptionsMonitor options) { /// - /// Converts a to a byte array. + /// Converts a to a byte array. /// - /// The to convert. - /// A byte array representation of the , or null if the is undefined. + /// The to convert. + /// A byte array representation of the , or null if the is undefined. [UserMapping] - public byte[]? JsonElementToByteArray(JsonElement source) => - source is { ValueKind: not JsonValueKind.Undefined } + public byte[]? JsonElementToByteArray(JsonElement source) + { + return source is { ValueKind: not JsonValueKind.Undefined, } ? JsonSerializer.SerializeToUtf8Bytes(source, options.CurrentValue) : null; + } /// - /// Converts a nullable to a byte array. + /// Converts a nullable to a byte array. /// - /// The to convert. - /// A byte array representation of the , or null if the is undefined. + /// The to convert. + /// A byte array representation of the , or null if the is undefined. [UserMapping] - public byte[]? JsonElementToByteArray(JsonElement? source) => - source is { ValueKind: not JsonValueKind.Undefined } + public byte[]? JsonElementToByteArray(JsonElement? source) + { + return source is { ValueKind: not JsonValueKind.Undefined, } ? JsonSerializer.SerializeToUtf8Bytes(source, options.CurrentValue) : null; + } /// - /// Converts a to a string. + /// Converts a to a string. /// - /// The to convert. - /// A string representation of the , or null if the is undefined. + /// The to convert. + /// A string representation of the , or null if the is undefined. [UserMapping] - public string? JsonElementToString(JsonElement source) => - source is { ValueKind: not JsonValueKind.Undefined } + public string? JsonElementToString(JsonElement source) + { + return source is { ValueKind: not JsonValueKind.Undefined, } ? JsonSerializer.Serialize(source, options.CurrentValue) : null; + } /// - /// Converts a nullable to a string. + /// Converts a nullable to a string. /// - /// The to convert. - /// A string representation of the , or null if the is undefined. + /// The to convert. + /// A string representation of the , or null if the is undefined. [UserMapping] - public string? JsonElementToString(JsonElement? source) => - source is { ValueKind: not JsonValueKind.Undefined } + public string? JsonElementToString(JsonElement? source) + { + return source is { ValueKind: not JsonValueKind.Undefined, } ? JsonSerializer.Serialize(source.Value, options.CurrentValue) : null; + } /// - /// Converts a byte array to a . + /// Converts a byte array to a . /// /// The byte array to convert. - /// A representation of the byte array, or the default if the byte array is null or empty. + /// A representation of the byte array, or the default if the byte array is null or empty. [UserMapping] - public JsonElement ByteArrayToJsonElement(byte[]? source) => - source switch - { - null or { Length: 0 } => new(), - _ => JsonSerializer.Deserialize(source, options.CurrentValue) - }; + public JsonElement ByteArrayToJsonElement(byte[]? source) + { + return source switch { null or { Length: 0, } => new(), _ => JsonSerializer.Deserialize(source, options.CurrentValue), }; + } /// - /// Converts a byte array to a . + /// Converts a byte array to a . /// /// The byte array to convert. - /// A representation of the byte array, or the default if the byte array is null or empty. + /// A representation of the byte array, or the default if the byte array is null or empty. [UserMapping] - public JsonElement? ByteArrayToNullableJsonElement(byte[]? source) => - source switch - { - null => null, - { Length: 0 } => new(), - _ => JsonSerializer.Deserialize(source, options.CurrentValue) - }; + public JsonElement? ByteArrayToNullableJsonElement(byte[]? source) + { + return source switch { null => null, { Length: 0, } => new(), _ => JsonSerializer.Deserialize(source, options.CurrentValue), }; + } /// - /// Converts a string to a . + /// Converts a string to a . /// /// The string to convert. - /// A representation of the string, or the default if the string is null or empty. + /// A representation of the string, or the default if the string is null or empty. [UserMapping] - public JsonElement StringToJsonElement(string? source) => - source switch - { - null or { Length: 0 } => new(), - _ => JsonSerializer.Deserialize(source, options.CurrentValue) - }; + public JsonElement StringToJsonElement(string? source) + { + return source switch { null or { Length: 0, } => new(), _ => JsonSerializer.Deserialize(source, options.CurrentValue), }; + } /// - /// Converts a string to a . + /// Converts a string to a . /// /// The string to convert. - /// A representation of the string, or the default if the string is null or empty. + /// A representation of the string, or the default if the string is null or empty. [UserMapping] - public JsonElement? StringToNullableJsonElement(string? source) => - source switch - { - null => null, - { Length: 0 } => new(), - _ => JsonSerializer.Deserialize(source, options.CurrentValue) - }; -} + public JsonElement? StringToNullableJsonElement(string? source) + { + return source switch { null => null, { Length: 0, } => new(), _ => JsonSerializer.Deserialize(source, options.CurrentValue), }; + } +} \ No newline at end of file diff --git a/src/Mapping/build/Rocket.Surgery.LaunchPad.Mapping.targets b/src/Mapping/build/Rocket.Surgery.LaunchPad.Mapping.targets index 3e98108ac..67dd5156c 100644 --- a/src/Mapping/build/Rocket.Surgery.LaunchPad.Mapping.targets +++ b/src/Mapping/build/Rocket.Surgery.LaunchPad.Mapping.targets @@ -1,8 +1,8 @@  - - - - + + + + diff --git a/test/Directory.Build.targets b/test/Directory.Build.targets index 46232fca7..ca8ebe08d 100644 --- a/test/Directory.Build.targets +++ b/test/Directory.Build.targets @@ -1,31 +1,30 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + + - + diff --git a/test/Extensions.Tests/Mapping/DurationTests.cs b/test/Extensions.Tests/Mapping/DurationTests.cs index 1ffbcea12..ae53823e4 100644 --- a/test/Extensions.Tests/Mapping/DurationTests.cs +++ b/test/Extensions.Tests/Mapping/DurationTests.cs @@ -8,7 +8,16 @@ namespace Extensions.Tests.Mapping; public partial class DurationTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { - [Mapper, PublicAPI] + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod(result, new Mapper(), TimeSpan.FromHours(1), Duration.FromMinutes(44)) + .UseHashedParameters(result.ToString()); + } + + [Mapper] + [PublicAPI] [UseStaticMapper(typeof(NodaTimeMapper))] private partial class Mapper { @@ -48,11 +57,4 @@ private class Foo4 { public TimeSpan? Bar { get; set; } } - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod(result, new Mapper(), TimeSpan.FromHours(1), Duration.FromMinutes(44)) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/Helpers/MapperDataAttribute.cs b/test/Extensions.Tests/Mapping/Helpers/MapperDataAttribute.cs index 5d49be27c..26f695c4e 100644 --- a/test/Extensions.Tests/Mapping/Helpers/MapperDataAttribute.cs +++ b/test/Extensions.Tests/Mapping/Helpers/MapperDataAttribute.cs @@ -13,8 +13,8 @@ public override IEnumerable GetData(MethodInfo testMethod) { if (method.IsGenericMethodDefinition) continue; var parameters = method.GetParameters(); - if (parameters is not [{ ParameterType.IsClass: true }]) continue; - yield return [new MethodResult(method)]; + if (parameters is not [{ ParameterType.IsClass: true, },]) continue; + yield return [new MethodResult(method),]; } } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/Helpers/MapperTestBase.cs b/test/Extensions.Tests/Mapping/Helpers/MapperTestBase.cs index 891d7e5d2..0795b6cef 100644 --- a/test/Extensions.Tests/Mapping/Helpers/MapperTestBase.cs +++ b/test/Extensions.Tests/Mapping/Helpers/MapperTestBase.cs @@ -4,8 +4,13 @@ namespace Extensions.Tests.Mapping.Helpers; public abstract class MapperTestBase(ITestOutputHelper testOutputHelper) : AutoFakeTest(testOutputHelper) { - protected SettingsTask VerifyMethod(MethodResult result, object mapper, params object[] instances) => - Verify(result.Map(mapper, instances)).UseHashedParameters(result.ToString()); - protected SettingsTask VerifyEachMethod(MethodResult result, object mapper, params object[] instances) => - Verify(result.MapEach(mapper, instances)).UseHashedParameters(result.ToString()); -} + protected SettingsTask VerifyMethod(MethodResult result, object mapper, params object[] instances) + { + return Verify(result.Map(mapper, instances)).UseHashedParameters(result.ToString()); + } + + protected SettingsTask VerifyEachMethod(MethodResult result, object mapper, params object[] instances) + { + return Verify(result.MapEach(mapper, instances)).UseHashedParameters(result.ToString()); + } +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/Helpers/MethodResult.cs b/test/Extensions.Tests/Mapping/Helpers/MethodResult.cs index 7f102317f..5c61a438c 100644 --- a/test/Extensions.Tests/Mapping/Helpers/MethodResult.cs +++ b/test/Extensions.Tests/Mapping/Helpers/MethodResult.cs @@ -16,41 +16,44 @@ public MapResult Map(object mapper, params object[] instances) { continue; } + property.SetValue(source, value); } - return new(source, methodInfo.Invoke(mapper, [source])); + return new(source, methodInfo.Invoke(mapper, [source,])); } public IEnumerable MapEach(object mapper, params object[] instances) { var parameterType = methodInfo.GetParameters()[0].ParameterType; var instanceLookup = instances.ToLookup(x => Nullable.GetUnderlyingType(x.GetType()) ?? x.GetType()); - var propertyLookup = parameterType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) - .ToDictionary(z => Nullable.GetUnderlyingType(z.PropertyType) ?? z.PropertyType); + var propertyLookup = parameterType + .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) + .ToDictionary(z => Nullable.GetUnderlyingType(z.PropertyType) ?? z.PropertyType); - return instanceLookup.Join( - propertyLookup, - z => z.Key, - z => z.Key, - (instances, properties) => - { - var propertyInfo = properties.Value; - return instances.Select( - instance => - { - var source = Activator.CreateInstance(parameterType); - propertyInfo.SetValue(source, instance); - return source; - } - ); - } - ) - .SelectMany(sources => sources, (_, source) => new MapResult(source, methodInfo.Invoke(mapper, [source]))); + return instanceLookup + .Join( + propertyLookup, + z => z.Key, + z => z.Key, + (instances, properties) => + { + var propertyInfo = properties.Value; + return instances.Select( + instance => + { + var source = Activator.CreateInstance(parameterType); + propertyInfo.SetValue(source, instance); + return source; + } + ); + } + ) + .SelectMany(sources => sources, (_, source) => new MapResult(source, methodInfo.Invoke(mapper, [source,]))); } public override string ToString() { return $"{methodInfo.Name}({methodInfo.GetParameters()[0].ParameterType.Name} -> {methodInfo.ReturnType.Name})"; } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/InstantTests.cs b/test/Extensions.Tests/Mapping/InstantTests.cs index 114095663..fc110e9c0 100644 --- a/test/Extensions.Tests/Mapping/InstantTests.cs +++ b/test/Extensions.Tests/Mapping/InstantTests.cs @@ -8,7 +8,24 @@ namespace Extensions.Tests.Mapping; public partial class InstantTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { - [Mapper, PublicAPI] + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + _fakeTimeProvider.GetUtcNow(), + _fakeTimeProvider.GetUtcNow().UtcDateTime, + Instant.FromDateTimeOffset(_fakeTimeProvider.GetUtcNow()) + ) + .UseHashedParameters(result.ToString()); + } + + [Mapper] + [PublicAPI] [UseStaticMapper(typeof(DateTimeMapper))] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(NodaTimeDateTimeMapper))] @@ -80,19 +97,4 @@ private class Foo6 { public DateTimeOffset? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - _fakeTimeProvider.GetUtcNow(), - _fakeTimeProvider.GetUtcNow().UtcDateTime, - Instant.FromDateTimeOffset(_fakeTimeProvider.GetUtcNow()) - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/JsonElementConverterTests.cs b/test/Extensions.Tests/Mapping/JsonElementConverterTests.cs index 4fa0b2b7d..9aa3909cf 100644 --- a/test/Extensions.Tests/Mapping/JsonElementConverterTests.cs +++ b/test/Extensions.Tests/Mapping/JsonElementConverterTests.cs @@ -8,45 +8,13 @@ namespace Extensions.Tests.Mapping; public partial class JsonElementConverterTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { - [Mapper, PublicAPI] - private partial class Mapper(IOptionsMonitor options) - { - [UseMapper] - private readonly SystemTextJsonMapper _systemTextJsonMapper = new(options); - - public partial JsonElementA MapToJsonElementA(StringValue source); - public partial StringValue MapToStringValue(JsonElementA source); - public partial JsonElementA MapToJsonElementA(ByteArray source); - public partial ByteArray MapToByteArray(JsonElementA source); -// public partial JsonElementB MapToJsonElementB(StringValue source); -// public partial StringValue MapToStringValue(JsonElementB source); -// public partial JsonElementB MapToJsonElementB(ByteArray source); -// public partial ByteArray MapToByteArray(JsonElementB source); -// public partial JsonElementB MapToJsonElementB(JsonElementA source); -// public partial JsonElementA MapToJsonElementA(JsonElementB source); - } - - private class ByteArray - { - public byte[]? Bar { get; set; } - } - - private class StringValue - { - public string? Bar { get; set; } - } - - private class JsonElementA - { - public JsonElement Bar { get; set; } - } - // private class JsonElementB // { // public JsonElement? Bar { get; set; } // } - [Theory, MapperData] + [Theory] + [MapperData] public Task Maps_All_Methods(MethodResult result) { var stub = A.Fake>(); @@ -62,7 +30,6 @@ public Task Maps_All_Methods(MethodResult result) "1234", "[1234,5678]", "{\"a\":1234}", - ""u8.ToArray(), "null"u8.ToArray(), "[]"u8.ToArray(), @@ -71,7 +38,6 @@ public Task Maps_All_Methods(MethodResult result) "1234"u8.ToArray(), "[1234,5678]"u8.ToArray(), "{\"a\":1234}"u8.ToArray(), - JsonDocument.Parse("null").RootElement, JsonDocument.Parse("[]").RootElement, JsonDocument.Parse("{}").RootElement, @@ -82,4 +48,39 @@ public Task Maps_All_Methods(MethodResult result) ) .UseHashedParameters(result.ToString()); } -} + + [Mapper] + [PublicAPI] + private partial class Mapper(IOptionsMonitor options) + { + [UseMapper] + private readonly SystemTextJsonMapper _systemTextJsonMapper = new(options); + + public partial JsonElementA MapToJsonElementA(StringValue source); + public partial StringValue MapToStringValue(JsonElementA source); + public partial JsonElementA MapToJsonElementA(ByteArray source); + + public partial ByteArray MapToByteArray(JsonElementA source); +// public partial JsonElementB MapToJsonElementB(StringValue source); +// public partial StringValue MapToStringValue(JsonElementB source); +// public partial JsonElementB MapToJsonElementB(ByteArray source); +// public partial ByteArray MapToByteArray(JsonElementB source); +// public partial JsonElementB MapToJsonElementB(JsonElementA source); +// public partial JsonElementA MapToJsonElementA(JsonElementB source); + } + + private class ByteArray + { + public byte[]? Bar { get; set; } + } + + private class StringValue + { + public string? Bar { get; set; } + } + + private class JsonElementA + { + public JsonElement Bar { get; set; } + } +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/LocalDateTests.cs b/test/Extensions.Tests/Mapping/LocalDateTests.cs index 5de8151da..21cdc853e 100644 --- a/test/Extensions.Tests/Mapping/LocalDateTests.cs +++ b/test/Extensions.Tests/Mapping/LocalDateTests.cs @@ -1,18 +1,32 @@ using Microsoft.Extensions.Time.Testing; using NodaTime; using Riok.Mapperly.Abstractions; -using Rocket.Surgery.LaunchPad.Mapping; using Rocket.Surgery.LaunchPad.Mapping.Profiles; namespace Extensions.Tests.Mapping; public partial class LocalDateTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + _fakeTimeProvider.GetLocalNow().DateTime, + DateOnly.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime), + LocalDate.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime) + ) + .UseHashedParameters(result.ToString()); + } + [Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] private partial class Mapper { - public partial Foo1 MapFoo1(Foo2 foo); public partial Foo1 MapFoo1(Foo5 foo); public partial Foo1 MapFoo1(Foo6 foo); @@ -34,6 +48,7 @@ private class Foo1 { public LocalDate Bar { get; set; } } + private class Foo2 { public LocalDate? Bar { get; set; } @@ -43,23 +58,9 @@ private class Foo5 { public DateOnly Bar { get; set; } } + private class Foo6 { public DateOnly? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - _fakeTimeProvider.GetLocalNow().DateTime, - DateOnly.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime), - LocalDate.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime) - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/LocalDateTimeTests.cs b/test/Extensions.Tests/Mapping/LocalDateTimeTests.cs index f5c07134f..f1c350229 100644 --- a/test/Extensions.Tests/Mapping/LocalDateTimeTests.cs +++ b/test/Extensions.Tests/Mapping/LocalDateTimeTests.cs @@ -1,4 +1,3 @@ -using System.Reflection; using Microsoft.Extensions.Time.Testing; using NodaTime; using Riok.Mapperly.Abstractions; @@ -11,6 +10,21 @@ namespace Extensions.Tests.Mapping; public partial class LocalDateTimeTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + _fakeTimeProvider.GetLocalNow().DateTime, + LocalDateTime.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime) + ) + .UseHashedParameters(result.ToString()); + } + [Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(NodaTimeDateTimeMapper))] @@ -52,18 +66,4 @@ private class Foo4 { public DateTime? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - _fakeTimeProvider.GetLocalNow().DateTime, - LocalDateTime.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime) - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/LocalTimeTests.cs b/test/Extensions.Tests/Mapping/LocalTimeTests.cs index 73635043c..91ed0e984 100644 --- a/test/Extensions.Tests/Mapping/LocalTimeTests.cs +++ b/test/Extensions.Tests/Mapping/LocalTimeTests.cs @@ -1,15 +1,28 @@ -using System.Reflection; using Microsoft.Extensions.Time.Testing; using NodaTime; -using NodaTime.Extensions; using Riok.Mapperly.Abstractions; -using Rocket.Surgery.LaunchPad.Mapping; using Rocket.Surgery.LaunchPad.Mapping.Profiles; namespace Extensions.Tests.Mapping; public partial class LocalTimeTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + _fakeTimeProvider.GetLocalNow().DateTime, + TimeOnly.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime), + LocalTime.FromTimeOnly(TimeOnly.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime)) + ) + .UseHashedParameters(result.ToString()); + } + [Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] private partial class Mapper @@ -50,19 +63,4 @@ private class Foo6 { public TimeOnly? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - _fakeTimeProvider.GetLocalNow().DateTime, - TimeOnly.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime), - LocalTime.FromTimeOnly(TimeOnly.FromDateTime(_fakeTimeProvider.GetLocalNow().DateTime)) - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/OffsetDateTimeTests.cs b/test/Extensions.Tests/Mapping/OffsetDateTimeTests.cs index f43764d9b..d8db5dd22 100644 --- a/test/Extensions.Tests/Mapping/OffsetDateTimeTests.cs +++ b/test/Extensions.Tests/Mapping/OffsetDateTimeTests.cs @@ -1,4 +1,3 @@ -using System.Reflection; using Microsoft.Extensions.Time.Testing; using NodaTime; using Riok.Mapperly.Abstractions; @@ -9,12 +8,26 @@ namespace Extensions.Tests.Mapping; public partial class OffsetDateTimeTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + _fakeTimeProvider.GetLocalNow(), + OffsetDateTime.FromDateTimeOffset(_fakeTimeProvider.GetLocalNow()) + ) + .UseHashedParameters(result.ToString()); + } + [Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(NodaTimeDateTimeMapper))] private partial class Mapper { - public partial Foo1 MapFoo1(Foo2 foo); public partial Foo1 MapFoo1(Foo3 foo); public partial Foo1 MapFoo1(Foo4 foo); @@ -36,6 +49,7 @@ private class Foo1 { public OffsetDateTime Bar { get; set; } } + private class Foo2 { public OffsetDateTime? Bar { get; set; } @@ -45,22 +59,9 @@ private class Foo3 { public DateTimeOffset Bar { get; set; } } + private class Foo4 { public DateTimeOffset? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - _fakeTimeProvider.GetLocalNow(), - OffsetDateTime.FromDateTimeOffset(_fakeTimeProvider.GetLocalNow()) - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/OffsetTests.cs b/test/Extensions.Tests/Mapping/OffsetTests.cs index e8f4d87db..41da220d4 100644 --- a/test/Extensions.Tests/Mapping/OffsetTests.cs +++ b/test/Extensions.Tests/Mapping/OffsetTests.cs @@ -8,6 +8,21 @@ namespace Extensions.Tests.Mapping; public partial class OffsetTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + Offset.FromHours(11), + TimeSpan.FromHours(10) + ) + .UseHashedParameters(result.ToString()); + } + [Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(NodaTimeDateTimeMapper))] @@ -49,18 +64,4 @@ private class Foo4 { public TimeSpan? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - Offset.FromHours(11), - TimeSpan.FromHours(10) - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/Mapping/PeriodTests.cs b/test/Extensions.Tests/Mapping/PeriodTests.cs index 2caacb1bc..f0cb16e3f 100644 --- a/test/Extensions.Tests/Mapping/PeriodTests.cs +++ b/test/Extensions.Tests/Mapping/PeriodTests.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.Time.Testing; using NodaTime; -using NodaTime.Text; using Riok.Mapperly.Abstractions; using Rocket.Surgery.LaunchPad.Mapping; using Rocket.Surgery.LaunchPad.Mapping.Profiles; @@ -9,6 +8,21 @@ namespace Extensions.Tests.Mapping; public partial class PeriodTests(ITestOutputHelper testOutputHelper) : MapperTestBase(testOutputHelper) { + private FakeTimeProvider _fakeTimeProvider = new(); + + [Theory] + [MapperData] + public Task Maps_All_Methods(MethodResult result) + { + return VerifyMethod( + result, + new Mapper(), + Period.FromMonths(10), + "P5M" + ) + .UseHashedParameters(result.ToString()); + } + [Mapper] [UseStaticMapper(typeof(NodaTimeMapper))] [UseStaticMapper(typeof(NodaTimeDateTimeMapper))] @@ -27,18 +41,4 @@ private class Foo3 { public string? Bar { get; set; } } - - FakeTimeProvider _fakeTimeProvider = new(); - - [Theory, MapperData] - public Task Maps_All_Methods(MethodResult result) - { - return VerifyMethod( - result, - new Mapper(), - Period.FromMonths(10), - "P5M" - ) - .UseHashedParameters(result.ToString()); - } -} +} \ No newline at end of file diff --git a/test/Extensions.Tests/ModuleInitializer.cs b/test/Extensions.Tests/ModuleInitializer.cs index 102d13bf0..36a7a529a 100644 --- a/test/Extensions.Tests/ModuleInitializer.cs +++ b/test/Extensions.Tests/ModuleInitializer.cs @@ -28,4 +28,4 @@ static string GetTypeName(Type type) } ); } -} +} \ No newline at end of file diff --git a/test/Sample.BlazorServer.Tests/FoundationTests.cs b/test/Sample.BlazorServer.Tests/FoundationTests.cs index 0b5e84990..8e58e3d18 100644 --- a/test/Sample.BlazorServer.Tests/FoundationTests.cs +++ b/test/Sample.BlazorServer.Tests/FoundationTests.cs @@ -11,4 +11,4 @@ public async Task Starts() var response = await AlbaHost.Server.CreateClient().GetAsync("/"); response.StatusCode.Should().Be(HttpStatusCode.OK); } -} +} \ No newline at end of file diff --git a/test/Sample.BlazorWasm.Tests/FoundationTests.cs b/test/Sample.BlazorWasm.Tests/FoundationTests.cs index 4384618a6..f5a8eb276 100644 --- a/test/Sample.BlazorWasm.Tests/FoundationTests.cs +++ b/test/Sample.BlazorWasm.Tests/FoundationTests.cs @@ -1,7 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; +namespace Sample.BlazorWasm.Tests; -namespace Sample.BlazorWasm.Tests; - -public class FoundationTests(ITestOutputHelper outputHelper) : HandleTestHostBase(outputHelper) -{ -} +public class FoundationTests(ITestOutputHelper outputHelper) : HandleTestHostBase(outputHelper) { } \ No newline at end of file diff --git a/test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs b/test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs index e060baca0..7abeb4443 100644 --- a/test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs +++ b/test/Sample.Classic.Restful.Tests/ClassicFoundationTests.cs @@ -21,11 +21,15 @@ public async Task Starts() public void OpenApiDocument() { var docs = ServiceProvider - .GetRequiredService>().Value.SwaggerDocs.Keys; + .GetRequiredService>() + .Value.SwaggerDocs.Keys; foreach (var document in docs) { - ServiceProvider.GetRequiredService() - .GetSwagger(document).Should().NotBeNull(); + ServiceProvider + .GetRequiredService() + .GetSwagger(document) + .Should() + .NotBeNull(); } } -} +} \ No newline at end of file diff --git a/test/Sample.Core.Tests/FoundationTests.cs b/test/Sample.Core.Tests/FoundationTests.cs index a42926443..5f1262a5c 100644 --- a/test/Sample.Core.Tests/FoundationTests.cs +++ b/test/Sample.Core.Tests/FoundationTests.cs @@ -1,7 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; +namespace Sample.Core.Tests; -namespace Sample.Core.Tests; - -public class FoundationTests(ITestOutputHelper outputHelper) : HandleTestHostBase(outputHelper) -{ -} +public class FoundationTests(ITestOutputHelper outputHelper) : HandleTestHostBase(outputHelper) { } \ No newline at end of file diff --git a/test/Sample.Graphql.Tests/FoundationTests.cs b/test/Sample.Graphql.Tests/FoundationTests.cs index abec8727e..c6050bc40 100644 --- a/test/Sample.Graphql.Tests/FoundationTests.cs +++ b/test/Sample.Graphql.Tests/FoundationTests.cs @@ -1,7 +1,6 @@ using System.Net; using Alba; using HotChocolate.Execution; -using Microsoft.Extensions.DependencyInjection; using Rocket.Surgery.Extensions.Testing; using Rocket.Surgery.LaunchPad.AspNetCore.Testing; using Sample.Core.Domain; @@ -34,4 +33,4 @@ public async Task GraphqlSchema() var exeuctor = await host.Services.GetRequestExecutorAsync(); await Verify(exeuctor.Schema.Print(), "graphql"); } -} +} \ No newline at end of file diff --git a/test/Sample.Grpc.Tests/FoundationTests.cs b/test/Sample.Grpc.Tests/FoundationTests.cs index 7dfbbcffa..cb4ade760 100644 --- a/test/Sample.Grpc.Tests/FoundationTests.cs +++ b/test/Sample.Grpc.Tests/FoundationTests.cs @@ -1,5 +1,4 @@ using System.Net; -using Microsoft.Extensions.DependencyInjection; using Sample.Grpc.Tests.Helpers; namespace Sample.Grpc.Tests; @@ -12,4 +11,4 @@ public async Task Starts() var response = await AlbaHost.Server.CreateClient().GetAsync("/"); response.StatusCode.Should().Be(HttpStatusCode.OK); } -} +} \ No newline at end of file diff --git a/test/Sample.Pages.Tests/FoundationTests.cs b/test/Sample.Pages.Tests/FoundationTests.cs index a54de772e..24b5b4d49 100644 --- a/test/Sample.Pages.Tests/FoundationTests.cs +++ b/test/Sample.Pages.Tests/FoundationTests.cs @@ -39,4 +39,4 @@ public async Task StartingEvents() A.CallTo(onStopped).MustHaveHappenedOnceExactly(); A.CallTo(onStopping).MustHaveHappenedOnceExactly(); } -} +} \ No newline at end of file diff --git a/test/Sample.Restful.Tests/FoundationTests.cs b/test/Sample.Restful.Tests/FoundationTests.cs index 94ab95aa8..a5fc8e6c6 100644 --- a/test/Sample.Restful.Tests/FoundationTests.cs +++ b/test/Sample.Restful.Tests/FoundationTests.cs @@ -20,8 +20,11 @@ public async Task Starts() [ClassData(typeof(OpenApiDocuments))] public void OpenApiDocument(string document) { - AlbaHost.Services.GetRequiredService() - .GetSwagger(document).Should().NotBeNull(); + AlbaHost + .Services.GetRequiredService() + .GetSwagger(document) + .Should() + .NotBeNull(); } private sealed class OpenApiDocuments : TheoryData @@ -36,4 +39,4 @@ public OpenApiDocuments() } } } -} +} \ No newline at end of file