From 67729ae38880c97f5f9bd3c09f33839933af6a4c Mon Sep 17 00:00:00 2001 From: Alexander Zeitler Date: Sun, 14 Apr 2024 16:20:32 +0200 Subject: [PATCH] chore: update to .net8 / marten 7 / NUnit --- .../.idea/jsLibraryMappings.xml | 6 ++ .../MartenDotNetTestTemplate.Tests.csproj | 21 ++++--- src/MartenDotNetTestTemplate.Tests/Usings.cs | 3 +- .../When_snapshot_is_configured_inline.cs | 56 ++++++++----------- src/global.json | 2 +- 5 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 src/.idea/.idea.MartenDotNetTestTemplate/.idea/jsLibraryMappings.xml diff --git a/src/.idea/.idea.MartenDotNetTestTemplate/.idea/jsLibraryMappings.xml b/src/.idea/.idea.MartenDotNetTestTemplate/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/src/.idea/.idea.MartenDotNetTestTemplate/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/MartenDotNetTestTemplate.Tests/MartenDotNetTestTemplate.Tests.csproj b/src/MartenDotNetTestTemplate.Tests/MartenDotNetTestTemplate.Tests.csproj index 273054a..dc55180 100644 --- a/src/MartenDotNetTestTemplate.Tests/MartenDotNetTestTemplate.Tests.csproj +++ b/src/MartenDotNetTestTemplate.Tests/MartenDotNetTestTemplate.Tests.csproj @@ -1,23 +1,26 @@ - net7.0 + net8.0 enable enable false + + 12 - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/src/MartenDotNetTestTemplate.Tests/Usings.cs b/src/MartenDotNetTestTemplate.Tests/Usings.cs index c802f44..dd047d9 100644 --- a/src/MartenDotNetTestTemplate.Tests/Usings.cs +++ b/src/MartenDotNetTestTemplate.Tests/Usings.cs @@ -1 +1,2 @@ -global using Xunit; +global using NUnit.Framework; +global using Shouldly; diff --git a/src/MartenDotNetTestTemplate.Tests/When_snapshot_is_configured_inline.cs b/src/MartenDotNetTestTemplate.Tests/When_snapshot_is_configured_inline.cs index 8a6f278..eac6257 100644 --- a/src/MartenDotNetTestTemplate.Tests/When_snapshot_is_configured_inline.cs +++ b/src/MartenDotNetTestTemplate.Tests/When_snapshot_is_configured_inline.cs @@ -1,48 +1,43 @@ using Marten; +using Marten.Events.Aggregation; using Marten.Events.Projections; -using Newtonsoft.Json; -using Shouldly; using static MartenDotNetTestTemplate.Tests.TestDatabase; namespace MartenDotNetTestTemplate.Tests; public record SomethingHappened(DateTimeOffset On); -public class Something +public record Something(DateTimeOffset On) { public Guid Id { get; set; } - public DateTimeOffset On { get; } +}; - [JsonConstructor] - private Something() - { - } - - private Something(DateTimeOffset on) - { - On = on; - } - - public static Something Create(SomethingHappened happened) - { - return new Something(happened.On); - } +public class SomethingProjection : SingleStreamProjection +{ + public static Something Create( + SomethingHappened happened + ) => + new(happened.On); } +[TestFixture] public class When_snapshot_is_configured_inline { - public class When_event_is_persisted : IAsyncLifetime + public class When_event_is_persisted { private Guid _streamId; private DocumentStore? _store; + [SetUp] public async Task InitializeAsync() { - _store = DocumentStore.For(_ => - { - _.Connection(GetTestDbConnectionString); - _.Projections.Snapshot(SnapshotLifecycle.Inline); - }); + _store = DocumentStore.For( + _ => + { + _.Connection(GetTestDbConnectionString()); + _.Projections.Add(ProjectionLifecycle.Inline); + } + ); var on = DateTimeOffset.Now; var happened = new SomethingHappened(on); @@ -53,19 +48,16 @@ public async Task InitializeAsync() await session.SaveChangesAsync(); } - [Fact] + [Test] public async Task should_write_snapshot_in_same_transaction() { - await using var session = _store.QuerySession(); - var something = session.Load(_streamId); + await using var session = _store?.QuerySession(); + var something = await session?.LoadAsync(_streamId)!; something.ShouldNotBeNull(); } - public Task DisposeAsync() - { - _store.Dispose(); - return Task.CompletedTask; - } + [TearDown] + public async Task DisposeAsync() => await _store.DisposeAsync(); } } diff --git a/src/global.json b/src/global.json index 3d90901..c65c9ea 100644 --- a/src/global.json +++ b/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.0", + "version": "8.0.0", "rollForward": "latestMinor", "allowPrerelease": true }