Skip to content

Commit b932eb7

Browse files
authored
Merge pull request #129 from SharpAdb/feature/csupdate
Upgrade C# language version to 14.0
2 parents 881898e + 6d19bcc commit b932eb7

File tree

129 files changed

+1986
-1793
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1986
-1793
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
workflow_dispatch:
1515

1616
env:
17-
DOTNET_VERSION: '9.0.x' # The .NET SDK version to use
17+
DOTNET_VERSION: '10.0.x' # The .NET SDK version to use
1818

1919
jobs:
2020
build-and-test:
@@ -45,7 +45,7 @@ jobs:
4545
run: dotnet test --no-restore --blame-hang-timeout 1m -p:FullTargets=false
4646

4747
pack-and-publish:
48-
name: pack-and-publish
48+
if: github.event_name == 'push'
4949
needs: build-and-test
5050
runs-on: windows-latest
5151
env:

AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ await RunTestAsync(
935935
() => TestClient.InstallCommitAsync(Device, "936013062"));
936936
}
937937

938-
#if WINDOWS10_0_18362_0_OR_GREATER
938+
#if WINDOWS10_0_17763_0_OR_GREATER
939939
/// <summary>
940940
/// Tests the <see cref="AdbClient.InstallAsync(DeviceData, IRandomAccessStream, Action{InstallProgressEventArgs}?, CancellationToken, string[])"/> method.
941941
/// </summary>

AdvancedSharpAdbClient.Tests/AdbClientTests.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ public void FormAdbRequestTest()
6565
Assert.Equal("000Chost:version"u8, AdbClient.FormAdbRequest("host:version"));
6666
}
6767

68+
/// <summary>
69+
/// Tests the <see cref="AdbClient.FormAdbRequest(ReadOnlySpan{char})"/> method.
70+
/// </summary>
71+
[Fact]
72+
public void FormAdbRequestSpanTest()
73+
{
74+
Assert.Equal("0009host:kill"u8, AdbClient.FormAdbRequest("host:kill".AsSpan()));
75+
Assert.Equal("000Chost:version"u8, AdbClient.FormAdbRequest("host:version".AsSpan()));
76+
}
77+
6878
/// <summary>
6979
/// Tests the <see cref="AdbClient.CreateAdbForwardRequest(string, int)"/> method.
7080
/// </summary>
@@ -75,6 +85,16 @@ public void CreateAdbForwardRequestTest()
7585
Assert.Equal("0012tcp:1981:127.0.0.1"u8, AdbClient.CreateAdbForwardRequest("127.0.0.1", 1981));
7686
}
7787

88+
/// <summary>
89+
/// Tests the <see cref="AdbClient.CreateAdbForwardRequest(ReadOnlySpan{char}, int)"/> method.
90+
/// </summary>
91+
[Fact]
92+
public void CreateAdbForwardRequestSpanTest()
93+
{
94+
Assert.Equal("0008tcp:1984"u8, AdbClient.CreateAdbForwardRequest([], 1984));
95+
Assert.Equal("0012tcp:1981:127.0.0.1"u8, AdbClient.CreateAdbForwardRequest("127.0.0.1".AsSpan(), 1981));
96+
}
97+
7898
/// <summary>
7999
/// Tests the <see cref="AdbClient.GetAdbVersion"/> method.
80100
/// </summary>
@@ -1139,7 +1159,7 @@ public void GetFeatureSetTest()
11391159
public void CloneTest()
11401160
{
11411161
Assert.True(TestClient is ICloneable<IAdbClient>);
1142-
#if WINDOWS10_0_18362_0_OR_GREATER
1162+
#if WINDOWS10_0_17763_0_OR_GREATER
11431163
Assert.True(TestClient is ICloneable<IAdbClient.IWinRT>);
11441164
#endif
11451165
AdbClient client = TestClient.Clone();
@@ -1149,6 +1169,16 @@ public void CloneTest()
11491169
Assert.Equal(endPoint, client.EndPoint);
11501170
}
11511171

1172+
/// <summary>
1173+
/// Tests the <see cref="AdbClient.ToString()"/> method.
1174+
/// </summary>
1175+
[Fact]
1176+
public void ToStringTest()
1177+
{
1178+
AdbClient adbClient = new();
1179+
Assert.Equal($"The {typeof(AdbClient)} communicate with adb server at '127.0.0.1:5037'.", adbClient.ToString());
1180+
}
1181+
11521182
private void RunConnectTest(Action test, string connectString)
11531183
{
11541184
string[] requests = [$"host:connect:{connectString}"];

AdvancedSharpAdbClient.Tests/AdbCommandLineClientTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,17 @@ public void StartServerTest()
6464
commandLine.StartServer();
6565
Assert.True(commandLine.ServerStarted);
6666
}
67+
68+
/// <summary>
69+
/// Tests the <see cref="AdbCommandLineClient.ToString()"/> method.
70+
/// </summary>
71+
[Fact]
72+
public void ToStringTest()
73+
{
74+
DummyAdbCommandLineClient commandLine = new();
75+
Assert.Equal($"The {typeof(DummyAdbCommandLineClient)} process with adb command line at '{ServerName}'.", commandLine.ToString());
76+
}
77+
78+
private static string ServerName => OperatingSystem.IsWindows() ? "adb.exe" : "adb";
6779
}
6880
}

AdvancedSharpAdbClient.Tests/AdbServerTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System;
33
using System.Net;
44
using System.Net.Sockets;
5-
using System.Runtime.InteropServices;
65
using Xunit;
76

