Skip to content

Commit 8c79ee7

Browse files
author
Okunets Yurii
committed
Add net8 9 10 as target framework. Fix conflict for CreateVersion7
1 parent d65d8d6 commit 8c79ee7

File tree

11 files changed

+64
-19
lines changed

11 files changed

+64
-19
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<LangVersion>14</LangVersion>
5-
<TargetFramework>net10.0</TargetFramework>
4+
<LangVersion>13</LangVersion>
5+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
66
<EnableNETAnalyzers>true</EnableNETAnalyzers>
77
<Nullable>enable</Nullable>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

ManagedCode.Communication.Tests/Commands/CommandExtensionsTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using ManagedCode.Communication.Commands;
3+
using ManagedCode.Communication.Helpers;
34
using Shouldly;
45
using Xunit;
56

@@ -49,7 +50,7 @@ public void WithMetadata_Action_CreatesMetadataAndConfigures()
4950
[Fact]
5051
public void WithMetadata_AssignsExistingInstance()
5152
{
52-
var command = Command.Create(Guid.CreateVersion7(), "TestCommand");
53+
var command = Command.Create(GuidHelper.CreateVersion7(), "TestCommand");
5354
var metadata = new CommandMetadata { UserAgent = "cli" };
5455

5556
command.WithMetadata(metadata);

ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
<PackageReference Include="Microsoft.Orleans.TestingHost" Version="9.2.1"/>
2626
<PackageReference Include="Shouldly" Version="4.3.0" />
2727
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
28-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
29-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.0" />
30-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
3128
<PackageReference Include="xunit" Version="2.9.3"/>
3229
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
3330
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -42,6 +39,24 @@
4239
<PrivateAssets>all</PrivateAssets>
4340
</PackageReference>
4441
</ItemGroup>
42+
43+
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
44+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.11" />
45+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.11" />
46+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.11" />
47+
</ItemGroup>
48+
49+
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
50+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
51+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
52+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="9.0.1" />
53+
</ItemGroup>
54+
55+
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
56+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
57+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.0" />
58+
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
59+
</ItemGroup>
4560

4661
<ItemGroup>
4762
<ProjectReference Include="..\ManagedCode.Communication.AspNetCore\ManagedCode.Communication.AspNetCore.csproj"/>

ManagedCode.Communication.Tests/Orleans/OrleansSerializationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Shouldly;
55
using ManagedCode.Communication.CollectionResultT;
66
using ManagedCode.Communication.Commands;
7+
using ManagedCode.Communication.Helpers;
78
using ManagedCode.Communication.Tests.Orleans.Fixtures;
89
using ManagedCode.Communication.Tests.Orleans.Grains;
910
using ManagedCode.Communication.Tests.Orleans.Models;
@@ -32,7 +33,7 @@ public async Task CompleteWorkflow_AllTypes_ShouldSerializeCorrectly()
3233
var grain = _grainFactory.GetGrain<ITestSerializationGrain>(Guid.NewGuid());
3334

3435
// Step 1: Send a command
35-
var commandId = Guid.CreateVersion7();
36+
var commandId = GuidHelper.CreateVersion7();
3637
var paymentRequest = new PaymentRequest
3738
{
3839
OrderId = "order-999",

ManagedCode.Communication.Tests/Orleans/Serialization/CommandSerializationTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using Shouldly;
55
using ManagedCode.Communication.Commands;
6+
using ManagedCode.Communication.Helpers;
67
using ManagedCode.Communication.Tests.Orleans.Fixtures;
78
using ManagedCode.Communication.Tests.Orleans.Grains;
89
using ManagedCode.Communication.Tests.Orleans.Models;
@@ -154,7 +155,7 @@ public async Task CommandT_WithComplexPayload_ShouldSerializeCorrectly()
154155
}
155156
};
156157

157-
var command = Command<PaymentRequest>.From(Guid.CreateVersion7(), payload);
158+
var command = Command<PaymentRequest>.From(GuidHelper.CreateVersion7(), payload);
158159
command.CommandType = "ProcessPayment";
159160
command.CorrelationId = "correlation-789";
160161
command.CausationId = "causation-012";
@@ -202,7 +203,7 @@ public async Task PaginationCommand_ShouldSerializeCorrectly()
202203
var grain = _grainFactory.GetGrain<ITestSerializationGrain>(Guid.NewGuid());
203204
var options = new PaginationOptions(defaultPageSize: 25, maxPageSize: 50, minPageSize: 10);
204205

