Skip to content

Commit

Permalink
.NET 9 + XUnit 3 (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShortDevelopment authored Jan 27, 2025
1 parent 78879be commit 31c016f
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'

- name: Install Workloads
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
include-prerelease: true

- name: Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private AuthenticationPayload() { }
public static AuthenticationPayload Parse(ref EndianReader reader)
=> new()
{
Certificate = new(reader.ReadBytesWithLength().ToArray()),
Certificate = X509CertificateLoader.LoadCertificate(reader.ReadBytesWithLength()),
SignedThumbprint = reader.ReadBytesWithLength().ToArray()
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<Version>0.1.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
2 changes: 1 addition & 1 deletion src/NearShare.Android.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-android34.0</TargetFramework>
<TargetFramework>net9.0-android35.0</TargetFramework>
<OutputType>Exe</OutputType>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<ApplicationId>de.shortdev.nearby_sharing_windows</ApplicationId>
Expand Down
21 changes: 11 additions & 10 deletions tests/ShortDev.Microsoft.ConnectedDevices.Test/E2E/End2EndTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using ShortDev.Microsoft.ConnectedDevices.Transports.Bluetooth;
using ShortDev.Microsoft.ConnectedDevices.Transports.Network;
using System.Net;
using Xunit.Abstractions;

namespace ShortDev.Microsoft.ConnectedDevices.Test.E2E;

Expand Down Expand Up @@ -54,14 +53,14 @@ public async Task TransferUri(bool useTcp1, bool useTcp2)
if (useTcp1)
UseTcp(device1, tcpPort: 5041, udpPort: 5051);

device1.Discover(cancellationToken: default);
device1.Discover(TestContext.Current.CancellationToken);

using var device2 = CreateDevice(network, "Device 2", "81-7A-80-8F-D5-80");
if (useTcp2)
UseTcp(device2, tcpPort: 5041, udpPort: 5051);

device2.Advertise(cancellationToken: default);
device2.Listen(cancellationToken: default);
device2.Advertise(TestContext.Current.CancellationToken);
device2.Listen(TestContext.Current.CancellationToken);

TaskCompletionSource<UriTransferToken> receivePromise = new();
NearShareReceiver.ReceivedUri += receivePromise.SetResult;
Expand All @@ -73,7 +72,8 @@ public async Task TransferUri(bool useTcp1, bool useTcp2)
await sender.SendUriAsync(
device: new("Device 2", DeviceType.Linux, Endpoint:
new(Transports.CdpTransportType.Rfcomm, "81-7A-80-8F-D5-80", "ServiceId")
), new Uri("https://nearshare.shortdev.de/")
), new Uri("https://nearshare.shortdev.de/"),
TestContext.Current.CancellationToken
);

var token = await receivePromise.Task;
Expand All @@ -99,14 +99,14 @@ public async Task TransferFile(bool useTcp1, bool useTcp2)
if (useTcp1)
UseTcp(device1, tcpPort: 5041, udpPort: 5051);

device1.Discover(cancellationToken: default);
device1.Discover(TestContext.Current.CancellationToken);

using var device2 = CreateDevice(network, "Device 2", "81-7A-80-8F-D5-80");
if (useTcp2)
UseTcp(device2, tcpPort: 5041, udpPort: 5051);

device2.Advertise(cancellationToken: default);
device2.Listen(cancellationToken: default);
device2.Advertise(TestContext.Current.CancellationToken);
device2.Listen(TestContext.Current.CancellationToken);

var buffer = new byte[Random.Shared.Next(1_000, 1_000_000)];
outputHelper.WriteLine($"[Information]: Generated buffer with size {buffer.LongLength}");
Expand All @@ -125,7 +125,8 @@ await sender.SendFileAsync(
new(Transports.CdpTransportType.Rfcomm, "81-7A-80-8F-D5-80", "ServiceId")
),
CdpFileProvider.FromBuffer("TestFile", buffer),
new Progress<NearShareProgress>()
new Progress<NearShareProgress>(),
TestContext.Current.CancellationToken
);

