Skip to content

Commit

Permalink
Fix/warnings (#1642)
Browse files Browse the repository at this point in the history
* First wave of warning fixes

* Warnings phase2
  • Loading branch information
david-driscoll authored Nov 11, 2023
1 parent 8b886ff commit fd78f47
Show file tree
Hide file tree
Showing 255 changed files with 921 additions and 1,584 deletions.
5 changes: 0 additions & 5 deletions .build/Build.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using System.Diagnostics;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.MSBuild;
using Polly;
using Rocket.Surgery.Nuke.DotNetCore;
using Serilog;

[PublicAPI]
[UnsetVisualStudioEnvironmentVariables]
Expand Down
1 change: 1 addition & 0 deletions LaunchPad.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{DF33E0FB-9
ProjectSection(SolutionItems) = preProject
test\Directory.Build.props = test\Directory.Build.props
test\Directory.Build.targets = test\Directory.Build.targets
test\.editorconfig = test\.editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = ".build", ".build\.build.csproj", "{166F1873-4CAE-4F54-88B6-5FE79678846B}"
Expand Down
1 change: 1 addition & 0 deletions sample/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dotnet_diagnostic.CA1822.severity = none
dotnet_diagnostic.CA5394.severity = none
dotnet_diagnostic.CA1707.severity = none
resharper_virtual_member_call_in_constructor_highlighting = none
resharper_nullable_warning_suppression_is_used_highlighting = none
1 change: 1 addition & 0 deletions sample/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);1591</NoWarn>
<IsTrimmable>false</IsTrimmable>
</PropertyGroup>
<ItemGroup>
<InternalsVisibleTo Include="Sample.Graphql.Tests" />
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.BlazorServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Main(string[] args)
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.LaunchWith(RocketBooster.ForDependencyContext(DependencyContext.Default), z => z.WithConventionsFrom(GetConventions))
.LaunchWith(RocketBooster.ForDependencyContext(DependencyContext.Default!), z => z.WithConventionsFrom(GetConventions))
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
}
}
9 changes: 2 additions & 7 deletions sample/Sample.BlazorServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

namespace Sample.BlazorServer;

public class Startup
public class Startup(IConfiguration configuration)
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }
public IConfiguration Configuration { get; } = configuration;

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public partial class LaunchRecordController : RestfulApiController
/// <summary>
/// Remove a launch record
/// </summary>
/// <param name="id"></param>
/// <param name="request"></param>
/// <returns></returns>
[HttpDelete("{id:guid}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@
namespace Sample.Classic.Restful.Controllers;

[Route("[controller]")]
public class WeatherForecastController : RestfulApiController
public class WeatherForecastController(ILogger<WeatherForecastController> logger) : RestfulApiController
{
private static readonly string[] Summaries =
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.Classic.Restful/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.LaunchWith(RocketBooster.ForDependencyContext(DependencyContext.Default), z => z.WithConventionsFrom(Imports.GetConventions));
.LaunchWith(RocketBooster.ForDependencyContext(DependencyContext.Default!), z => z.WithConventionsFrom(Imports.GetConventions));
}
}
9 changes: 2 additions & 7 deletions sample/Sample.Classic.Restful/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ namespace Sample.Classic.Restful;
/// <summary>
/// Startup interop (here for testing only or for 3.1 support)
/// </summary>
public class Startup
public class Startup(IConfiguration configuration)
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }
public IConfiguration Configuration { get; } = configuration;

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
Expand Down
31 changes: 7 additions & 24 deletions sample/Sample.Command/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,28 @@ public class InstanceThing
}


public class Dump : Command<AppSettings>
public class Dump(IConfiguration configuration, ILogger<Dump> logger, InstanceThing instanceThing)
: Command<AppSettings>
{
private readonly IConfiguration _configuration;
private readonly ILogger<Dump> _logger;
private readonly InstanceThing _instanceThing;

public Dump(IConfiguration configuration, ILogger<Dump> logger, InstanceThing instanceThing)
{
_configuration = configuration;
_logger = logger;
_instanceThing = instanceThing;
}

public override int Execute([NotNull] CommandContext context, [NotNull] AppSettings settings)
{
// ReSharper disable once TemplateIsNotCompileTimeConstantProblem
_logger.LogInformation(_instanceThing.From);
foreach (var item in _configuration.AsEnumerable().Reverse())
logger.LogInformation(instanceThing.From);
foreach (var item in configuration.AsEnumerable().Reverse())
{
_logger.LogInformation("{Key}: {Value}", item.Key, item.Value ?? string.Empty);
logger.LogInformation("{Key}: {Value}", item.Key, item.Value ?? string.Empty);
}

return 1;
}
}