205-
var command = PaginationCommand.Create(Guid.CreateVersion7(), skip: 25, take: 5, options);
206+
var command = PaginationCommand.Create(GuidHelper.CreateVersion7(), skip: 25, take: 5, options);
206207
command.CorrelationId = "pagination-correlation";
207208
command.Metadata = new CommandMetadata
208209
{

ManagedCode.Communication/Commands/Factories/CommandFactoryBridge.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using ManagedCode.Communication.Helpers;
23

34
namespace ManagedCode.Communication.Commands;
45

@@ -10,7 +11,7 @@ internal static class CommandFactoryBridge
1011
public static TSelf Create<TSelf>(string commandType)
1112
where TSelf : class, ICommandFactory<TSelf>
1213
{
13-
return TSelf.Create(Guid.CreateVersion7(), commandType);
14+
return TSelf.Create(GuidHelper.CreateVersion7(), commandType);
1415
}
1516

1617
public static TSelf Create<TSelf>(Guid commandId, string commandType)
@@ -23,7 +24,7 @@ public static TSelf Create<TSelf, TEnum>(TEnum commandType)
2324
where TSelf : class, ICommandFactory<TSelf>
2425
where TEnum : Enum
2526
{
26-
return TSelf.Create(Guid.CreateVersion7(), commandType.ToString());
27+
return TSelf.Create(GuidHelper.CreateVersion7(), commandType.ToString());
2728
}
2829

2930
public static TSelf Create<TSelf, TEnum>(Guid commandId, TEnum commandType)
@@ -68,7 +69,7 @@ internal static class CommandValueFactoryBridge
6869
public static TSelf Create<TSelf, TValue>(TValue value)
6970
where TSelf : class, ICommandValueFactory<TSelf, TValue>
7071
{
71-
return TSelf.Create(Guid.CreateVersion7(), ResolveCommandType(value), value);
72+
return TSelf.Create(GuidHelper.CreateVersion7(), ResolveCommandType(value), value);
7273
}
7374

7475
public static TSelf Create<TSelf, TValue>(Guid commandId, TValue value)

ManagedCode.Communication/Commands/Factories/ICommandFactory.Defaults.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using ManagedCode.Communication.Helpers;
23

34
namespace ManagedCode.Communication.Commands;
45

@@ -12,13 +13,13 @@ static virtual TSelf Create(string commandType)
1213
throw new ArgumentException("Command type must be provided.", nameof(commandType));
1314
}
1415

15-
return TSelf.Create(Guid.CreateVersion7(), commandType);
16+
return TSelf.Create(GuidHelper.CreateVersion7(), commandType);
1617
}
1718

1819
static virtual TSelf Create<TEnum>(TEnum commandType)
1920
where TEnum : Enum
2021
{
21-
return TSelf.Create(Guid.CreateVersion7(), commandType.ToString());
22+
return TSelf.Create(GuidHelper.CreateVersion7(), commandType.ToString());
2223
}
2324

2425
static virtual TSelf Create<TEnum>(Guid commandId, TEnum commandType)

ManagedCode.Communication/Commands/Factories/ICommandValueFactory.Defaults.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using ManagedCode.Communication.Helpers;
23

34
namespace ManagedCode.Communication.Commands;
45

@@ -8,7 +9,7 @@ public partial interface ICommandValueFactory<TSelf, TValue>
89
static virtual TSelf Create(TValue value)
910
{
1011
var commandType = ResolveCommandType(value);
11-
return TSelf.Create(Guid.CreateVersion7(), commandType, value);
12+
return TSelf.Create(GuidHelper.CreateVersion7(), commandType, value);
1213
}
1314

1415
static virtual TSelf Create(Guid commandId, TValue value)

ManagedCode.Communication/Commands/PaginationCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Text.Json.Serialization;
3+
using ManagedCode.Communication.Helpers;
34

45
namespace ManagedCode.Communication.Commands;
56

@@ -73,7 +74,7 @@ public static PaginationCommand Create(PaginationRequest request, PaginationOpti
7374
{
7475
ArgumentNullException.ThrowIfNull(request);
7576
var normalized = request.Normalize(options);
76-
return Create(Guid.CreateVersion7(), DefaultCommandType, normalized, options);
77+
return Create(GuidHelper.CreateVersion7(), DefaultCommandType, normalized, options);
7778
}
7879

7980
/// <summary>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace ManagedCode.Communication.Helpers;
4+
5+
internal static class GuidHelper
6+
{
7+
/// <summary>
8+
/// Creates a version 7 GUID (monotonic, sortable) if available,
9+
/// otherwise falls back to a sequential GUID for .NET 8.
10+
/// </summary>
11+
public static Guid CreateVersion7()
12+
{
13+
#if NET9_0_OR_GREATER
14+
return Guid.CreateVersion7();
15+
#else
16+
// For .NET 8, use NewGuid() as a fallback
17+
// In production, you might want to use a proper UUID v7 implementation
18+
// or a library like System.Guid.NewSequentialGuid() if available
19+
return Guid.NewGuid();
20+
#endif
21+
}
22+
}

0 commit comments

Comments
 (0)