From 7ce8a9a8208fc4d37e674577646e935b6ec7bd7f Mon Sep 17 00:00:00 2001 From: David Pine Date: Wed, 20 Nov 2024 15:34:36 -0600 Subject: [PATCH] Upgrade to .NET 9.0 --- .github/workflows/build-validation.yml | 4 +- .github/workflows/codeql.yml | 2 +- .github/workflows/nuget-publish.yml | 6 +-- .github/workflows/pr-validation.yml | 2 +- Directory.Build.props | 2 +- Directory.Packages.props | 44 +++++++++---------- .../BasicEventSourcingSample.csproj | 2 +- .../EventSourcingCustomerAccount.csproj | 2 +- .../EventSourcingJobsTracker.csproj | 2 +- .../ChangeFeedConsole.csproj | 2 +- .../ChangeFeedWeb/ChangeFeedWeb.csproj | 2 +- .../AzureFunctionTier.csproj | 2 +- .../BugSandbox/BugSandbox.csproj | 2 +- .../BugSandbox/Program.cs | 2 +- .../InMemoryWebTier/InMemoryWebTier.csproj | 2 +- .../OptimisticConcurrencyControl.csproj | 2 +- .../Paging/Paging.csproj | 2 +- .../ServiceTier/Program.cs | 10 ++--- .../ServiceTier/ServiceTier.csproj | 6 +-- .../Specification/Specification.csproj | 2 +- .../LanguagesControllerTests.cs | 2 +- .../WebTier.Integration.Tests.csproj | 2 +- .../WebTier/WebTier.csproj | 2 +- .../DefaultCosmosEventSourcingBuilder.cs | 2 +- .../Converters/DomainEventConverter.cs | 25 +++++------ .../Extensions/ServiceCollectionExtensions.cs | 2 +- .../DefaultDomainEventProjection.cs | 2 +- .../Stores/DefaultEventStore.Read.cs | 2 +- .../Builders/PatchOperationBuilder.cs | 7 +-- .../DefaultConatinerChangeFeedProcessor.cs | 4 +- .../Microsoft.Azure.CosmosRepository.csproj | 3 +- .../Repositories/InMemoryRepository.Count.cs | 16 ++++--- .../Repositories/InMemoryRepository.Create.cs | 2 +- .../InMemoryRepository.Serialization.cs | 9 ++-- .../Repositories/InMemoryRepository.Update.cs | 4 +- .../AcceptanceTests.Execute.cs | 2 +- ....CosmosEventSourcingAcceptanceTests.csproj | 2 +- .../Extensions/ObjectExtensions.cs | 2 +- .../Items/EventItemTests.cs | 10 ++--- ...soft.Azure.CosmosEventSourcingTests.csproj | 2 +- ...adLetterProjectionBuilderDecoratorTests.cs | 2 +- ...re.CosmosRepository.AspNetCoreTests.csproj | 2 +- ...ure.CosmosRepositoryAcceptanceTests.csproj | 2 +- .../Extensions/ExpressionExtensionTests.cs | 4 +- .../InMemoryRepositoryTests.cs | 6 +-- ...crosoft.Azure.CosmosRepositoryTests.csproj | 2 +- .../Paging/PagingTests.IAsyncEnumerable.cs | 8 ++-- .../CosmosTestHelper/CosmosTestHelper.csproj | 5 ++- 48 files changed, 116 insertions(+), 117 deletions(-) diff --git a/.github/workflows/build-validation.yml b/.github/workflows/build-validation.yml index 5d743f83d..6ad618be7 100644 --- a/.github/workflows/build-validation.yml +++ b/.github/workflows/build-validation.yml @@ -34,7 +34,7 @@ jobs: uses: actions/setup-dotnet@main with: dotnet-version: | - 8.0.x + 9.0.x - name: Install dependencies run: dotnet restore @@ -57,7 +57,7 @@ jobs: # uses: actions/setup-dotnet@main # with: # dotnet-version: | - # 8.0.x + # 9.0.x # - name: Install dependencies # run: dotnet restore diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 7046dff74..63096c3e4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -81,7 +81,7 @@ jobs: uses: actions/setup-dotnet@main with: dotnet-version: | - 8.0.x + 9.0.x - name: Install dependencies run: dotnet restore diff --git a/.github/workflows/nuget-publish.yml b/.github/workflows/nuget-publish.yml index 9d3dc3882..6c2514ba8 100644 --- a/.github/workflows/nuget-publish.yml +++ b/.github/workflows/nuget-publish.yml @@ -12,7 +12,7 @@ jobs: uses: actions/setup-dotnet@main with: dotnet-version: | - 8.0.x + 9.0.x - name: Install dependencies run: dotnet restore @@ -32,7 +32,7 @@ jobs: # uses: actions/setup-dotnet@main # with: # dotnet-version: | - # 8.0.x + # 9.0.x # - name: Install dependencies # run: dotnet restore @@ -107,7 +107,7 @@ jobs: uses: actions/setup-dotnet@main with: dotnet-version: | - 8.0.x + 9.0.x - name: Restore ${{ matrix.project }} dependencies run: dotnet restore ./src/${{ matrix.project }}/${{ matrix.project }}.csproj diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 21acd6bd3..0fe74b67b 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -22,7 +22,7 @@ jobs: uses: actions/setup-dotnet@main with: dotnet-version: | - 8.0.x + 9.0.x - name: Install dependencies run: dotnet restore diff --git a/Directory.Build.props b/Directory.Build.props index 561133061..1c9f5446e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,7 +13,7 @@ netstandard2.0 - net7.0;net8.0; + net8.0;net9.0 preview diff --git a/Directory.Packages.props b/Directory.Packages.props index be0fca56d..d5937e929 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,40 +3,40 @@ true - + - - + + - - + + - - - - - - - - - - - - + + + + + + + + + + + + - + - - - + + + - + diff --git a/samples/Microsoft.Azure.CosmosEventSourcing/BasicEventSourcingSample/BasicEventSourcingSample.csproj b/samples/Microsoft.Azure.CosmosEventSourcing/BasicEventSourcingSample/BasicEventSourcingSample.csproj index 2e4f37d6f..b7966df14 100644 --- a/samples/Microsoft.Azure.CosmosEventSourcing/BasicEventSourcingSample/BasicEventSourcingSample.csproj +++ b/samples/Microsoft.Azure.CosmosEventSourcing/BasicEventSourcingSample/BasicEventSourcingSample.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable 373fc06c-c3e7-4ecb-bf30-88a8ae4eb700 diff --git a/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingCustomerAccount/EventSourcingCustomerAccount.csproj b/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingCustomerAccount/EventSourcingCustomerAccount.csproj index 54f4839bf..a8dec366b 100644 --- a/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingCustomerAccount/EventSourcingCustomerAccount.csproj +++ b/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingCustomerAccount/EventSourcingCustomerAccount.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable 55a00f1c-8604-4ac2-adf3-dd3127af43bc diff --git a/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingJobsTracker/EventSourcingJobsTracker.csproj b/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingJobsTracker/EventSourcingJobsTracker.csproj index f64647e67..3359d80b6 100644 --- a/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingJobsTracker/EventSourcingJobsTracker.csproj +++ b/samples/Microsoft.Azure.CosmosEventSourcing/EventSourcingJobsTracker/EventSourcingJobsTracker.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable ce605ed2-3eba-45c1-8970-76b34c1c2837 diff --git a/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedConsole/ChangeFeedConsole.csproj b/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedConsole/ChangeFeedConsole.csproj index 5a0ae4d3c..04e32000d 100644 --- a/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedConsole/ChangeFeedConsole.csproj +++ b/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedConsole/ChangeFeedConsole.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable diff --git a/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedWeb/ChangeFeedWeb.csproj b/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedWeb/ChangeFeedWeb.csproj index ea36d42f0..bf1de9416 100644 --- a/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedWeb/ChangeFeedWeb.csproj +++ b/samples/Microsoft.Azure.CosmosRepository.AspNetCore/ChangeFeedWeb/ChangeFeedWeb.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable 66ceb007-2b64-4ecc-8234-8eb82effee6b diff --git a/samples/Microsoft.Azure.CosmosRepository/AzureFunctionTier/AzureFunctionTier.csproj b/samples/Microsoft.Azure.CosmosRepository/AzureFunctionTier/AzureFunctionTier.csproj index 22b6ab28c..456b6811d 100644 --- a/samples/Microsoft.Azure.CosmosRepository/AzureFunctionTier/AzureFunctionTier.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/AzureFunctionTier/AzureFunctionTier.csproj @@ -1,6 +1,6 @@  - net8.0 + net9.0 enable v4 diff --git a/samples/Microsoft.Azure.CosmosRepository/BugSandbox/BugSandbox.csproj b/samples/Microsoft.Azure.CosmosRepository/BugSandbox/BugSandbox.csproj index ae7c96d95..5a9ab9bb5 100644 --- a/samples/Microsoft.Azure.CosmosRepository/BugSandbox/BugSandbox.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/BugSandbox/BugSandbox.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable diff --git a/samples/Microsoft.Azure.CosmosRepository/BugSandbox/Program.cs b/samples/Microsoft.Azure.CosmosRepository/BugSandbox/Program.cs index d27032711..439346c29 100644 --- a/samples/Microsoft.Azure.CosmosRepository/BugSandbox/Program.cs +++ b/samples/Microsoft.Azure.CosmosRepository/BugSandbox/Program.cs @@ -57,7 +57,7 @@ await repository.CreateAsync( public class ExampleModel : Item { - public string Category { get; set; } + public required string Category { get; set; } } public class ExampleSpecification : DefaultSpecification diff --git a/samples/Microsoft.Azure.CosmosRepository/InMemoryWebTier/InMemoryWebTier.csproj b/samples/Microsoft.Azure.CosmosRepository/InMemoryWebTier/InMemoryWebTier.csproj index 9bc8b596b..e5eaf6412 100644 --- a/samples/Microsoft.Azure.CosmosRepository/InMemoryWebTier/InMemoryWebTier.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/InMemoryWebTier/InMemoryWebTier.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 diff --git a/samples/Microsoft.Azure.CosmosRepository/OptimisticConcurrencyControl/OptimisticConcurrencyControl.csproj b/samples/Microsoft.Azure.CosmosRepository/OptimisticConcurrencyControl/OptimisticConcurrencyControl.csproj index 4e57cfa44..83ec893bb 100644 --- a/samples/Microsoft.Azure.CosmosRepository/OptimisticConcurrencyControl/OptimisticConcurrencyControl.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/OptimisticConcurrencyControl/OptimisticConcurrencyControl.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable enable fd4da918-55af-4010-9ba0-e75f0e0dc917 diff --git a/samples/Microsoft.Azure.CosmosRepository/Paging/Paging.csproj b/samples/Microsoft.Azure.CosmosRepository/Paging/Paging.csproj index 8b91affe4..a72628a9d 100644 --- a/samples/Microsoft.Azure.CosmosRepository/Paging/Paging.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/Paging/Paging.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 9c9f04ba-0288-4b94-a15e-c669da85dfad diff --git a/samples/Microsoft.Azure.CosmosRepository/ServiceTier/Program.cs b/samples/Microsoft.Azure.CosmosRepository/ServiceTier/Program.cs index e3663066b..e1a57c1ae 100644 --- a/samples/Microsoft.Azure.CosmosRepository/ServiceTier/Program.cs +++ b/samples/Microsoft.Azure.CosmosRepository/ServiceTier/Program.cs @@ -59,7 +59,7 @@ static async Task RoundtripCrudOpsOnPeopleRepositoryAsync(IRepository re // Creating... Console.WriteLine("[Person] Repository creating..."); - _ = await repository.CreateAsync(new[] { maryShaw, calvinWeatherfield }); + _ = await repository.CreateAsync([maryShaw, calvinWeatherfield]); // Reading... Person mary = await repository.GetAsync(maryShaw.Id, maryShaw.SyntheticPartitionKey); @@ -117,7 +117,7 @@ static async Task VerifyUpdates(IRepository repo) // Creating... Console.WriteLine("[Widget] Repository creating..."); - _ = await repository.CreateAsync(new[] { widget1, widget2 }); + _ = await repository.CreateAsync([widget1, widget2]); // Reading... Widget contraption = await repository.GetAsync(widget1.Id); @@ -208,9 +208,9 @@ static async Task ServiceExampleAsync(IExampleService service) // Deleting... Console.WriteLine("[Person] Service deleting..."); - await Task.WhenAll(new[] - { + await Task.WhenAll( + [ service.DeletePersonAsync(james).AsTask(), service.DeletePersonAsync(adele).AsTask() - }); + ]); } diff --git a/samples/Microsoft.Azure.CosmosRepository/ServiceTier/ServiceTier.csproj b/samples/Microsoft.Azure.CosmosRepository/ServiceTier/ServiceTier.csproj index 77d30dab5..428ed2699 100644 --- a/samples/Microsoft.Azure.CosmosRepository/ServiceTier/ServiceTier.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/ServiceTier/ServiceTier.csproj @@ -1,15 +1,15 @@ - + Exe - net8.0 + net9.0 enable enable - + diff --git a/samples/Microsoft.Azure.CosmosRepository/Specification/Specification.csproj b/samples/Microsoft.Azure.CosmosRepository/Specification/Specification.csproj index 41ec6c6a6..50340c863 100644 --- a/samples/Microsoft.Azure.CosmosRepository/Specification/Specification.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/Specification/Specification.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net9.0 enable diff --git a/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/LanguagesControllerTests.cs b/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/LanguagesControllerTests.cs index 10e95219a..70ca9776b 100644 --- a/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/LanguagesControllerTests.cs +++ b/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/LanguagesControllerTests.cs @@ -37,7 +37,7 @@ public async Task Post_Always_Creates_A_Language() Id = string.Empty, Name = "C#", Description = "A language created by Microsoft.", - Aliases = new[] { "C#", ".NET" }, + Aliases = ["C#", ".NET"], PrimaryStyle = ProgrammingStyle.ObjectOriented, InitialReleaseDate = new DateTime(2001, 10, 25) }; diff --git a/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/WebTier.Integration.Tests.csproj b/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/WebTier.Integration.Tests.csproj index 187791e5c..42fd58309 100644 --- a/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/WebTier.Integration.Tests.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/WebTier.Integration.Tests/WebTier.Integration.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 false diff --git a/samples/Microsoft.Azure.CosmosRepository/WebTier/WebTier.csproj b/samples/Microsoft.Azure.CosmosRepository/WebTier/WebTier.csproj index d843fa6d7..73aea9f4d 100644 --- a/samples/Microsoft.Azure.CosmosRepository/WebTier/WebTier.csproj +++ b/samples/Microsoft.Azure.CosmosRepository/WebTier/WebTier.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 faa0315d-a570-4d95-9c36-14570d154189 diff --git a/src/Microsoft.Azure.CosmosEventSourcing/Builders/DefaultCosmosEventSourcingBuilder.cs b/src/Microsoft.Azure.CosmosEventSourcing/Builders/DefaultCosmosEventSourcingBuilder.cs index 19b4b5e8e..fea21cec3 100644 --- a/src/Microsoft.Azure.CosmosEventSourcing/Builders/DefaultCosmosEventSourcingBuilder.cs +++ b/src/Microsoft.Azure.CosmosEventSourcing/Builders/DefaultCosmosEventSourcingBuilder.cs @@ -62,7 +62,7 @@ public ICosmosEventSourcingBuilder AddDomainEventTypes( .Where(type => typeof(IDomainEvent).IsAssignableFrom(type))) .ToList(); - types.ForEach(t => DomainEventConverter.ConvertableTypes.Add(t)); + types.ForEach(t => DomainEventConverter.ConvertibleTypes.Add(t)); return this; } diff --git a/src/Microsoft.Azure.CosmosEventSourcing/Converters/DomainEventConverter.cs b/src/Microsoft.Azure.CosmosEventSourcing/Converters/DomainEventConverter.cs index c44306693..d32bab849 100644 --- a/src/Microsoft.Azure.CosmosEventSourcing/Converters/DomainEventConverter.cs +++ b/src/Microsoft.Azure.CosmosEventSourcing/Converters/DomainEventConverter.cs @@ -9,15 +9,15 @@ namespace Microsoft.Azure.CosmosEventSourcing.Converters; internal class DomainEventConverter : JsonConverter { - public static HashSet ConvertableTypes { get; } = []; + public static HashSet ConvertibleTypes { get; } = []; - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => - serializer.Serialize(writer, value, value.GetType()); + public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer) => + serializer.Serialize(writer, value, objectType: value?.GetType() ?? throw new ArgumentNullException(nameof(value))); - public override object ReadJson( + public override object? ReadJson( JsonReader reader, Type objectType, - object existingValue, + object? existingValue, JsonSerializer serializer) { try @@ -25,18 +25,17 @@ public override object ReadJson( var j = JToken.ReadFrom(reader); var type = j["eventName"]?.ToString(); type ??= j["EventName"]?.ToString(); - Type? payloadType = ConvertableTypes.FirstOrDefault(x => x.Name == type); + Type? payloadType = ConvertibleTypes.FirstOrDefault(x => x.Name == type); - if (payloadType is null) + return payloadType switch { - return new NonDeserializableEvent + null => new NonDeserializableEvent { Name = type ?? "not-defined", - Payload = j.ToObject() - }; - } - - return j.ToObject(payloadType); + Payload = j.ToObject() ?? [] + }, + _ => j.ToObject(payloadType) + }; } catch (Exception e) { diff --git a/src/Microsoft.Azure.CosmosEventSourcing/Extensions/ServiceCollectionExtensions.cs b/src/Microsoft.Azure.CosmosEventSourcing/Extensions/ServiceCollectionExtensions.cs index 79ffd6d59..4f80d5faa 100644 --- a/src/Microsoft.Azure.CosmosEventSourcing/Extensions/ServiceCollectionExtensions.cs +++ b/src/Microsoft.Azure.CosmosEventSourcing/Extensions/ServiceCollectionExtensions.cs @@ -28,7 +28,7 @@ public static IServiceCollection AddCosmosEventSourcing( Action eventSourcingBuilder) { DefaultCosmosEventSourcingBuilder builder = new(services); - DomainEventConverter.ConvertableTypes.Add(typeof(AtomicEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(AtomicEvent)); eventSourcingBuilder.Invoke(builder); services.AddScoped(); services.AddScoped(typeof(IEventStore<>), typeof(DefaultEventStore<>)); diff --git a/src/Microsoft.Azure.CosmosEventSourcing/Projections/DefaultDomainEventProjection.cs b/src/Microsoft.Azure.CosmosEventSourcing/Projections/DefaultDomainEventProjection.cs index 373505b93..b2bd6d651 100644 --- a/src/Microsoft.Azure.CosmosEventSourcing/Projections/DefaultDomainEventProjection.cs +++ b/src/Microsoft.Azure.CosmosEventSourcing/Projections/DefaultDomainEventProjection.cs @@ -46,7 +46,7 @@ await Task.WhenAll(handlers.Select(handler => try { var result = handlerType.GetMethod("HandleAsync")? - .Invoke(handler, new object[] { eventItem.DomainEvent, eventItem, cancellationToken }); + .Invoke(handler, [eventItem.DomainEvent, eventItem, cancellationToken]); if (result is ValueTask valueTask) { diff --git a/src/Microsoft.Azure.CosmosEventSourcing/Stores/DefaultEventStore.Read.cs b/src/Microsoft.Azure.CosmosEventSourcing/Stores/DefaultEventStore.Read.cs index e88f78510..42029cda2 100644 --- a/src/Microsoft.Azure.CosmosEventSourcing/Stores/DefaultEventStore.Read.cs +++ b/src/Microsoft.Azure.CosmosEventSourcing/Stores/DefaultEventStore.Read.cs @@ -37,7 +37,7 @@ public async ValueTask ReadAggregateAsync( return method is null ? throw new ReplayMethodNotDefinedException(type) - : (TAggregateRoot)method.Invoke(null, new object[] { payloads })!; + : (TAggregateRoot)method.Invoke(null, [payloads])!; } public async ValueTask ReadAggregateAsync( diff --git a/src/Microsoft.Azure.CosmosRepository/Builders/PatchOperationBuilder.cs b/src/Microsoft.Azure.CosmosRepository/Builders/PatchOperationBuilder.cs index f9d39e6de..20ae3cf01 100644 --- a/src/Microsoft.Azure.CosmosRepository/Builders/PatchOperationBuilder.cs +++ b/src/Microsoft.Azure.CosmosRepository/Builders/PatchOperationBuilder.cs @@ -31,21 +31,18 @@ public IPatchOperationBuilder Replace(Expression - GetPropertyToReplace([propertyInfo]); - private string GetPropertyToReplace(IEnumerable propertyInfos) { List propertiesNames = []; - foreach (PropertyInfo propertyInfo in propertyInfos) + foreach (PropertyInfo propertyInfo in propertyInfos.Cast()) { JsonPropertyAttribute[] attributes = propertyInfo.GetCustomAttributes(true).ToArray(); var propertyName = attributes.Length is 0 ? _namingStrategy.GetPropertyName(propertyInfo.Name, false) - : attributes[0].PropertyName; + : attributes[0].PropertyName ?? propertyInfo.Name; propertiesNames.Add(propertyName); } diff --git a/src/Microsoft.Azure.CosmosRepository/ChangeFeed/DefaultConatinerChangeFeedProcessor.cs b/src/Microsoft.Azure.CosmosRepository/ChangeFeed/DefaultConatinerChangeFeedProcessor.cs index c3c513b3c..321ba8141 100644 --- a/src/Microsoft.Azure.CosmosRepository/ChangeFeed/DefaultConatinerChangeFeedProcessor.cs +++ b/src/Microsoft.Azure.CosmosRepository/ChangeFeed/DefaultConatinerChangeFeedProcessor.cs @@ -73,7 +73,7 @@ internal async Task OnChangesAsync( foreach (JObject change in changes) { - if (!change.TryGetValue("type", out JToken type)) + if (!change.TryGetValue("type", out JToken? type)) { //TODO: _logger.LogWarning(...) here? Should this be turn on/off thing? A user might not have created documents with the type field ?! continue; @@ -121,7 +121,7 @@ await Task.WhenAll(handlers.Select(handler => try { var response = handlerType.GetMethod("HandleAsync")? - .Invoke(handler, new[] { item, cancellationToken }); + .Invoke(handler, [item, cancellationToken]); if (response is ValueTask valueTask) { diff --git a/src/Microsoft.Azure.CosmosRepository/Microsoft.Azure.CosmosRepository.csproj b/src/Microsoft.Azure.CosmosRepository/Microsoft.Azure.CosmosRepository.csproj index cff3f7544..5c9ba7df3 100644 --- a/src/Microsoft.Azure.CosmosRepository/Microsoft.Azure.CosmosRepository.csproj +++ b/src/Microsoft.Azure.CosmosRepository/Microsoft.Azure.CosmosRepository.csproj @@ -34,7 +34,7 @@ false false Microsoft.Azure.CosmosRepository - NU5125 + $(NoWarn);NU5125 true https://github.com/IEvangelist/azure-cosmos-dotnet-repository LICENSE @@ -50,6 +50,7 @@ + diff --git a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Count.cs b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Count.cs index e19586f1b..0870c52c7 100644 --- a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Count.cs +++ b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Count.cs @@ -1,7 +1,6 @@ // Copyright (c) David Pine. All rights reserved. // Licensed under the MIT License. - // ReSharper disable once CheckNamespace namespace Microsoft.Azure.CosmosRepository; @@ -11,17 +10,20 @@ internal partial class InMemoryRepository public async ValueTask CountAsync(CancellationToken cancellationToken = default) { await Task.CompletedTask; - return InMemoryStorage - .GetValues().Select(DeserializeItem).Count(item => item.Type == typeof(TItem).Name); + return InMemoryStorage.GetValues() + .Select(DeserializeItem) + .Count(item => item?.Type == typeof(TItem).Name); } /// - public async ValueTask CountAsync(Expression> predicate, + public async ValueTask CountAsync( + Expression> predicate, CancellationToken cancellationToken = default) { await Task.CompletedTask; - return InMemoryStorage - .GetValues().Select(DeserializeItem).Count(predicate.Compose( - item => item.Type == typeof(TItem).Name, Expression.AndAlso).Compile()); + return InMemoryStorage.GetValues() + .Select(DeserializeItem) + .Count(predicate.Compose( + item => item.Type == typeof(TItem).Name, Expression.AndAlso).Compile()); } } \ No newline at end of file diff --git a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Create.cs b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Create.cs index 5d5d43876..46a5758cd 100644 --- a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Create.cs +++ b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Create.cs @@ -49,7 +49,7 @@ private async ValueTask CreateAsync(TItem value, bool raiseChanges = fals valueWithTimestamps.CreatedTimeUtc = DateTime.UtcNow; } - var serialisedValue = SerializeItem(value, Guid.NewGuid().ToString(), CurrentTs); + var serialisedValue = InMemoryRepository.SerializeItem(value, Guid.NewGuid().ToString(), CurrentTs); ConcurrentDictionary items = InMemoryStorage.GetDictionary(); items.TryAdd(value.Id, serialisedValue); diff --git a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Serialization.cs b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Serialization.cs index f405d11be..b12102f5e 100644 --- a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Serialization.cs +++ b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Serialization.cs @@ -7,7 +7,7 @@ namespace Microsoft.Azure.CosmosRepository; internal partial class InMemoryRepository { - private string SerializeItem( + private static string SerializeItem( TItem item, string? etag = null, long? ts = null) @@ -26,8 +26,9 @@ private string SerializeItem( return jObject.ToString(); } - internal TItem DeserializeItem(string jsonItem) => JsonConvert.DeserializeObject(jsonItem); + internal TItem DeserializeItem(string jsonItem) => + JsonConvert.DeserializeObject(jsonItem)!; - internal TDeserializeTo DeserializeItem(string jsonItem) => - JsonConvert.DeserializeObject(jsonItem); + internal static TDeserializeTo DeserializeItem(string jsonItem) => + JsonConvert.DeserializeObject(jsonItem)!; } \ No newline at end of file diff --git a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Update.cs b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Update.cs index ff9721230..c9136bbcc 100644 --- a/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Update.cs +++ b/src/Microsoft.Azure.CosmosRepository/Repositories/InMemoryRepository.Update.cs @@ -30,7 +30,7 @@ private async ValueTask UpdateAsync( MismatchedEtags(); } - items[value.Id] = SerializeItem(value, Guid.NewGuid().ToString(), CurrentTs); + items[value.Id] = InMemoryRepository.SerializeItem(value, Guid.NewGuid().ToString(), CurrentTs); TItem item = DeserializeItem(items[value.Id]); @@ -129,7 +129,7 @@ public async ValueTask UpdateAsync(string id, ConcurrentDictionary items = InMemoryStorage.GetDictionary(); - items[id] = SerializeItem(item!, Guid.NewGuid().ToString(), CurrentTs); + items[id] = InMemoryRepository.SerializeItem(item!, Guid.NewGuid().ToString(), CurrentTs); Changes?.Invoke(new ChangeFeedItemArgs(DeserializeItem(items[id]))); } diff --git a/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/AcceptanceTests.Execute.cs b/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/AcceptanceTests.Execute.cs index b8a661151..0869d5e88 100644 --- a/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/AcceptanceTests.Execute.cs +++ b/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/AcceptanceTests.Execute.cs @@ -20,7 +20,7 @@ namespace Microsoft.Azure.CosmosEventSourcingAcceptanceTests; public partial class AcceptanceTests { - private readonly string[] _names = { "List 1", "List 2", "List 3" }; + private readonly string[] _names = ["List 1", "List 2", "List 3"]; private readonly TodoListMapper _mapper = new(); private readonly List _atomicEventIds = []; diff --git a/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests.csproj b/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests.csproj index 15aada29f..aaa6995f1 100644 --- a/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests.csproj +++ b/tests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests/Microsoft.Azure.CosmosEventSourcingAcceptanceTests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable false diff --git a/tests/Microsoft.Azure.CosmosEventSourcingTests/Extensions/ObjectExtensions.cs b/tests/Microsoft.Azure.CosmosEventSourcingTests/Extensions/ObjectExtensions.cs index dc8e1c051..c1b5cb20a 100644 --- a/tests/Microsoft.Azure.CosmosEventSourcingTests/Extensions/ObjectExtensions.cs +++ b/tests/Microsoft.Azure.CosmosEventSourcingTests/Extensions/ObjectExtensions.cs @@ -29,7 +29,7 @@ public static void SetPrivatePropertyValue(this object obj, string propName, obj, BindingFlags.NonPublic | BindingFlags.Instance, null, - new object?[] { val! }, + [val!], null); } } \ No newline at end of file diff --git a/tests/Microsoft.Azure.CosmosEventSourcingTests/Items/EventItemTests.cs b/tests/Microsoft.Azure.CosmosEventSourcingTests/Items/EventItemTests.cs index 422926a8d..c27c3a17b 100644 --- a/tests/Microsoft.Azure.CosmosEventSourcingTests/Items/EventItemTests.cs +++ b/tests/Microsoft.Azure.CosmosEventSourcingTests/Items/EventItemTests.cs @@ -40,7 +40,7 @@ public void Ctor_ValidValues_CreatesSource() public void EventItem_Serialization_WorksCorrectly() { //Arrange - DomainEventConverter.ConvertableTypes.Add(typeof(SampleEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(SampleEvent)); SampleEvent evt = new() { EventId = Guid.NewGuid().ToString(), @@ -66,7 +66,7 @@ public void EventItem_Serialization_WorksCorrectly() public void EventItem_AtomicEventSerialization_WorksCorrectlyWithNullTimeToLive() { //Arrange - DomainEventConverter.ConvertableTypes.Add(typeof(AtomicEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(AtomicEvent)); var etagValue = Guid.NewGuid().ToString(); AtomicEvent evt = new(Guid.NewGuid().ToString(), string.Empty) { @@ -97,7 +97,7 @@ public void EventItem_AtomicEventSerialization_WorksCorrectlyWithNullTimeToLive( public void EventItem_AtomicEventSerialization_WorksCorrectlyWithPopulatedTimeToLive() { //Arrange - DomainEventConverter.ConvertableTypes.Add(typeof(AtomicEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(AtomicEvent)); var etagValue = Guid.NewGuid().ToString(); AtomicEvent evt = new(Guid.NewGuid().ToString(), string.Empty) { @@ -132,7 +132,7 @@ public void EventItem_AtomicEventSerialization_WorksCorrectlyWithPopulatedTimeTo public void EventItem_AtomicEventDeserialization_WorksCorrectly() { //Arrange - DomainEventConverter.ConvertableTypes.Add(typeof(AtomicEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(AtomicEvent)); var etagValue = Guid.NewGuid().ToString(); AtomicEvent atomicEvent = new(nameof(AtomicEvent), null!) { @@ -162,7 +162,7 @@ public void EventItem_AtomicEventDeserialization_WorksCorrectly() public void EventItem_AtomicEventPass_WorksCorrectly() { //Arrange - DomainEventConverter.ConvertableTypes.Add(typeof(AtomicEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(AtomicEvent)); var etagValue = Guid.NewGuid().ToString(); AtomicEvent atomicEvent = new(nameof(AtomicEvent), null!) { diff --git a/tests/Microsoft.Azure.CosmosEventSourcingTests/Microsoft.Azure.CosmosEventSourcingTests.csproj b/tests/Microsoft.Azure.CosmosEventSourcingTests/Microsoft.Azure.CosmosEventSourcingTests.csproj index 828ca6953..63b843750 100644 --- a/tests/Microsoft.Azure.CosmosEventSourcingTests/Microsoft.Azure.CosmosEventSourcingTests.csproj +++ b/tests/Microsoft.Azure.CosmosEventSourcingTests/Microsoft.Azure.CosmosEventSourcingTests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable false True diff --git a/tests/Microsoft.Azure.CosmosEventSourcingTests/Projections/Decorators/DeadLetterProjectionBuilderDecoratorTests.cs b/tests/Microsoft.Azure.CosmosEventSourcingTests/Projections/Decorators/DeadLetterProjectionBuilderDecoratorTests.cs index c6e0a07af..08452f64f 100644 --- a/tests/Microsoft.Azure.CosmosEventSourcingTests/Projections/Decorators/DeadLetterProjectionBuilderDecoratorTests.cs +++ b/tests/Microsoft.Azure.CosmosEventSourcingTests/Projections/Decorators/DeadLetterProjectionBuilderDecoratorTests.cs @@ -69,7 +69,7 @@ public async Task Handle_FailedProjection_WritesToDeadLetterDb() .WithDeadLetterDecorator(); }); - DomainEventConverter.ConvertableTypes.Add(typeof(SampleDecoratorEvent)); + DomainEventConverter.ConvertibleTypes.Add(typeof(SampleDecoratorEvent)); services.AddInMemoryCosmosRepository(); diff --git a/tests/Microsoft.Azure.CosmosRepository.AspNetCoreTests/Microsoft.Azure.CosmosRepository.AspNetCoreTests.csproj b/tests/Microsoft.Azure.CosmosRepository.AspNetCoreTests/Microsoft.Azure.CosmosRepository.AspNetCoreTests.csproj index df014030c..706758be2 100644 --- a/tests/Microsoft.Azure.CosmosRepository.AspNetCoreTests/Microsoft.Azure.CosmosRepository.AspNetCoreTests.csproj +++ b/tests/Microsoft.Azure.CosmosRepository.AspNetCoreTests/Microsoft.Azure.CosmosRepository.AspNetCoreTests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable false diff --git a/tests/Microsoft.Azure.CosmosRepositoryAcceptanceTests/Microsoft.Azure.CosmosRepositoryAcceptanceTests.csproj b/tests/Microsoft.Azure.CosmosRepositoryAcceptanceTests/Microsoft.Azure.CosmosRepositoryAcceptanceTests.csproj index 1d8a21ecb..d65c69a7d 100644 --- a/tests/Microsoft.Azure.CosmosRepositoryAcceptanceTests/Microsoft.Azure.CosmosRepositoryAcceptanceTests.csproj +++ b/tests/Microsoft.Azure.CosmosRepositoryAcceptanceTests/Microsoft.Azure.CosmosRepositoryAcceptanceTests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable false diff --git a/tests/Microsoft.Azure.CosmosRepositoryTests/Extensions/ExpressionExtensionTests.cs b/tests/Microsoft.Azure.CosmosRepositoryTests/Extensions/ExpressionExtensionTests.cs index 8248c3c10..1e735674e 100644 --- a/tests/Microsoft.Azure.CosmosRepositoryTests/Extensions/ExpressionExtensionTests.cs +++ b/tests/Microsoft.Azure.CosmosRepositoryTests/Extensions/ExpressionExtensionTests.cs @@ -8,8 +8,8 @@ public class ExpressionExtensionTests public static IEnumerable CompositionInput => new[] { new object[] { new DateTime(1970, 4, 20), true }, - new object[] { default(DateTime), false }, - new object[] { DateTime.Now, false } + [default(DateTime), false], + [DateTime.Now, false] }; [ diff --git a/tests/Microsoft.Azure.CosmosRepositoryTests/InMemoryRepositoryTests.cs b/tests/Microsoft.Azure.CosmosRepositoryTests/InMemoryRepositoryTests.cs index 27c6c7f0c..18cdb5a0d 100644 --- a/tests/Microsoft.Azure.CosmosRepositoryTests/InMemoryRepositoryTests.cs +++ b/tests/Microsoft.Azure.CosmosRepositoryTests/InMemoryRepositoryTests.cs @@ -245,12 +245,10 @@ await Assert.ThrowsAsync(() => _invalidSerializableRepository.CreateAsync(invalidSerialisable).AsTask()); Assert.True(InMemoryStorage.GetDictionary().ContainsKey(invalidSerialisable.Id)); Assert.Equal(args.Property1, - _invalidSerializableRepository - .DeserializeItem( + InMemoryRepository.DeserializeItem( InMemoryStorage.GetDictionary()[invalidSerialisable.Id]).Property1); Assert.Equal(args.PartitionKey, - _invalidSerializableRepository - .DeserializeItem( + InMemoryRepository.DeserializeItem( InMemoryStorage.GetDictionary()[invalidSerialisable.Id]).PartitionKey); } diff --git a/tests/Microsoft.Azure.CosmosRepositoryTests/Microsoft.Azure.CosmosRepositoryTests.csproj b/tests/Microsoft.Azure.CosmosRepositoryTests/Microsoft.Azure.CosmosRepositoryTests.csproj index 71c0e4bd1..eead00ed8 100644 --- a/tests/Microsoft.Azure.CosmosRepositoryTests/Microsoft.Azure.CosmosRepositoryTests.csproj +++ b/tests/Microsoft.Azure.CosmosRepositoryTests/Microsoft.Azure.CosmosRepositoryTests.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 true enable false diff --git a/tests/Microsoft.Azure.CosmosRepositoryTests/Paging/PagingTests.IAsyncEnumerable.cs b/tests/Microsoft.Azure.CosmosRepositoryTests/Paging/PagingTests.IAsyncEnumerable.cs index 74c72e3e8..f0048de52 100644 --- a/tests/Microsoft.Azure.CosmosRepositoryTests/Paging/PagingTests.IAsyncEnumerable.cs +++ b/tests/Microsoft.Azure.CosmosRepositoryTests/Paging/PagingTests.IAsyncEnumerable.cs @@ -22,7 +22,7 @@ public partial class PagingTests _expressionProvider, _specificationEvaluator); - private static readonly string[] s_sourceArray = new[] { "🎶", "💿", "🎸", "🥁", "🎙" }; + private static readonly string[] s_sourceArray = ["🎶", "💿", "🎸", "🥁", "🎙"]; public PagingTests() => _options.Setup(monitor => monitor.CurrentValue) @@ -32,8 +32,8 @@ public PagingTests() => public async Task ReadOnlyRepositoriesDefaultImplementationOfPageAsyncYieldsCorrectly() { // Arrange - TestItem[] items = new[] - { + TestItem[] items = + [ new TestItem { Number = 100, Property = "🎶 Record player" }, new TestItem { Number = 101, Property = "💿 Vinyl albums" }, new TestItem { Number = 102, Property = "🎸 Electric guitar" }, @@ -48,7 +48,7 @@ public async Task ReadOnlyRepositoriesDefaultImplementationOfPageAsyncYieldsCorr new TestItem { Number = 111, Property = "🎵 Music" }, new TestItem { Number = 112, Property = "🎨 Art" }, new TestItem { Number = 113, Property = "🎭 Self-expression" } - }; + ]; _containerProviderForTestItem.Setup( cp => cp.GetContainerAsync()).ReturnsAsync(_container.Object); diff --git a/tools/CosmosTestHelper/CosmosTestHelper.csproj b/tools/CosmosTestHelper/CosmosTestHelper.csproj index b53ca3e95..2dc311847 100644 --- a/tools/CosmosTestHelper/CosmosTestHelper.csproj +++ b/tools/CosmosTestHelper/CosmosTestHelper.csproj @@ -1,13 +1,14 @@ - + Exe - net8.0 + net9.0 enable enable +