public class DefaultCommand : Command<AppSettings>
public class DefaultCommand(ILogger<DefaultCommand> logger) : Command<AppSettings>
{
private readonly ILogger<DefaultCommand> _logger;

public DefaultCommand(ILogger<DefaultCommand> logger)
{
_logger = logger;
}

public override int Execute([NotNull] CommandContext context, [NotNull] AppSettings settings)
{
Console.WriteLine("Hello World!");
_logger.LogInformation("Test");
logger.LogInformation("Test");
return 1;
}
}
2 changes: 1 addition & 1 deletion sample/Sample.Core/DataConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Register(IConventionContext context, IConfiguration configuration, I
);
#if NET
// temp?
services.TryAddScoped(_ => _.GetRequiredService<IDbContextFactory<RocketDbContext>>().CreateDbContext());
services.TryAddScoped(provider => provider.GetRequiredService<IDbContextFactory<RocketDbContext>>().CreateDbContext());
#endif
}
}
11 changes: 2 additions & 9 deletions sample/Sample.Core/DataGenerationConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@ public void Register(IConventionContext context, IConfiguration configuration, I
services.Insert(0, ServiceDescriptor.Singleton<IHostedService, HostedService>());
}

private class HostedService : IHostedService
private class HostedService(IServiceProvider serviceProvider) : IHostedService
{
private readonly IServiceProvider _serviceProvider;

public HostedService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await _serviceProvider.WithScoped<RocketDbContext>().Invoke(
await serviceProvider.WithScoped<RocketDbContext>().Invoke(
async dbContext =>
{
await dbContext.Database.EnsureCreatedAsync(cancellationToken).ConfigureAwait(false);
Expand Down
9 changes: 6 additions & 3 deletions sample/Sample.Core/Domain/LaunchRecord.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rocket.Surgery.LaunchPad.EntityFramework;
using Sample.Core.Models;
Expand All @@ -8,8 +9,10 @@ namespace Sample.Core.Domain;
public class LaunchRecord // : ILaunchRecord
{
public LaunchRecordId Id { get; set; }
public string? Partner { get; set; } = null!;
public string? Payload { get; set; } = null!;
[StringLength(1000)]
public string? Partner { get; set; }
[StringLength(1000)]
public string? Payload { get; set; }
public long PayloadWeightKg { get; set; }
public DateTimeOffset? ActualLaunchDate { get; set; }
public DateTimeOffset ScheduledLaunchDate { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion sample/Sample.Core/Domain/ReadyRocket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Rocket.Surgery.LaunchPad.EntityFramework;
using Sample.Core.Models;
Expand All @@ -11,6 +12,7 @@ namespace Sample.Core.Domain;
public class ReadyRocket // : IReadyRocket
{
public RocketId Id { get; set; }
[StringLength(30)]
public string SerialNumber { get; set; } = null!;
public RocketType Type { get; set; }

Expand Down
12 changes: 2 additions & 10 deletions sample/Sample.Core/Domain/RocketDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

namespace Sample.Core.Domain;

public class RocketDbContext : LpContext<RocketDbContext>
public class RocketDbContext(DbContextOptions<RocketDbContext>? options = null) : LpContext<RocketDbContext>(options ?? new DbContextOptions<RocketDbContext>())
{
public RocketDbContext(DbContextOptions<RocketDbContext>? options = null) : base(options ?? new DbContextOptions<RocketDbContext>())
{
}

public DbSet<ReadyRocket> Rockets { get; set; } = null!;
public DbSet<LaunchRecord> LaunchRecords { get; set; } = null!;

Expand All @@ -28,7 +24,7 @@ protected override void ConfigureConventions(ModelConfigurationBuilder configura
#endif
}

public class StronglyTypedIdValueConverterSelector : ValueConverterSelector
public class StronglyTypedIdValueConverterSelector(ValueConverterSelectorDependencies dependencies) : ValueConverterSelector(dependencies)
{
[return: NotNullIfNotNull("type")]
private static Type? UnwrapNullableType(Type? type)
Expand All @@ -45,10 +41,6 @@ public class StronglyTypedIdValueConverterSelector : ValueConverterSelector
private readonly ConcurrentDictionary<(Type ModelClrType, Type ProviderClrType), ValueConverterInfo> _converters
= new ConcurrentDictionary<(Type ModelClrType, Type ProviderClrType), ValueConverterInfo>();

public StronglyTypedIdValueConverterSelector(ValueConverterSelectorDependencies dependencies) : base(dependencies)
{
}

public override IEnumerable<ValueConverterInfo> Select(Type modelClrType, Type? providerClrType = null)
{
var baseConverters = base.Select(modelClrType, providerClrType);
Expand Down
19 changes: 5 additions & 14 deletions sample/Sample.Core/Operations/LaunchRecords/CreateLaunchRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,22 @@ public Validator()
}
}

private class Handler : IRequestHandler<Request, Response>
private class Handler(RocketDbContext dbContext, IMapper mapper) : IRequestHandler<Request, Response>
{
private readonly RocketDbContext _dbContext;
private readonly IMapper _mapper;

public Handler(RocketDbContext dbContext, IMapper mapper)
{
_dbContext = dbContext;
_mapper = mapper;
}

public async Task<Response> Handle(Request request, CancellationToken cancellationToken)
{
var record = _mapper.Map<LaunchRecord>(request);
var record = mapper.Map<LaunchRecord>(request);

var rocket = await _dbContext.Rockets.FindAsync(new object[] { request.RocketId }, cancellationToken);
var rocket = await dbContext.Rockets.FindAsync(new object[] { request.RocketId }, cancellationToken);
if (rocket == null)
{
throw new RequestFailedException("Rocket not found!");
}

record.Rocket = rocket;

await _dbContext.AddAsync(record, cancellationToken).ConfigureAwait(false);
await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
await dbContext.AddAsync(record, cancellationToken).ConfigureAwait(false);
await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

return new Response
{
Expand Down
15 changes: 4 additions & 11 deletions sample/Sample.Core/Operations/LaunchRecords/DeleteLaunchRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,11 @@ public Validator()
}

[UsedImplicitly]
private class Handler : IRequestHandler<Request>
private class Handler(RocketDbContext dbContext) : IRequestHandler<Request>
{
private readonly RocketDbContext _dbContext;

public Handler(RocketDbContext dbContext)
{
_dbContext = dbContext;
}

public async Task Handle(Request request, CancellationToken cancellationToken)
{
var rocket = await _dbContext.LaunchRecords.FindAsync(new object[] { request.Id }, cancellationToken);
var rocket = await dbContext.LaunchRecords.FindAsync(new object[] { request.Id }, cancellationToken);
if (rocket == null)
{
throw new NotFoundException();
Expand All @@ -55,8 +48,8 @@ public async Task Handle(Request request, CancellationToken cancellationToken)
throw new NotAuthorizedException("Unable to operate on given record");
}

_dbContext.Remove(rocket);
await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
dbContext.Remove(rocket);
await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
}
}
}
24 changes: 8 additions & 16 deletions sample/Sample.Core/Operations/LaunchRecords/EditLaunchRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,12 @@ public Validator()
}
}

private class Handler : PatchRequestHandler<Request, PatchRequest, LaunchRecordModel>, IRequestHandler<Request, LaunchRecordModel>
private class Handler(RocketDbContext dbContext, IMapper mapper, IMediator mediator)
: PatchRequestHandler<Request, PatchRequest, LaunchRecordModel>(mediator), IRequestHandler<Request, LaunchRecordModel>
{
private readonly RocketDbContext _dbContext;
private readonly IMapper _mapper;

public Handler(RocketDbContext dbContext, IMapper mapper, IMediator mediator) : base(mediator)
{
_dbContext = dbContext;
_mapper = mapper;
}

private async Task<LaunchRecord> GetLaunchRecord(LaunchRecordId id, CancellationToken cancellationToken)
{
var rocket = await _dbContext.LaunchRecords
var rocket = await dbContext.LaunchRecords
.Include(z => z.Rocket)
.FirstOrDefaultAsync(z => z.Id == id, cancellationToken)
.ConfigureAwait(false);
Expand All @@ -130,18 +122,18 @@ private async Task<LaunchRecord> GetLaunchRecord(LaunchRecordId id, Cancellation
protected override async Task<Request> GetRequest(PatchRequest patchRequest, CancellationToken cancellationToken)
{
var rocket = await GetLaunchRecord(patchRequest.Id, cancellationToken);
return _mapper.Map<Request>(_mapper.Map<LaunchRecordModel>(rocket));
return mapper.Map<Request>(mapper.Map<LaunchRecordModel>(rocket));
}

public async Task<LaunchRecordModel> Handle(Request request, CancellationToken cancellationToken)
{
var rocket = await GetLaunchRecord(request.Id, cancellationToken);

_mapper.Map(request, rocket);
_dbContext.Update(rocket);
await _dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
mapper.Map(request, rocket);
dbContext.Update(rocket);
await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

return _mapper.Map<LaunchRecordModel>(rocket);
return mapper.Map<LaunchRecordModel>(rocket);
}
}
}
Loading

0 comments on commit fd78f47

Please sign in to comment.