Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET 9 + XUnit 3 #198

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading