diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index cd13217f..a52b049a 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -14,7 +14,7 @@ on:
workflow_dispatch:
env:
- DOTNET_VERSION: '9.0.x' # The .NET SDK version to use
+ DOTNET_VERSION: '10.0.x' # The .NET SDK version to use
jobs:
build-and-test:
@@ -45,7 +45,7 @@ jobs:
run: dotnet test --no-restore --blame-hang-timeout 1m -p:FullTargets=false
pack-and-publish:
- name: pack-and-publish
+ if: github.event_name == 'push'
needs: build-and-test
runs-on: windows-latest
env:
diff --git a/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs b/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs
index ba1c14c4..ee238518 100644
--- a/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs
+++ b/AdvancedSharpAdbClient.Tests/AdbClientTests.Async.cs
@@ -935,7 +935,7 @@ await RunTestAsync(
() => TestClient.InstallCommitAsync(Device, "936013062"));
}
-#if WINDOWS10_0_18362_0_OR_GREATER
+#if WINDOWS10_0_17763_0_OR_GREATER
///
/// Tests the method.
///
diff --git a/AdvancedSharpAdbClient.Tests/AdbClientTests.cs b/AdvancedSharpAdbClient.Tests/AdbClientTests.cs
index 4beaef40..c703acac 100644
--- a/AdvancedSharpAdbClient.Tests/AdbClientTests.cs
+++ b/AdvancedSharpAdbClient.Tests/AdbClientTests.cs
@@ -65,6 +65,16 @@ public void FormAdbRequestTest()
Assert.Equal("000Chost:version"u8, AdbClient.FormAdbRequest("host:version"));
}
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void FormAdbRequestSpanTest()
+ {
+ Assert.Equal("0009host:kill"u8, AdbClient.FormAdbRequest("host:kill".AsSpan()));
+ Assert.Equal("000Chost:version"u8, AdbClient.FormAdbRequest("host:version".AsSpan()));
+ }
+
///
/// Tests the method.
///
@@ -75,6 +85,16 @@ public void CreateAdbForwardRequestTest()
Assert.Equal("0012tcp:1981:127.0.0.1"u8, AdbClient.CreateAdbForwardRequest("127.0.0.1", 1981));
}
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void CreateAdbForwardRequestSpanTest()
+ {
+ Assert.Equal("0008tcp:1984"u8, AdbClient.CreateAdbForwardRequest([], 1984));
+ Assert.Equal("0012tcp:1981:127.0.0.1"u8, AdbClient.CreateAdbForwardRequest("127.0.0.1".AsSpan(), 1981));
+ }
+
///
/// Tests the method.
///
@@ -1139,7 +1159,7 @@ public void GetFeatureSetTest()
public void CloneTest()
{
Assert.True(TestClient is ICloneable);
-#if WINDOWS10_0_18362_0_OR_GREATER
+#if WINDOWS10_0_17763_0_OR_GREATER
Assert.True(TestClient is ICloneable);
#endif
AdbClient client = TestClient.Clone();
@@ -1149,6 +1169,16 @@ public void CloneTest()
Assert.Equal(endPoint, client.EndPoint);
}
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void ToStringTest()
+ {
+ AdbClient adbClient = new();
+ Assert.Equal($"The {typeof(AdbClient)} communicate with adb server at '127.0.0.1:5037'.", adbClient.ToString());
+ }
+
private void RunConnectTest(Action test, string connectString)
{
string[] requests = [$"host:connect:{connectString}"];
diff --git a/AdvancedSharpAdbClient.Tests/AdbCommandLineClientTests.cs b/AdvancedSharpAdbClient.Tests/AdbCommandLineClientTests.cs
index 9a589945..f01540e1 100644
--- a/AdvancedSharpAdbClient.Tests/AdbCommandLineClientTests.cs
+++ b/AdvancedSharpAdbClient.Tests/AdbCommandLineClientTests.cs
@@ -64,5 +64,17 @@ public void StartServerTest()
commandLine.StartServer();
Assert.True(commandLine.ServerStarted);
}
+
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void ToStringTest()
+ {
+ DummyAdbCommandLineClient commandLine = new();
+ Assert.Equal($"The {typeof(DummyAdbCommandLineClient)} process with adb command line at '{ServerName}'.", commandLine.ToString());
+ }
+
+ private static string ServerName => OperatingSystem.IsWindows() ? "adb.exe" : "adb";
}
}
diff --git a/AdvancedSharpAdbClient.Tests/AdbServerTests.cs b/AdvancedSharpAdbClient.Tests/AdbServerTests.cs
index de5136fe..249212b9 100644
--- a/AdvancedSharpAdbClient.Tests/AdbServerTests.cs
+++ b/AdvancedSharpAdbClient.Tests/AdbServerTests.cs
@@ -2,7 +2,6 @@
using System;
using System.Net;
using System.Net.Sockets;
-using System.Runtime.InteropServices;
using Xunit;
namespace AdvancedSharpAdbClient.Tests
@@ -262,6 +261,15 @@ public void CloneTest()
Assert.Equal(endPoint, server.EndPoint);
}
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void ToStringTest()
+ {
+ Assert.Equal($"The {typeof(AdbServer)} communicate with adb at '127.0.0.1:5037'.", adbServer.ToString());
+ }
+
///
/// Tests the method.
///
@@ -269,6 +277,6 @@ public void CloneTest()
public void ConstructorAdbClientNullTest() =>
_ = Assert.Throws(() => new AdbServer((EndPoint)null, adbSocketFactory, adbCommandLineClientFactory));
- private static string ServerName => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "adb.exe" : "adb";
+ private static string ServerName => OperatingSystem.IsWindows() ? "adb.exe" : "adb";
}
}
diff --git a/AdvancedSharpAdbClient.Tests/AdbSocketTests.cs b/AdvancedSharpAdbClient.Tests/AdbSocketTests.cs
index 05eecd14..b3067d42 100644
--- a/AdvancedSharpAdbClient.Tests/AdbSocketTests.cs
+++ b/AdvancedSharpAdbClient.Tests/AdbSocketTests.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Runtime.CompilerServices;
using System.Text;
using Xunit;
@@ -266,6 +267,17 @@ public void SendAdbRequestTest() =>
socket => socket.SendAdbRequest("Test"),
"0004Test"u8.ToArray());
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void SendAdbRequestSpanTest()
+ {
+ RunTest(
+ socket => socket.SendAdbRequest((DefaultInterpolatedStringHandler)$"Test"),
+ "0004Test"u8.ToArray());
+ }
+
///
/// Tests the method.
///
@@ -297,6 +309,17 @@ public void CloneTest()
Assert.Equal(adbSocket.Connected, socket.Connected);
}
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void ToStringTest()
+ {
+ using DummyTcpSocket tcpSocket = new();
+ using AdbSocket adbSocket = new(tcpSocket);
+ Assert.Equal($"{typeof(AdbSocket)} {{ {nameof(AdbSocket.Socket)} = {tcpSocket} }}", adbSocket.ToString());
+ }
+
private static void RunTest(Action test, byte[] expectedDataSent)
{
using DummyTcpSocket tcpSocket = new();
diff --git a/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj b/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj
index 286e9bd9..dd742435 100644
--- a/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj
+++ b/AdvancedSharpAdbClient.Tests/AdvancedSharpAdbClient.Tests.csproj
@@ -7,14 +7,14 @@
-
+
- net8.0-windows10.0.17763.0
+ net10.0-windows10.0.17763.0
- net8.0
+ net10.0
@@ -23,10 +23,10 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs
index 23195239..598da93c 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.Async.cs
@@ -105,7 +105,7 @@ public async Task DumpScreenAsyncTest()
Assert.Equal(doc, xml);
}
-#if WINDOWS10_0_18362_0_OR_GREATER
+#if WINDOWS10_0_17763_0_OR_GREATER
///
/// Tests the method.
///
diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs
index 382faf36..23cb8b5d 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceClientTexts.cs
@@ -191,7 +191,7 @@ public void DumpScreenTest()
Assert.Equal(doc, xml);
}
-#if WINDOWS10_0_18362_0_OR_GREATER
+#if WINDOWS10_0_17763_0_OR_GREATER
///
/// Tests the method.
///
diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceExtensionsTests.Async.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceExtensionsTests.Async.cs
index 0851b398..33cfb31f 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceExtensionsTests.Async.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/DeviceExtensionsTests.Async.cs
@@ -1,5 +1,6 @@
using NSubstitute;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -164,7 +165,7 @@ public async Task GetDirectoryAsyncListingTest()
{
Assert.Equal(remotePath, x.ArgAt(0));
Assert.Equal(default, x.ArgAt(1));
- return stats.AsEnumerableAsync(x.ArgAt(1));
+ return stats.ToAsyncEnumerable(x.ArgAt(1));
});
Factories.SyncServiceFactory = (c, d) =>
diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/Models/VersionInfoTests.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/Models/VersionInfoTests.cs
index 8d9da8f1..8197d472 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceCommands/Models/VersionInfoTests.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/Models/VersionInfoTests.cs
@@ -32,7 +32,7 @@ public void TryAsVersionTest(int versionCode, string versionName, bool expected)
}
}
-#if WINDOWS10_0_18362_0_OR_GREATER
+#if WINDOWS10_0_17763_0_OR_GREATER
///
/// Tests the method.
///
diff --git a/AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.cs b/AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.cs
index 1fc000d2..52a9057c 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.cs
@@ -18,7 +18,7 @@ public void ConstructorNullTest()
{
_ = Assert.Throws(() => new PackageManager(null, default));
_ = Assert.Throws(() => new PackageManager(null, new DeviceData { Serial = "169.254.109.177:5555" }));
- _ = Assert.Throws(() => new PackageManager(Substitute.For(), default));
+ _ = Assert.Throws(() => new PackageManager(Substitute.For(), default));
}
[Theory]
@@ -257,6 +257,14 @@ public void GetPackageVersionInfoTest()
Assert.Equal("11.0.62 (448-160311229)", versionInfo.VersionName);
}
+ [Fact]
+ public void ToStringTest()
+ {
+ DummyAdbClient client = new();
+ PackageManager manager = new(client, Device, skipInit: true);
+ Assert.Equal($"{typeof(PackageManager)} {{ {nameof(PackageManager.Device)} = {Device}, {nameof(PackageManager.AdbClient)} = {client} }}", manager.ToString());
+ }
+
private struct InstallProgress(params PackageInstallProgressState[] states) : IProgress
{
private PackageInstallProgressState? state;
diff --git a/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.Async.cs b/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.Async.cs
index cbd021a3..7e7d6462 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.Async.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.Async.cs
@@ -53,6 +53,8 @@ await RunTestAsync(
Assert.Single(sink.ListChangedEvents);
Assert.Single(sink.DisconnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.DisconnectedEvents[0].Device.Serial);
+ Assert.False(sink.DisconnectedEvents[0].IsConnect);
+ Assert.Equal("Device disconnected: 169.254.109.177:5555", sink.DisconnectedEvents[0].ToString());
}
[Fact]
@@ -101,6 +103,8 @@ await RunTestAsync(
Assert.Single(sink.ListChangedEvents);
Assert.Empty(sink.DisconnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
+ Assert.True(sink.ConnectedEvents[0].IsConnect);
+ Assert.Equal("Device connected: 169.254.109.177:5555", sink.ConnectedEvents[0].ToString());
}
///
@@ -126,6 +130,8 @@ await RunTestAsync(
Assert.Equal("169.254.109.177:5555", monitor.Devices[0].Serial);
Assert.Single(sink.ConnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
+ Assert.True(sink.ConnectedEvents[0].IsConnect);
+ Assert.Equal("Device connected: 169.254.109.177:5555", sink.ConnectedEvents[0].ToString());
Assert.Empty(sink.ChangedEvents);
Assert.Single(sink.NotifiedEvents);
Assert.Single(sink.ListChangedEvents);
@@ -180,6 +186,9 @@ await RunTestAsync(
Assert.Single(sink.ListChangedEvents);
Assert.Empty(sink.DisconnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial);
+ Assert.Equal(DeviceState.Offline, sink.ChangedEvents[0].OldState);
+ Assert.Equal(DeviceState.Online, sink.ChangedEvents[0].NewState);
+ Assert.Equal("Device state changed: 169.254.109.177:5555 Offline -> Online", sink.ChangedEvents[0].ToString());
}
[Fact]
diff --git a/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.cs b/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.cs
index c29ee6be..50aae730 100644
--- a/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.cs
+++ b/AdvancedSharpAdbClient.Tests/DeviceMonitorTests.cs
@@ -83,6 +83,8 @@ public void DeviceDisconnectedTest()
Assert.Single(sink.ListChangedEvents);
Assert.Single(sink.DisconnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.DisconnectedEvents[0].Device.Serial);
+ Assert.False(sink.DisconnectedEvents[0].IsConnect);
+ Assert.Equal("Device disconnected: 169.254.109.177:5555", sink.DisconnectedEvents[0].ToString());
}
[Fact]
@@ -131,6 +133,8 @@ public void DeviceConnectedTest()
Assert.Single(sink.ListChangedEvents);
Assert.Empty(sink.DisconnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
+ Assert.True(sink.ConnectedEvents[0].IsConnect);
+ Assert.Equal("Device connected: 169.254.109.177:5555", sink.ConnectedEvents[0].ToString());
}
///
@@ -156,6 +160,8 @@ public void StartInitialDeviceListTest()
Assert.Equal("169.254.109.177:5555", monitor.Devices[0].Serial);
Assert.Single(sink.ConnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.ConnectedEvents[0].Device.Serial);
+ Assert.True(sink.ConnectedEvents[0].IsConnect);
+ Assert.Equal("Device connected: 169.254.109.177:5555", sink.ConnectedEvents[0].ToString());
Assert.Empty(sink.ChangedEvents);
Assert.Single(sink.NotifiedEvents);
Assert.Single(sink.ListChangedEvents);
@@ -210,6 +216,9 @@ public void TriggeredWhenStatusChangedTest()
Assert.Single(sink.ListChangedEvents);
Assert.Empty(sink.DisconnectedEvents);
Assert.Equal("169.254.109.177:5555", sink.ChangedEvents[0].Device.Serial);
+ Assert.Equal(DeviceState.Offline, sink.ChangedEvents[0].OldState);
+ Assert.Equal(DeviceState.Online, sink.ChangedEvents[0].NewState);
+ Assert.Equal("Device state changed: 169.254.109.177:5555 Offline -> Online", sink.ChangedEvents[0].ToString());
}
[Fact]
@@ -295,5 +304,15 @@ public void CloneTest()
using DeviceMonitor monitor = deviceMonitor.Clone();
Assert.NotEqual(deviceMonitor.Socket, monitor.Socket);
}
+
+ ///
+ /// Tests the method.
+ ///
+ [Fact]
+ public void ToStringTest()
+ {
+ using DeviceMonitor deviceMonitor = new(Socket);
+ Assert.Equal($"{typeof(DeviceMonitor)} {{ {nameof(DeviceMonitor.Socket)} = {Socket}, {nameof(DeviceMonitor.IsRunning)} = False }}", deviceMonitor.ToString());
+ }
}
}
diff --git a/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbClient.cs b/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbClient.cs
index 7d7be238..f2b8b31a 100644
--- a/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbClient.cs
+++ b/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbClient.cs
@@ -40,14 +40,15 @@ public IAsyncEnumerable ExecuteRemoteEnumerableAsync(string command, Dev
public void ExecuteServerCommand(string target, string command)
{
- StringBuilder requestBuilder = new();
- if (!StringExtensions.IsNullOrWhiteSpace(target))
+ DefaultInterpolatedStringHandler requestBuilder = new(1, 2);
+ if (!string.IsNullOrWhiteSpace(target))
{
- _ = requestBuilder.Append(target).Append(':');
+ requestBuilder.AppendLiteral(target);
+ requestBuilder.AppendFormatted(':');
}
- _ = requestBuilder.Append(command);
+ requestBuilder.AppendLiteral(command);
- string request = requestBuilder.ToString();
+ string request = requestBuilder.ToStringAndClear();
ReceivedCommands.Add(request);
}
@@ -56,14 +57,15 @@ public void ExecuteServerCommand(string target, string command, IAdbSocket socke
public void ExecuteServerCommand(string target, string command, IShellOutputReceiver receiver, Encoding encoding)
{
- StringBuilder requestBuilder = new();
- if (!StringExtensions.IsNullOrWhiteSpace(target))
+ DefaultInterpolatedStringHandler requestBuilder = new(1, 2);
+ if (!string.IsNullOrWhiteSpace(target))
{
- _ = requestBuilder.Append(target).Append(':');
+ requestBuilder.AppendLiteral(target);
+ requestBuilder.AppendFormatted(':');
}
- _ = requestBuilder.Append(command);
+ requestBuilder.AppendLiteral(command);
- string request = requestBuilder.ToString();
+ string request = requestBuilder.ToStringAndClear();
ReceivedCommands.Add(request);
if (Commands.TryGetValue(request, out string value))
@@ -91,14 +93,15 @@ public void ExecuteServerCommand(string target, string command, IAdbSocket socke
public IEnumerable ExecuteServerEnumerable(string target, string command, Encoding encoding)
{
- StringBuilder requestBuilder = new();
- if (!StringExtensions.IsNullOrWhiteSpace(target))
+ DefaultInterpolatedStringHandler requestBuilder = new(1, 2);
+ if (!string.IsNullOrWhiteSpace(target))
{
- _ = requestBuilder.Append(target).Append(':');
+ requestBuilder.AppendLiteral(target);
+ requestBuilder.AppendFormatted(':');
}
- _ = requestBuilder.Append(command);
+ requestBuilder.AppendLiteral(command);
- string request = requestBuilder.ToString();
+ string request = requestBuilder.ToStringAndClear();
ReceivedCommands.Add(request);
if (Commands.TryGetValue(request, out string value))
@@ -122,14 +125,15 @@ public async Task ExecuteServerCommandAsync(string target, string command, Cance
{
await Task.Yield();
- StringBuilder requestBuilder = new();
- if (!StringExtensions.IsNullOrWhiteSpace(target))
+ DefaultInterpolatedStringHandler requestBuilder = new(1, 2);
+ if (!string.IsNullOrWhiteSpace(target))
{
- _ = requestBuilder.Append(target).Append(':');
+ requestBuilder.AppendLiteral(target);
+ requestBuilder.AppendFormatted(':');
}
- _ = requestBuilder.Append(command);
+ requestBuilder.AppendLiteral(command);
- string request = requestBuilder.ToString();
+ string request = requestBuilder.ToStringAndClear();
ReceivedCommands.Add(request);
}
@@ -138,14 +142,15 @@ public Task ExecuteServerCommandAsync(string target, string command, IAdbSocket
public async Task ExecuteServerCommandAsync(string target, string command, IShellOutputReceiver receiver, Encoding encoding, CancellationToken cancellationToken = default)
{
- StringBuilder requestBuilder = new();
- if (!StringExtensions.IsNullOrWhiteSpace(target))
+ DefaultInterpolatedStringHandler requestBuilder = new(1, 2);
+ if (!string.IsNullOrWhiteSpace(target))
{
- _ = requestBuilder.Append(target).Append(':');
+ requestBuilder.AppendLiteral(target);
+ requestBuilder.AppendFormatted(':');
}
- _ = requestBuilder.Append(command);
+ requestBuilder.AppendLiteral(command);
- string request = requestBuilder.ToString();
+ string request = requestBuilder.ToStringAndClear();
ReceivedCommands.Add(request);
if (Commands.TryGetValue(request, out string value))
@@ -173,14 +178,15 @@ public Task ExecuteServerCommandAsync(string target, string command, IAdbSocket
public async IAsyncEnumerable ExecuteServerEnumerableAsync(string target, string command, Encoding encoding, [EnumeratorCancellation] CancellationToken cancellationToken)
{
- StringBuilder requestBuilder = new();
- if (!StringExtensions.IsNullOrWhiteSpace(target))
+ DefaultInterpolatedStringHandler requestBuilder = new(1, 2);
+ if (!string.IsNullOrWhiteSpace(target))
{
- _ = requestBuilder.Append(target).Append(':');
+ requestBuilder.AppendLiteral(target);
+ requestBuilder.AppendFormatted(':');
}
- _ = requestBuilder.Append(command);
+ requestBuilder.AppendLiteral(command);
- string request = requestBuilder.ToString();
+ string request = requestBuilder.ToStringAndClear();
ReceivedCommands.Add(request);
if (Commands.TryGetValue(request, out string value))
diff --git a/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbCommandLineClient.cs b/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbCommandLineClient.cs
index aef700c2..dde88fae 100644
--- a/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbCommandLineClient.cs
+++ b/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbCommandLineClient.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -28,20 +27,19 @@ protected override int RunProcess(string filename, string command, ICollection RunProcessAsync(string filename, string comma
return RunProcess(filename, command, errorOutput, standardOutput, Timeout.Infinite);
}
- private static string ServerName => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "adb.exe" : "adb";
+ private static string ServerName => OperatingSystem.IsWindows() ? "adb.exe" : "adb";
}
}
diff --git a/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs b/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs
index c54d040b..0a7db301 100644
--- a/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs
+++ b/AdvancedSharpAdbClient.Tests/Dummys/DummyAdbSocket.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Net.Sockets;
+using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
@@ -17,7 +18,7 @@ internal partial class DummyAdbSocket : IDummyAdbSocket, ICloneable and to throw
/// a indicating that the adb server has forcefully closed the connection.
///
- public const string ServerDisconnected = "ServerDisconnected";
+ public const string ServerDisconnected = nameof(ServerDisconnected);
public DummyAdbSocket() => IsConnected = true;
@@ -65,6 +66,8 @@ internal partial class DummyAdbSocket : IDummyAdbSocket, ICloneable Requests.Add(request);
+ public void SendAdbRequest(DefaultInterpolatedStringHandler request) => Requests.Add(request.ToString());
+
public int Read(byte[] data)
{
Span actual = SyncDataReceived.Dequeue();
diff --git a/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLogger.cs b/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLogger.cs
index a6cb3d63..0d588a46 100644
--- a/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLogger.cs
+++ b/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLogger.cs
@@ -5,8 +5,7 @@ namespace AdvancedSharpAdbClient.Logs.Tests
{
internal class DummyLogger(string name) : ILogger
{
- public string Name { get; } = name;
-
+ public string Name => name;
public void Log(LogLevel logLevel, Exception exception, string message, params object[] args)
{
Debug.Write($"{Name} logged: ");
@@ -14,10 +13,9 @@ public void Log(LogLevel logLevel, Exception exception, string message, params o
}
}
- internal class DummyLogger : DummyLogger, ILogger
+ internal class DummyLogger : DummyLogger, ILogger where T : allows ref struct
{
public Type Type { get; } = typeof(T);
-
public DummyLogger() : base(typeof(T).Name) { }
}
diff --git a/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLoggerFactory.cs b/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLoggerFactory.cs
index 97980ccc..1e26f1bd 100644
--- a/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLoggerFactory.cs
+++ b/AdvancedSharpAdbClient.Tests/Dummys/Logs/DummyLoggerFactory.cs
@@ -4,6 +4,6 @@ internal class DummyLoggerFactory : ILoggerFactory
{
public ILogger CreateLogger(string categoryName) => new DummyLogger(categoryName);
- public ILogger CreateLogger() => new DummyLogger();
+ public ILogger CreateLogger() where T : allows ref struct => new DummyLogger();
}
}
diff --git a/AdvancedSharpAdbClient.Tests/Extensions/AdbClientExtensionsTests.Async.cs b/AdvancedSharpAdbClient.Tests/Extensions/AdbClientExtensionsTests.Async.cs
index 7603dcda..2f559540 100644
--- a/AdvancedSharpAdbClient.Tests/Extensions/AdbClientExtensionsTests.Async.cs
+++ b/AdvancedSharpAdbClient.Tests/Extensions/AdbClientExtensionsTests.Async.cs
@@ -51,7 +51,7 @@ public async Task ExecuteServerCommandAsyncTest()
Assert.Equal(command, x.ArgAt(1));
Assert.Equal(encoding, x.ArgAt(2));
Assert.Equal(default, x.ArgAt(3));
- return result.AsEnumerableAsync(x.ArgAt(3));
+ return result.ToAsyncEnumerable(x.ArgAt(3));
});
_ = client.ExecuteServerEnumerableAsync(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any())
.Returns(x =>
@@ -61,7 +61,7 @@ public async Task ExecuteServerCommandAsyncTest()
Assert.Equal(socket, x.ArgAt(2));
Assert.Equal(encoding, x.ArgAt(3));
Assert.Equal(default, x.ArgAt(4));
- return result.AsEnumerableAsync(x.ArgAt(4));
+ return result.ToAsyncEnumerable(x.ArgAt(4));
});
await client.ExecuteServerCommandAsync(target, command, receiver);
@@ -102,7 +102,7 @@ public async Task ExecuteRemoteCommandAsyncTest()
Assert.Equal(device, x.ArgAt(1));
Assert.Equal(encoding, x.ArgAt(2));
Assert.Equal(default, x.ArgAt(3));
- return result.AsEnumerableAsync(x.ArgAt(3));
+ return result.ToAsyncEnumerable(x.ArgAt(3));
});
await client.ExecuteRemoteCommandAsync(command, device, receiver);
diff --git a/AdvancedSharpAdbClient.Tests/Extensions/EnumerableExtensionsTests.cs b/AdvancedSharpAdbClient.Tests/Extensions/EnumerableExtensionsTests.cs
index 94f0b900..d52c4de1 100644
--- a/AdvancedSharpAdbClient.Tests/Extensions/EnumerableExtensionsTests.cs
+++ b/AdvancedSharpAdbClient.Tests/Extensions/EnumerableExtensionsTests.cs
@@ -42,8 +42,8 @@ public void AddRangeTest()
public async Task TaskToArrayTest()
{
int[] array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
- Task> arrayTask = TaskExExtensions.Delay(10).ContinueWith(_ => array.Select(x => x));
- IEnumerable> taskArray = array.Select(x => TaskExExtensions.Delay(x).ContinueWith(_ => x));
+ Task> arrayTask = Task.Delay(10).ContinueWith(_ => array.Select(x => x));
+ IEnumerable> taskArray = array.Select(x => Task.Delay(x).ContinueWith(_ => x));
Assert.Equal(array, await taskArray.ToArrayAsync());
Assert.Equal(array, await arrayTask.ToArrayAsync());
}
diff --git a/AdvancedSharpAdbClient.Tests/Extensions/ExceptionExtensionsTests.cs b/AdvancedSharpAdbClient.Tests/Extensions/ExceptionExtensionsTests.cs
deleted file mode 100644
index 945f62ba..00000000
--- a/AdvancedSharpAdbClient.Tests/Extensions/ExceptionExtensionsTests.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using System;
-using Xunit;
-
-namespace AdvancedSharpAdbClient.Polyfills.Tests
-{
- ///
- /// Tests the class.
- ///
- public class ExceptionExtensionsTests
- {
- [Theory]
- [InlineData(null)]
- [InlineData("")]
- [InlineData("name")]
- public void ThrowIfNullTest(string paramName)
- {
- foreach (object o in new[] { new object(), string.Empty, "argument" })
- {
- ExceptionExtensions.ThrowIfNull(o);
- ExceptionExtensions.ThrowIfNull(o, nameof(paramName));
- }
-
- Assert.Equal(paramName, Assert.Throws(() => ExceptionExtensions.ThrowIfNull(null, paramName)).ParamName);
- }
-
- [Fact]
- public void ThrowIfGreaterThanTest()
- {
- Assert.Equal(1, Assert.Throws(() => ExceptionExtensions.ThrowIfGreaterThan(1, 0)).ActualValue);
- Assert.Equal(1u, Assert.Throws(() => ExceptionExtensions.ThrowIfGreaterThan(1, 0)).ActualValue);
- Assert.Equal(1.000000001, Assert.Throws(() => ExceptionExtensions.ThrowIfGreaterThan(1.000000001, 1)).ActualValue);
- Assert.Equal(1.00001f, Assert.Throws(() => ExceptionExtensions.ThrowIfGreaterThan(1.00001f, 1)).ActualValue);
-
- ExceptionExtensions.ThrowIfGreaterThan(1, 2);
- }
-
- [Fact]
- public static void ThrowIfLessThanTest()
- {
- Assert.Equal(0, Assert.Throws(() => ExceptionExtensions.ThrowIfLessThan(0, 1)).ActualValue);
- Assert.Equal(0u, Assert.Throws(() => ExceptionExtensions.ThrowIfLessThan(0, 1)).ActualValue);
- Assert.Equal(1d, Assert.Throws(() => ExceptionExtensions.ThrowIfLessThan(1, 1.000000001)).ActualValue);
- Assert.Equal(1f, Assert.Throws(() => ExceptionExtensions.ThrowIfLessThan(1, 1.00001f)).ActualValue);
-
- ExceptionExtensions.ThrowIfLessThan(2, 1);
- }
-
- [Fact]
- public static void ThrowIfNegativeTest()
- {
- Assert.Equal(-1d, Assert.Throws(() => ExceptionExtensions.ThrowIfNegative(-1d)).ActualValue);
-
- ExceptionExtensions.ThrowIfNegative(0);
- ExceptionExtensions.ThrowIfNegative(1);
- }
-
- [Fact]
- public static void ThrowIfTest()
- {
- object obj = new();
- ObjectDisposedException ex = Assert.Throws(
- () => ExceptionExtensions.ThrowIf(true, obj));
-
- Assert.Equal("System.Object", ex.ObjectName);
- }
- }
-}
diff --git a/AdvancedSharpAdbClient.Tests/Logs/LogTests.cs b/AdvancedSharpAdbClient.Tests/Logs/LogTests.cs
index a5c67741..8aab49f5 100644
--- a/AdvancedSharpAdbClient.Tests/Logs/LogTests.cs
+++ b/AdvancedSharpAdbClient.Tests/Logs/LogTests.cs
@@ -1,5 +1,7 @@
-using System;
+using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities;
+using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using Xunit;
@@ -32,6 +34,7 @@ public void ReadLogTest()
Assert.Equal(Priority.Info, androidLog.Priority);
Assert.Equal("ActivityManager", androidLog.Tag);
Assert.Equal("Start proc com.google.android.gm for broadcast com.google.android.gm/.widget.GmailWidgetProvider: pid=7026 uid=10066 gids={50066, 9997, 3003, 1028, 1015} abi=x86", androidLog.Message);
+ Assert.Equal($"{log.TimeStamp.LocalDateTime:yy-MM-dd HH:mm:ss.fff} 707 707 I ActivityManager: Start proc com.google.android.gm for broadcast com.google.android.gm/.widget.GmailWidgetProvider: pid=7026 uid=10066 gids={{50066, 9997, 3003, 1028, 1015}} abi=x86", androidLog.ToString());
Assert.NotNull(reader.ReadEntry());
Assert.NotNull(reader.ReadEntry());
@@ -61,6 +64,7 @@ public async Task ReadLogAsyncTest()
Assert.Equal(Priority.Info, androidLog.Priority);
Assert.Equal("ActivityManager", androidLog.Tag);
Assert.Equal("Start proc com.google.android.gm for broadcast com.google.android.gm/.widget.GmailWidgetProvider: pid=7026 uid=10066 gids={50066, 9997, 3003, 1028, 1015} abi=x86", androidLog.Message);
+ Assert.Equal($"{log.TimeStamp.LocalDateTime:yy-MM-dd HH:mm:ss.fff} 707 707 I ActivityManager: Start proc com.google.android.gm for broadcast com.google.android.gm/.widget.GmailWidgetProvider: pid=7026 uid=10066 gids={{50066, 9997, 3003, 1028, 1015}} abi=x86", androidLog.ToString());
Assert.NotNull(await reader.ReadEntryAsync());
Assert.NotNull(await reader.ReadEntryAsync());
@@ -89,6 +93,7 @@ public void ReadEventLogTest()
Assert.Single(eventLog.Values);
Assert.NotNull(eventLog.Values[0]);
Assert.IsType>(eventLog.Values[0]);
+ Assert.Equal($"{entry.TimeStamp.LocalDateTime:yy-MM-dd HH:mm:ss.fff} 707 707 0 : System.Collections.Generic.List`1[System.Object]", eventLog.ToString());
List