await receivePromise.Task;
Expand All @@ -140,7 +141,7 @@ await sender.SendFileAsync(
void OnFileTransfer(FileTransferToken token)
{
Assert.Equal("Device 1", token.DeviceName);
Assert.Equal(1, token.Files.Count);
Assert.Single(token.Files);
Assert.Equal("TestFile", token.Files[0].Name);
Assert.Equal((ulong)buffer.LongLength, token.Files[0].Size);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using Xunit.Abstractions;

namespace ShortDev.Microsoft.ConnectedDevices.Test.E2E;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using ShortDev.Microsoft.ConnectedDevices.Messages;
using ShortDev.Microsoft.ConnectedDevices.NearShare.Messages;
using ShortDev.Microsoft.ConnectedDevices.Serialization;
using System.Diagnostics;
using Xunit.Abstractions;

namespace ShortDev.Microsoft.ConnectedDevices.Test;

Expand All @@ -16,7 +14,7 @@ static SerializationTest()

private readonly ITestOutputHelper _output = output;

public static IEnumerable<object[]> GenerateMsgTypes()
public static IEnumerable<TheoryDataRow<Type>> GenerateMsgTypes()
{
var assembly = typeof(CommonHeader).Assembly;
foreach (var type in assembly.DefinedTypes)
Expand All @@ -26,7 +24,7 @@ public static IEnumerable<object[]> GenerateMsgTypes()
IsOk(typeof(ICdpPayload<>), type) &&
type.Name != "PresenceResponse"
)
yield return new object[] { type };
yield return type;
}

static bool IsOk(Type TInterface, Type TClass)
Expand Down Expand Up @@ -56,7 +54,7 @@ static void TestRun<T>(Endianness endianness) where T : ICdpSerializable<T>
Type type = typeof(T);

// allocate
var instance = (T)TestValueGenerator.RandomValue(typeof(T));
var instance = TestValueGenerator.RandomValue<T>();

// write - 1st pass
EndianWriter writer = new(endianness);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<IsPackable>false</IsPackable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.12.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\lib\ShortDev.Microsoft.ConnectedDevices.NearShare\ShortDev.Microsoft.ConnectedDevices.NearShare.csproj" />
<ProjectReference Include="..\..\lib\ShortDev.Microsoft.ConnectedDevices\ShortDev.Microsoft.ConnectedDevices.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\lib\ShortDev.Microsoft.ConnectedDevices.NearShare\ShortDev.Microsoft.ConnectedDevices.NearShare.csproj" />
<ProjectReference Include="..\..\lib\ShortDev.Microsoft.ConnectedDevices\ShortDev.Microsoft.ConnectedDevices.csproj" />
</ItemGroup>

</Project>
8 changes: 3 additions & 5 deletions tests/ShortDev.Microsoft.ConnectedDevices.Test/UtilsTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Xunit.Abstractions;

namespace ShortDev.Microsoft.ConnectedDevices.Test;
namespace ShortDev.Microsoft.ConnectedDevices.Test;
public sealed class UtilsTest(ITestOutputHelper output)
{
[Theory]
Expand All @@ -19,7 +17,7 @@ await LongRunningOperationWithThrow(delayMs)
});

// Wait for long-running task to complete
await Task.Delay(delayMs * 2);
await Task.Delay(delayMs * 2, TestContext.Current.CancellationToken);
}

[Theory]
Expand All @@ -38,7 +36,7 @@ await LongRunningOperationWithThrow(delayMs)
});

// Wait for long-running task to complete
await Task.Delay(delayMs * 2);
await Task.Delay(delayMs * 2, TestContext.Current.CancellationToken);
}

static async Task<object> LongRunningOperationWithThrow(int delayMs)
Expand Down

0 comments on commit 31c016f

Please sign in to comment.