Skip to content

Commit

Permalink
Try to fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Oct 31, 2023
1 parent a06c5a7 commit 195e8a5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public async void InstallPackageAsyncTest()
{
DummySyncService syncService = new();

using FactoriesLocker locker = await FactoriesLocker.WaitAsync();

Factories.SyncServiceFactory = (c, d) => syncService;

DummyAdbClient adbClient = new();

adbClient.Commands["shell:pm list packages -f"] = "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d";
Expand All @@ -52,7 +48,7 @@ public async void InstallPackageAsyncTest()
State = DeviceState.Online
};

PackageManager manager = new(adbClient, device);
PackageManager manager = new(adbClient, device, (c, d) => syncService);
await manager.InstallPackageAsync("Assets/test.txt");

Assert.Equal(3, adbClient.ReceivedCommands.Count);
Expand Down Expand Up @@ -129,10 +125,6 @@ public async void InstallMultiplePackageAsyncTest()
{
DummySyncService syncService = new();

using FactoriesLocker locker = await FactoriesLocker.WaitAsync();

Factories.SyncServiceFactory = (c, d) => syncService;

DummyAdbClient adbClient = new();

adbClient.Commands["shell:pm list packages -f"] = "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d";
Expand All @@ -151,7 +143,7 @@ public async void InstallMultiplePackageAsyncTest()
State = DeviceState.Online
};

PackageManager manager = new(adbClient, device);
PackageManager manager = new(adbClient, device, (c, d) => syncService);
await manager.InstallMultiplePackageAsync("Assets/test.txt", ["Assets/gapps.txt", "Assets/logcat.bin"]);

Assert.Equal(9, adbClient.ReceivedCommands.Count);
Expand Down Expand Up @@ -184,8 +176,6 @@ public async void InstallMultiplePackageAsyncTest()
Assert.Equal(2, syncService.UploadedFiles.Count);
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/gapps.txt"));
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/logcat.bin"));

Factories.Reset();
}

[Fact]
Expand Down
16 changes: 2 additions & 14 deletions AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public void InstallPackageTest()
{
DummySyncService syncService = new();

using FactoriesLocker locker = FactoriesLocker.Wait();

Factories.SyncServiceFactory = (c, d) => syncService;

DummyAdbClient adbClient = new();

adbClient.Commands["shell:pm list packages -f"] = "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d";
Expand All @@ -80,7 +76,7 @@ public void InstallPackageTest()
State = DeviceState.Online
};

PackageManager manager = new(adbClient, device);
PackageManager manager = new(adbClient, device, (c, d) => syncService);
manager.InstallPackage("Assets/test.txt");

Assert.Equal(3, adbClient.ReceivedCommands.Count);
Expand All @@ -89,8 +85,6 @@ public void InstallPackageTest()

Assert.Single(syncService.UploadedFiles);
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/test.txt"));

Factories.Reset();
}

[Fact]
Expand Down Expand Up @@ -157,10 +151,6 @@ public void InstallMultiplePackageTest()
{
DummySyncService syncService = new();

using FactoriesLocker locker = FactoriesLocker.Wait();

Factories.SyncServiceFactory = (c, d) => syncService;

DummyAdbClient adbClient = new();

adbClient.Commands["shell:pm list packages -f"] = "package:/system/app/Gallery2/Gallery2.apk=com.android.gallery3d";
Expand All @@ -179,7 +169,7 @@ public void InstallMultiplePackageTest()
State = DeviceState.Online
};

PackageManager manager = new(adbClient, device);
PackageManager manager = new(adbClient, device, (c, d) => syncService);
manager.InstallMultiplePackage("Assets/test.txt", ["Assets/gapps.txt", "Assets/logcat.bin"]);

Assert.Equal(9, adbClient.ReceivedCommands.Count);
Expand Down Expand Up @@ -212,8 +202,6 @@ public void InstallMultiplePackageTest()
Assert.Equal(2, syncService.UploadedFiles.Count);
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/gapps.txt"));
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/logcat.bin"));

Factories.Reset();
}

[Fact]
Expand Down
15 changes: 6 additions & 9 deletions AdvancedSharpAdbClient.Tests/SocketBasedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class SocketBasedTests
{
protected SocketBasedTests(bool integrationTest, bool doDispose)
{
using FactoriesLocker locker = FactoriesLocker.Wait();
Func<EndPoint, IAdbSocket> AdbSocketFactory;

// this.EndPoint = AdbClient.Instance.EndPoint;
#if DEBUG
Expand All @@ -21,28 +21,25 @@ protected SocketBasedTests(bool integrationTest, bool doDispose)
if (integrationTest)
{
TracingAdbSocket tracingSocket = new(EndPoint) { DoDispose = doDispose };

Factories.AdbSocketFactory = (endPoint) => tracingSocket;
AdbSocketFactory = (endPoint) => tracingSocket;
}
else
{
DummyAdbSocket socket = new();
Factories.AdbSocketFactory = (endPoint) => socket;
AdbSocketFactory = (endPoint) => socket;
}

IntegrationTest = integrationTest;
#else
// In release mode (e.g. on the build server),
// never run integration tests.
DummyAdbSocket socket = new();
Factories.AdbSocketFactory = (endPoint) => socket;
AdbSocketFactory = (endPoint) => socket;
IntegrationTest = false;
#endif
Socket = (IDummyAdbSocket)Factories.AdbSocketFactory(EndPoint);

TestClient = new AdbClient();
Socket = (IDummyAdbSocket)AdbSocketFactory(EndPoint);

Factories.Reset();
TestClient = new AdbClient(AdbSocketFactory);
}

protected static AdbResponse[] NoResponses { get; } = [];
Expand Down
9 changes: 9 additions & 0 deletions AdvancedSharpAdbClient/AdbClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ public AdbClient(string host, int port, Func<EndPoint, IAdbSocket> adbSocketFact
{
}

/// <summary>
/// Initializes a new instance of the <see cref="AdbClient"/> class.
/// </summary>
/// <param name="adbSocketFactory">The <see cref="Func{EndPoint, IAdbSocket}"/> to create <see cref="IAdbSocket"/>.</param>
public AdbClient(Func<EndPoint, IAdbSocket> adbSocketFactory)
: this(new IPEndPoint(IPAddress.Loopback, AdbServerPort), adbSocketFactory)
{
}

/// <summary>
/// Get or set default encoding.
/// </summary>
Expand Down

0 comments on commit 195e8a5

Please sign in to comment.