diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eac2160..9be567f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v2 with: - dotnet-version: "6.0.x" + dotnet-version: "8.0.x" - name: Install dependencies run: dotnet restore src - name: Use GitVersion diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e6229f9..981501f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v2 with: - dotnet-version: "6.0.x" + dotnet-version: "8.0.x" - name: Install dependencies run: dotnet restore src - name: Use GitVersion diff --git a/GitVersion.yml b/GitVersion.yml index 5cb6811..1e8a51a 100644 --- a/GitVersion.yml +++ b/GitVersion.yml @@ -1,4 +1,4 @@ -next-version: 1.0.0 +next-version: 2.0.0 mode: Mainline major-version-bump-message: '\+semver:\s?(breaking|major)' minor-version-bump-message: '\+semver:\s?(feature|minor)' diff --git a/src/LittleBlocks.Exports.Agent.UnitTests/LittleBlocks.Exports.Agent.UnitTests.csproj b/src/LittleBlocks.Exports.Agent.UnitTests/LittleBlocks.Exports.Agent.UnitTests.csproj index da99c60..561921c 100644 --- a/src/LittleBlocks.Exports.Agent.UnitTests/LittleBlocks.Exports.Agent.UnitTests.csproj +++ b/src/LittleBlocks.Exports.Agent.UnitTests/LittleBlocks.Exports.Agent.UnitTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false @@ -9,18 +9,18 @@ - - - - - - - - + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/LittleBlocks.Exports.Agent/LittleBlocks.Exports.Agent.csproj b/src/LittleBlocks.Exports.Agent/LittleBlocks.Exports.Agent.csproj index 679bd82..43d781f 100644 --- a/src/LittleBlocks.Exports.Agent/LittleBlocks.Exports.Agent.csproj +++ b/src/LittleBlocks.Exports.Agent/LittleBlocks.Exports.Agent.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net8.0 LittleBlocks.Exports.Agent Mohammad Moattar, Lewis Percival true diff --git a/src/LittleBlocks.Exports.Autofac/ContainerBuilderExtensions.cs b/src/LittleBlocks.Exports.Autofac/ContainerBuilderExtensions.cs index abbd0fa..dee667c 100644 --- a/src/LittleBlocks.Exports.Autofac/ContainerBuilderExtensions.cs +++ b/src/LittleBlocks.Exports.Autofac/ContainerBuilderExtensions.cs @@ -52,7 +52,7 @@ public static ContainerBuilder RegisterCsv(this ContainerBuilder builder, public static ContainerBuilder RegisterS3BucketStorageWithSamlSupport(this ContainerBuilder builder, IConfiguration configuration, Action configure) { - if (builder == null) throw new ArgumentNullException(nameof(builder)); + ArgumentNullException.ThrowIfNull(builder); var options = new BucketOptions(); configuration.GetSection(nameof(BucketOptions)).Bind(options); @@ -74,7 +74,7 @@ public static ContainerBuilder RegisterS3BucketStorageWithSamlSupport(this Conta public static ContainerBuilder RegisterS3BucketStorage(this ContainerBuilder builder, IConfiguration configuration, Action configure) { - if (builder == null) throw new ArgumentNullException(nameof(builder)); + ArgumentNullException.ThrowIfNull(builder); var options = new BucketOptions(); configuration.GetSection(nameof(BucketOptions)).Bind(options); @@ -94,7 +94,7 @@ public static ContainerBuilder RegisterS3BucketStorage(this ContainerBuilder bui public static ContainerBuilder RegisterInMemoryStorage(this ContainerBuilder builder) { - if (builder == null) throw new ArgumentNullException(nameof(builder)); + ArgumentNullException.ThrowIfNull(builder); builder.RegisterType().IfNotRegistered(typeof(CsvStorageTargetResolver)) .AsImplementedInterfaces(); @@ -109,7 +109,7 @@ public static ContainerBuilder RegisterInMemoryStorage(this ContainerBuilder bui public static ContainerBuilder RegisterLocalDiskStorage(this ContainerBuilder builder) { - if (builder == null) throw new ArgumentNullException(nameof(builder)); + ArgumentNullException.ThrowIfNull(builder); builder.RegisterType().IfNotRegistered(typeof(CsvStorageTargetResolver)) .AsImplementedInterfaces(); diff --git a/src/LittleBlocks.Exports.Autofac/LittleBlocks.Exports.Autofac.csproj b/src/LittleBlocks.Exports.Autofac/LittleBlocks.Exports.Autofac.csproj index dbc4d20..844baae 100644 --- a/src/LittleBlocks.Exports.Autofac/LittleBlocks.Exports.Autofac.csproj +++ b/src/LittleBlocks.Exports.Autofac/LittleBlocks.Exports.Autofac.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net8.0 true LittleBlocks.Exports.Autofac Mohammad Moattar @@ -11,7 +11,7 @@ - + diff --git a/src/LittleBlocks.Exports.Client.UnitTests/LittleBlocks.Exports.Client.UnitTests.csproj b/src/LittleBlocks.Exports.Client.UnitTests/LittleBlocks.Exports.Client.UnitTests.csproj index 4c080db..52283dc 100644 --- a/src/LittleBlocks.Exports.Client.UnitTests/LittleBlocks.Exports.Client.UnitTests.csproj +++ b/src/LittleBlocks.Exports.Client.UnitTests/LittleBlocks.Exports.Client.UnitTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false @@ -9,17 +9,17 @@ - - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/LittleBlocks.Exports.Client/ExporterClientBuilder.cs b/src/LittleBlocks.Exports.Client/ExporterClientBuilder.cs index 2a78efb..b5a6b9e 100644 --- a/src/LittleBlocks.Exports.Client/ExporterClientBuilder.cs +++ b/src/LittleBlocks.Exports.Client/ExporterClientBuilder.cs @@ -40,8 +40,8 @@ public IExporterClient Build(string name) public IExporterClientRegistry AddClient(string name, string clientUrl) { - if (name == null) throw new ArgumentNullException(nameof(name)); - if (clientUrl == null) throw new ArgumentNullException(nameof(clientUrl)); + ArgumentNullException.ThrowIfNull(name); + ArgumentNullException.ThrowIfNull(clientUrl); if (_exporterCache.ContainsKey(name)) throw new DuplicateExporterException($"Duplicate exporter with name {name} exists in the cache"); diff --git a/src/LittleBlocks.Exports.Client/LittleBlocks.Exports.Client.csproj b/src/LittleBlocks.Exports.Client/LittleBlocks.Exports.Client.csproj index b45ea23..9564a9f 100644 --- a/src/LittleBlocks.Exports.Client/LittleBlocks.Exports.Client.csproj +++ b/src/LittleBlocks.Exports.Client/LittleBlocks.Exports.Client.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net8.0 true LittleBlocks.Exports.Client Mohammad Moattar, Lewis Percival @@ -11,8 +11,8 @@ - - + + diff --git a/src/LittleBlocks.Exports.Common/LittleBlocks.Exports.Common.csproj b/src/LittleBlocks.Exports.Common/LittleBlocks.Exports.Common.csproj index 1194ebc..cd3b9b6 100644 --- a/src/LittleBlocks.Exports.Common/LittleBlocks.Exports.Common.csproj +++ b/src/LittleBlocks.Exports.Common/LittleBlocks.Exports.Common.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net8.0 true LittleBlocks.Exports.Common Mohammad Moattar, Lewis Percival @@ -11,7 +11,7 @@ - + diff --git a/src/LittleBlocks.Exports.IntegrationTests/CsvFileGenerationWithServiceCollectionTests.cs b/src/LittleBlocks.Exports.IntegrationTests/CsvFileGenerationWithServiceCollectionTests.cs index 635dc4c..eee550a 100644 --- a/src/LittleBlocks.Exports.IntegrationTests/CsvFileGenerationWithServiceCollectionTests.cs +++ b/src/LittleBlocks.Exports.IntegrationTests/CsvFileGenerationWithServiceCollectionTests.cs @@ -129,35 +129,7 @@ public async Task Should_ThrowError_WhenTheConfigurationDoesntHaveMappingForTheT .Be( $"Error in creating export configuration '{typeof(SampleEntity2)}'. Make sure the ClassMap has been registered"); } - - // [Fact] - // TODO: Should be revised - public async Task Should_ExportAsync_UploadTheFileInAws() - { - var configPath = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location) ?? string.Empty, - "appsettings.json"); - var entities = _fixture.FakeEntityList(5); - var configuration = new ConfigurationBuilder().AddJsonFile(configPath, false).Build(); - var storageTargets = new[] - { - new StorageTarget - { - TargetLocation = "Mezz/Valuations/Automated/", StorageTargetType = StorageTargetType.S3Bucket - } - }; - var services = new ServiceCollection(); - services.AddLogging(); - services.AddS3BucketStorageWithSamlSupport(configuration); - services.AddCsv(c => { c.Register(); }); - - var serviceProvider = services.BuildServiceProvider(); - var sut = serviceProvider.GetRequiredService(); - - var actual = await sut.ExportAsync(entities, new ExporterOptions(DateTime.Today, storageTargets)); - - actual.Should().NotBe(null); - } - + [Fact] public async Task Should_ExportAsync_UploadTheFileInAzureBlobStorageWithSharedKey() { @@ -169,7 +141,7 @@ public async Task Should_ExportAsync_UploadTheFileInAzureBlobStorageWithSharedKe { new StorageTarget { - TargetLocation = "mezz/valuations/automated/", StorageTargetType = StorageTargetType.BlobStorage + TargetLocation = "test/targets/automated/", StorageTargetType = StorageTargetType.BlobStorage } }; var services = new ServiceCollection(); @@ -198,7 +170,7 @@ public async Task Should_ExportAsync_UploadTheFileInAzureBlobStorageWithAzureAd( { new StorageTarget { - TargetLocation = "mezz/valuations/manual/", StorageTargetType = StorageTargetType.BlobStorage + TargetLocation = "test/targets/manual/", StorageTargetType = StorageTargetType.BlobStorage } }; var services = new ServiceCollection(); @@ -215,30 +187,5 @@ public async Task Should_ExportAsync_UploadTheFileInAzureBlobStorageWithAzureAd( actual.Should().NotBe(null); actual.HasError.Should().BeFalse(); } - - //[Fact] - public async Task Should_ExportAsync_UploadTheFileInAzureBlobStorageWithEmulator() - { - var entities = _fixture.FakeEntityList(5); - var storageTargets = new[] - { - new StorageTarget - { - TargetLocation = "mezz/valuations/manual/", StorageTargetType = StorageTargetType.BlobStorage - } - }; - var services = new ServiceCollection(); - services.AddLogging(); - services.AddAccountWithEmulatorStorage(); - services.AddCsv(c => { c.Register(); }); - - var serviceProvider = services.BuildServiceProvider(); - var sut = serviceProvider.GetRequiredService(); - - var actual = await sut.ExportAsync(entities, new ExporterOptions(DateTime.Today, storageTargets)); - - actual.Should().NotBe(null); - actual.HasError.Should().BeFalse(); - } } } \ No newline at end of file diff --git a/src/LittleBlocks.Exports.IntegrationTests/LittleBlocks.Exports.IntegrationTests.csproj b/src/LittleBlocks.Exports.IntegrationTests/LittleBlocks.Exports.IntegrationTests.csproj index b88449f..64d68ff 100644 --- a/src/LittleBlocks.Exports.IntegrationTests/LittleBlocks.Exports.IntegrationTests.csproj +++ b/src/LittleBlocks.Exports.IntegrationTests/LittleBlocks.Exports.IntegrationTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false @@ -9,20 +9,20 @@ - - - - - - - - - - + + + + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/LittleBlocks.Exports.UnitTests/LittleBlocks.Exports.UnitTests.csproj b/src/LittleBlocks.Exports.UnitTests/LittleBlocks.Exports.UnitTests.csproj index dc931e8..e2c1b4c 100644 --- a/src/LittleBlocks.Exports.UnitTests/LittleBlocks.Exports.UnitTests.csproj +++ b/src/LittleBlocks.Exports.UnitTests/LittleBlocks.Exports.UnitTests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 false @@ -9,17 +9,17 @@ - - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/LittleBlocks.Exports.UnitTests/Storage/CsvStorageTargetTests.cs b/src/LittleBlocks.Exports.UnitTests/Storage/CsvStorageTargetTests.cs index 424a4d4..c0f85c4 100644 --- a/src/LittleBlocks.Exports.UnitTests/Storage/CsvStorageTargetTests.cs +++ b/src/LittleBlocks.Exports.UnitTests/Storage/CsvStorageTargetTests.cs @@ -34,10 +34,10 @@ public async Task Should_Resolve_ReturnCorrectStorageTarget_WhenItIsPresented(IB { // Arrange var sut = new GenericCsvStorageTarget(StorageTargetType.InMemory, blobStorage); - var expected = "Mezz/Valuation/File.csv"; + var expected = "Test/Storage/File.csv"; // Act - await sut.WriteAsync("Mezz/Valuation/", "File.csv", new byte[] {1, 12, 123}); + await sut.WriteAsync("Test/Storage/", "File.csv", new byte[] {1, 12, 123}); // Assert await blobStorage.Received(1) diff --git a/src/LittleBlocks.Exports/Csv/CsvContextMapRegistry.cs b/src/LittleBlocks.Exports/Csv/CsvContextMapRegistry.cs index 166ef34..1f50e3e 100644 --- a/src/LittleBlocks.Exports/Csv/CsvContextMapRegistry.cs +++ b/src/LittleBlocks.Exports/Csv/CsvContextMapRegistry.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using CsvHelper.Configuration; namespace LittleBlocks.Exports.Csv @@ -34,7 +35,7 @@ public void Register() public Type Resolve() { - return _registry.TryGetValue(typeof(T), out var map) ? map : null; + return _registry.GetValueOrDefault(typeof(T)); } } } \ No newline at end of file diff --git a/src/LittleBlocks.Exports/Csv/CsvExportConfigurationBuilder.cs b/src/LittleBlocks.Exports/Csv/CsvExportConfigurationBuilder.cs index ee121a6..5b715d9 100644 --- a/src/LittleBlocks.Exports/Csv/CsvExportConfigurationBuilder.cs +++ b/src/LittleBlocks.Exports/Csv/CsvExportConfigurationBuilder.cs @@ -40,7 +40,7 @@ public CsvExportConfigurationBuilder(ICsvContextMapResolver csvContextMapResolve public CsvExportConfiguration Build(ExporterOptions options) { - if (options == null) throw new ArgumentNullException(nameof(options)); + ArgumentNullException.ThrowIfNull(options); var classMap = _csvContextMapResolver.Resolve(); if (classMap == null) diff --git a/src/LittleBlocks.Exports/Csv/CsvFileExporter.cs b/src/LittleBlocks.Exports/Csv/CsvFileExporter.cs index fa50841..44a6326 100644 --- a/src/LittleBlocks.Exports/Csv/CsvFileExporter.cs +++ b/src/LittleBlocks.Exports/Csv/CsvFileExporter.cs @@ -42,8 +42,8 @@ public CsvFileExporter(ICsvFileWriter csvFileWriter, public async Task ExportAsync(IEnumerable items, ExporterOptions options) where T : class { - if (items == null) throw new ArgumentNullException(nameof(items)); - if (options == null) throw new ArgumentNullException(nameof(options)); + ArgumentNullException.ThrowIfNull(items); + ArgumentNullException.ThrowIfNull(options); var entities = items as T[] ?? items.ToArray(); if (!entities.Any()) diff --git a/src/LittleBlocks.Exports/Csv/CsvFileWriter.cs b/src/LittleBlocks.Exports/Csv/CsvFileWriter.cs index bafbd8b..6111b01 100644 --- a/src/LittleBlocks.Exports/Csv/CsvFileWriter.cs +++ b/src/LittleBlocks.Exports/Csv/CsvFileWriter.cs @@ -43,8 +43,8 @@ public CsvFileWriter(ICsvStorageTargetResolver storageTargetResolver, ILogger(IEnumerable items, CsvExportConfiguration configuration) where T : class { - if (items == null) throw new ArgumentNullException(nameof(items)); - if (configuration == null) throw new ArgumentNullException(nameof(configuration)); + ArgumentNullException.ThrowIfNull(items); + ArgumentNullException.ThrowIfNull(configuration); var enumerable = items as T[] ?? items.ToArray(); @@ -120,20 +120,18 @@ private async Task GenerateFileAsync(IEnumerable items, CsvExportC { _logger.LogInformation($"Generating file content for {typeof(T)} output"); - using (var stream = new MemoryStream()) - using (var writer = new StreamWriter(stream)) - using (var csvWriter = new CsvWriter(writer, configuration.Configuration)) - { - csvWriter.Context.SetupFromCsvConfiguration(configuration); + using var stream = new MemoryStream(); + await using var writer = new StreamWriter(stream); + await using var csvWriter = new CsvWriter(writer, configuration.Configuration); + csvWriter.Context.SetupFromCsvConfiguration(configuration); - await csvWriter.WriteRecordsAsync(items); - await csvWriter.FlushAsync(); - await writer.FlushAsync(); - await stream.FlushAsync(); + await csvWriter.WriteRecordsAsync(items); + await csvWriter.FlushAsync(); + await writer.FlushAsync(); + await stream.FlushAsync(); - stream.Position = 0; - return stream.ToByteArray(); - } + stream.Position = 0; + return stream.ToByteArray(); } } } \ No newline at end of file diff --git a/src/LittleBlocks.Exports/Csv/CvsContextExtensions.cs b/src/LittleBlocks.Exports/Csv/CvsContextExtensions.cs index 20fce89..8eddebe 100644 --- a/src/LittleBlocks.Exports/Csv/CvsContextExtensions.cs +++ b/src/LittleBlocks.Exports/Csv/CvsContextExtensions.cs @@ -26,8 +26,8 @@ public static class CvsContextExtensions { public static void SetupFromCsvConfiguration(this CsvContext context, CsvExportConfiguration configuration) { - if (context == null) throw new ArgumentNullException(nameof(context)); - if (configuration == null) throw new ArgumentNullException(nameof(configuration)); + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(configuration); configuration.ClassMaps.ToList().ForEach(cm => context.RegisterClassMap(cm)); diff --git a/src/LittleBlocks.Exports/Csv/DateBasedExportFileNameBuilder.cs b/src/LittleBlocks.Exports/Csv/DateBasedExportFileNameBuilder.cs index 8435a01..e3f7b2b 100644 --- a/src/LittleBlocks.Exports/Csv/DateBasedExportFileNameBuilder.cs +++ b/src/LittleBlocks.Exports/Csv/DateBasedExportFileNameBuilder.cs @@ -23,7 +23,7 @@ public class DateBasedExportFileNameBuilder : IExportFileNameBuilder { public string Build(ExporterOptions options) { - if (options == null) throw new ArgumentNullException(nameof(options)); + ArgumentNullException.ThrowIfNull(options); var format = options.FileNameDateTimeFormat ?? ExporterDefaults.DefaultFileNameDateTimeFormat; return $"{options.ExportFilePrefix}{options.AsOfDate.ToString(format)}.csv"; diff --git a/src/LittleBlocks.Exports/Csv/ExportResult.cs b/src/LittleBlocks.Exports/Csv/ExportResult.cs index df8d56f..9436906 100644 --- a/src/LittleBlocks.Exports/Csv/ExportResult.cs +++ b/src/LittleBlocks.Exports/Csv/ExportResult.cs @@ -32,7 +32,7 @@ private ExportResult() public static ExportResult Fail(string error, string targetFile = null) { - if (error == null) throw new ArgumentNullException(nameof(error)); + ArgumentNullException.ThrowIfNull(error); return new ExportResult { @@ -44,8 +44,8 @@ public static ExportResult Fail(string error, string targetFile = null) public static ExportResult Success(string targetFile, int recordCount) { - if (targetFile == null) throw new ArgumentNullException(nameof(targetFile)); - if (recordCount <= 0) throw new ArgumentOutOfRangeException(nameof(recordCount)); + ArgumentNullException.ThrowIfNull(targetFile); + ArgumentOutOfRangeException.ThrowIfNegativeOrZero(recordCount); return new ExportResult { diff --git a/src/LittleBlocks.Exports/Csv/StorageTargetException.cs b/src/LittleBlocks.Exports/Csv/StorageTargetException.cs index 415eb47..66543f9 100644 --- a/src/LittleBlocks.Exports/Csv/StorageTargetException.cs +++ b/src/LittleBlocks.Exports/Csv/StorageTargetException.cs @@ -22,14 +22,9 @@ namespace LittleBlocks.Exports.Csv { - public class StorageTargetException : Exception + public class StorageTargetException(IEnumerable exceptions) : Exception(FormatMessage(exceptions)) { - public StorageTargetException(IEnumerable exceptions) : base(FormatMessage(exceptions)) - { - Exceptions = exceptions ?? throw new ArgumentNullException(nameof(exceptions)); - } - - public IEnumerable Exceptions { get; } + public IEnumerable Exceptions { get; } = exceptions ?? throw new ArgumentNullException(nameof(exceptions)); private static string FormatMessage(IEnumerable exceptions) { diff --git a/src/LittleBlocks.Exports/LittleBlocks.Exports.csproj b/src/LittleBlocks.Exports/LittleBlocks.Exports.csproj index 6fa221f..46f0cf8 100644 --- a/src/LittleBlocks.Exports/LittleBlocks.Exports.csproj +++ b/src/LittleBlocks.Exports/LittleBlocks.Exports.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + net8.0 true LittleBlocks.Exports Mohammad Moattar, Lewis Percival @@ -11,13 +11,13 @@ - - - - - - - + + + + + + + diff --git a/src/LittleBlocks.Exports/ServiceCollectionExtensions.cs b/src/LittleBlocks.Exports/ServiceCollectionExtensions.cs index 1a0668f..7bd9719 100644 --- a/src/LittleBlocks.Exports/ServiceCollectionExtensions.cs +++ b/src/LittleBlocks.Exports/ServiceCollectionExtensions.cs @@ -57,7 +57,7 @@ public static IServiceCollection AddCsv(this IServiceCollection services, public static IServiceCollection AddS3BucketStorageWithSamlSupport(this IServiceCollection services, IConfiguration configuration, Action configure = null) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); var options = new BucketOptions(); configuration.GetSection(nameof(BucketOptions)).Bind(options); @@ -78,7 +78,7 @@ public static IServiceCollection AddS3BucketStorageWithSamlSupport(this IService public static IServiceCollection AddS3BucketStorage(this IServiceCollection services, IConfiguration configuration, Action configure = null) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); var options = new BucketOptions(); configuration.GetSection(nameof(BucketOptions)).Bind(options); @@ -98,7 +98,7 @@ public static IServiceCollection AddS3BucketStorage(this IServiceCollection serv public static IServiceCollection AddAccountWithSharedKeyStorage(this IServiceCollection services, IConfiguration configuration, Action configure = null) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); var options = new BlobSharedKeyOptions(); configuration.GetSection(nameof(BlobSharedKeyOptions)).Bind(options); @@ -118,7 +118,7 @@ public static IServiceCollection AddAccountWithSharedKeyStorage(this IServiceCol public static IServiceCollection AddAccountWithAzureAdStorage(this IServiceCollection services, IConfiguration configuration, Action configure = null) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); var options = new BlobAzureAdOptions(); configuration.GetSection(nameof(BlobAzureAdOptions)).Bind(options); @@ -138,7 +138,7 @@ public static IServiceCollection AddAccountWithAzureAdStorage(this IServiceColle public static IServiceCollection AddAccountWithEmulatorStorage(this IServiceCollection services) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); services.TryAddTransient(); services.AddTransient(sp => @@ -152,7 +152,7 @@ public static IServiceCollection AddAccountWithEmulatorStorage(this IServiceColl public static IServiceCollection AddInMemoryStorage(this IServiceCollection services) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); services.TryAddTransient(); services.AddScoped(sp => @@ -166,7 +166,7 @@ public static IServiceCollection AddInMemoryStorage(this IServiceCollection serv public static IServiceCollection AddLocalDiskStorage(this IServiceCollection services) { - if (services == null) throw new ArgumentNullException(nameof(services)); + ArgumentNullException.ThrowIfNull(services); services.TryAddTransient(); services.AddScoped(); diff --git a/src/LittleBlocks.Exports/Storage/CsvStorageTargetResolver.cs b/src/LittleBlocks.Exports/Storage/CsvStorageTargetResolver.cs index 5ef0771..7857cc5 100644 --- a/src/LittleBlocks.Exports/Storage/CsvStorageTargetResolver.cs +++ b/src/LittleBlocks.Exports/Storage/CsvStorageTargetResolver.cs @@ -33,7 +33,7 @@ public CsvStorageTargetResolver(IEnumerable exports) public ICsvStorageTarget Resolve(StorageTargetType storageTargetType) { - return _exports.ContainsKey(storageTargetType) ? _exports[storageTargetType] : null; + return _exports.GetValueOrDefault(storageTargetType); } } } \ No newline at end of file diff --git a/src/LittleBlocks.Exports/Storage/Fluent/S3/InvalidAwsProfileException.cs b/src/LittleBlocks.Exports/Storage/Fluent/S3/InvalidAwsProfileException.cs index 29ef4de..2c22aa3 100644 --- a/src/LittleBlocks.Exports/Storage/Fluent/S3/InvalidAwsProfileException.cs +++ b/src/LittleBlocks.Exports/Storage/Fluent/S3/InvalidAwsProfileException.cs @@ -19,10 +19,5 @@ namespace LittleBlocks.Exports.Storage.Fluent.S3 { - public class InvalidAwsProfileException : Exception - { - public InvalidAwsProfileException(string message) : base(message) - { - } - } + public class InvalidAwsProfileException(string message) : Exception(message); } \ No newline at end of file diff --git a/src/LittleBlocks.Exports/Storage/GenericCsvStorageTarget.cs b/src/LittleBlocks.Exports/Storage/GenericCsvStorageTarget.cs index fdb3816..f8c7440 100644 --- a/src/LittleBlocks.Exports/Storage/GenericCsvStorageTarget.cs +++ b/src/LittleBlocks.Exports/Storage/GenericCsvStorageTarget.cs @@ -41,9 +41,9 @@ public GenericCsvStorageTarget(StorageTargetType storageTargetType, IBlobStorage public async Task WriteAsync(string targetLocation, string fileName, byte[] fileContent) { - if (targetLocation == null) throw new ArgumentNullException(nameof(targetLocation)); - if (fileName == null) throw new ArgumentNullException(nameof(fileName)); - if (fileContent == null) throw new ArgumentNullException(nameof(fileContent)); + ArgumentNullException.ThrowIfNull(targetLocation); + ArgumentNullException.ThrowIfNull(fileName); + ArgumentNullException.ThrowIfNull(fileContent); var filePath = Path.Combine(targetLocation, fileName); await _blobStorage.WriteAsync(filePath, fileContent); diff --git a/src/LittleBlocks.Exports/Storage/LocalDiskCsvStorageTarget.cs b/src/LittleBlocks.Exports/Storage/LocalDiskCsvStorageTarget.cs index 5e25bff..6088fdc 100644 --- a/src/LittleBlocks.Exports/Storage/LocalDiskCsvStorageTarget.cs +++ b/src/LittleBlocks.Exports/Storage/LocalDiskCsvStorageTarget.cs @@ -31,9 +31,9 @@ public sealed class LocalDiskCsvStorageTarget : ICsvStorageTarget public async Task WriteAsync(string targetLocation, string fileName, byte[] fileContent) { - if (targetLocation == null) throw new ArgumentNullException(nameof(targetLocation)); - if (fileName == null) throw new ArgumentNullException(nameof(fileName)); - if (fileContent == null) throw new ArgumentNullException(nameof(fileContent)); + ArgumentNullException.ThrowIfNull(targetLocation); + ArgumentNullException.ThrowIfNull(fileName); + ArgumentNullException.ThrowIfNull(fileContent); var filePath = Path.Combine(targetLocation, fileName); var blobStorage = CreateBlobStorage(targetLocation); diff --git a/src/LittleBlocks.Exports/Storage/StorageTargetNotFoundException.cs b/src/LittleBlocks.Exports/Storage/StorageTargetNotFoundException.cs index de26add..fe72675 100644 --- a/src/LittleBlocks.Exports/Storage/StorageTargetNotFoundException.cs +++ b/src/LittleBlocks.Exports/Storage/StorageTargetNotFoundException.cs @@ -19,10 +19,5 @@ namespace LittleBlocks.Exports.Storage { - public sealed class StorageTargetNotFoundException : Exception - { - public StorageTargetNotFoundException(string message) : base(message) - { - } - } + public sealed class StorageTargetNotFoundException(string message) : Exception(message); } \ No newline at end of file