87
namespace AdvancedSharpAdbClient.Tests
@@ -262,13 +261,22 @@ public void CloneTest()
262261
Assert.Equal(endPoint, server.EndPoint);
263262
}
264263

264+
/// <summary>
265+
/// Tests the <see cref="AdbServer.ToString()"/> method.
266+
/// </summary>
267+
[Fact]
268+
public void ToStringTest()
269+
{
270+
Assert.Equal($"The {typeof(AdbServer)} communicate with adb at '127.0.0.1:5037'.", adbServer.ToString());
271+
}
272+
265273
/// <summary>
266274
/// Tests the <see cref="AdbServer(EndPoint, Func{EndPoint, IAdbSocket}, Func{string, IAdbCommandLineClient})"/> method.
267275
/// </summary>
268276
[Fact]
269277
public void ConstructorAdbClientNullTest() =>
270278
_ = Assert.Throws<ArgumentNullException>(() => new AdbServer((EndPoint)null, adbSocketFactory, adbCommandLineClientFactory));
271279

272-
private static string ServerName => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "adb.exe" : "adb";
280+
private static string ServerName => OperatingSystem.IsWindows() ? "adb.exe" : "adb";
273281
}
274282
}

AdvancedSharpAdbClient.Tests/AdbSocketTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Runtime.CompilerServices;
34
using System.Text;
45
using Xunit;
56

@@ -266,6 +267,17 @@ public void SendAdbRequestTest() =>
266267
socket => socket.SendAdbRequest("Test"),
267268
"0004Test"u8.ToArray());
268269

270+
/// <summary>
271+
/// Tests the <see cref="AdbSocket.SendAdbRequest(DefaultInterpolatedStringHandler)"/> method.
272+
/// </summary>
273+
[Fact]
274+
public void SendAdbRequestSpanTest()
275+
{
276+
RunTest(
277+
socket => socket.SendAdbRequest((DefaultInterpolatedStringHandler)$"Test"),
278+
"0004Test"u8.ToArray());
279+
}
280+
269281
/// <summary>
270282
/// Tests the <see cref="AdbSocket.GetShellStream"/> method.
271283
/// </summary>
@@ -297,6 +309,17 @@ public void CloneTest()
297309
Assert.Equal(adbSocket.Connected, socket.Connected);
298310
}
299311

312+
/// <summary>
313+
/// Tests the <see cref="AdbSocket.ToString()"/> method.
314+
/// </summary>
315+
[Fact]
316+
public void ToStringTest()
317+
{
318+
using DummyTcpSocket tcpSocket = new();
319+
using AdbSocket adbSocket = new(tcpSocket);
320+
Assert.Equal($"{typeof(AdbSocket)} {{ {nameof(AdbSocket.Socket)} = {tcpSocket} }}", adbSocket.ToString());
321+
}
322+
300323
private static void RunTest(Action<IAdbSocket> test, byte[] expectedDataSent)
301324
{
302325
using DummyTcpSocket tcpSocket = new();

AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
</PropertyGroup>
88

99
<Choose>
10-
<When Condition="'$(IsWindows)' == 'True' and '$(IsStandard)' != 'True'">
10+
<When Condition="'$(IsWindows)' == 'True'">
1111
<PropertyGroup>
12-
<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
12+
<TargetFramework>net10.0-windows10.0.17763.0</TargetFramework>
1313
</PropertyGroup>
1414
</When>
1515
<Otherwise>
1616
<PropertyGroup>
17-
<TargetFramework>net8.0</TargetFramework>
17+
<TargetFramework>net10.0</TargetFramework>
1818
</PropertyGroup>
1919
</Otherwise>
2020
</Choose>
@@ -23,10 +23,10 @@
2323
<PackageReference Include="coverlet.msbuild" Version="6.0.4" PrivateAssets="all">
2424
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2525
</PackageReference>
26-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
26+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
2727
<PackageReference Include="NSubstitute" Version="5.3.0" />
2828
<PackageReference Include="xunit" Version="2.9.3" />
29-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" PrivateAssets="all">
29+
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" PrivateAssets="all">
3030
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3131
</PackageReference>
3232
</ItemGroup>

AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public async Task DumpScreenAsyncTest()
105105
Assert.Equal(doc, xml);
106106
}
107107

108-
#if WINDOWS10_0_18362_0_OR_GREATER
108+
#if WINDOWS10_0_17763_0_OR_GREATER
109109
/// <summary>
110110
/// Tests the <see cref="DeviceClient.DumpScreenWinRTAsync(CancellationToken)"/> method.
111111
/// </summary>

AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void DumpScreenTest()
191191
Assert.Equal(doc, xml);
192192
}
193193

194-
#if WINDOWS10_0_18362_0_OR_GREATER
194+
#if WINDOWS10_0_17763_0_OR_GREATER
195195
/// <summary>
196196
/// Tests the <see cref="DeviceClient.DumpScreenWinRT()"/> method.
197197
/// </summary>

AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceExtensionsTests.Async.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using NSubstitute;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text;
45
using System.Threading;
56
using System.Threading.Tasks;
@@ -164,7 +165,7 @@ public async Task GetDirectoryAsyncListingTest()
164165
{
165166
Assert.Equal(remotePath, x.ArgAt<string>(0));
166167
Assert.Equal(default, x.ArgAt<CancellationToken>(1));
167-
return stats.AsEnumerableAsync(x.ArgAt<CancellationToken>(1));
168+
return stats.ToAsyncEnumerable(x.ArgAt<CancellationToken>(1));
168169
});
169170

170171
Factories.SyncServiceFactory = (c, d) =>

0 commit comments

Comments
 (0)