Skip to content

Commit 195e8a5

Browse files
committed
Try to fix test
1 parent a06c5a7 commit 195e8a5

4 files changed

Lines changed: 19 additions & 35 deletions

File tree

AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.Async.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public async void InstallPackageAsyncTest()
3737
{
3838
DummySyncService syncService = new();
3939

40-
using FactoriesLocker locker = await FactoriesLocker.WaitAsync();
41-
42-
Factories.SyncServiceFactory = (c, d) => syncService;
43-
4440
DummyAdbClient adbClient = new();
4541

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

55-
PackageManager manager = new(adbClient, device);
51+
PackageManager manager = new(adbClient, device, (c, d) => syncService);
5652
await manager.InstallPackageAsync("Assets/test.txt");
5753

5854
Assert.Equal(3, adbClient.ReceivedCommands.Count);
@@ -129,10 +125,6 @@ public async void InstallMultiplePackageAsyncTest()
129125
{
130126
DummySyncService syncService = new();
131127

132-
using FactoriesLocker locker = await FactoriesLocker.WaitAsync();
133-
134-
Factories.SyncServiceFactory = (c, d) => syncService;
135-
136128
DummyAdbClient adbClient = new();
137129

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

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

157149
Assert.Equal(9, adbClient.ReceivedCommands.Count);
@@ -184,8 +176,6 @@ public async void InstallMultiplePackageAsyncTest()
184176
Assert.Equal(2, syncService.UploadedFiles.Count);
185177
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/gapps.txt"));
186178
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/logcat.bin"));
187-
188-
Factories.Reset();
189179
}
190180

191181
[Fact]

AdvancedSharpAdbClient.Tests/DeviceCommands/PackageManagerTests.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ public void InstallPackageTest()
6565
{
6666
DummySyncService syncService = new();
6767

68-
using FactoriesLocker locker = FactoriesLocker.Wait();
69-
70-
Factories.SyncServiceFactory = (c, d) => syncService;
71-
7268
DummyAdbClient adbClient = new();
7369

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

83-
PackageManager manager = new(adbClient, device);
79+
PackageManager manager = new(adbClient, device, (c, d) => syncService);
8480
manager.InstallPackage("Assets/test.txt");
8581

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

9086
Assert.Single(syncService.UploadedFiles);
9187
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/test.txt"));
92-
93-
Factories.Reset();
9488
}
9589

9690
[Fact]
@@ -157,10 +151,6 @@ public void InstallMultiplePackageTest()
157151
{
158152
DummySyncService syncService = new();
159153

160-
using FactoriesLocker locker = FactoriesLocker.Wait();
161-
162-
Factories.SyncServiceFactory = (c, d) => syncService;
163-
164154
DummyAdbClient adbClient = new();
165155

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

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

185175
Assert.Equal(9, adbClient.ReceivedCommands.Count);
@@ -212,8 +202,6 @@ public void InstallMultiplePackageTest()
212202
Assert.Equal(2, syncService.UploadedFiles.Count);
213203
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/gapps.txt"));
214204
Assert.True(syncService.UploadedFiles.ContainsKey("/data/local/tmp/logcat.bin"));
215-
216-
Factories.Reset();
217205
}
218206

219207
[Fact]

AdvancedSharpAdbClient.Tests/SocketBasedTests.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class SocketBasedTests
1212
{
1313
protected SocketBasedTests(bool integrationTest, bool doDispose)
1414
{
15-
using FactoriesLocker locker = FactoriesLocker.Wait();
15+
Func<EndPoint, IAdbSocket> AdbSocketFactory;
1616

1717
// this.EndPoint = AdbClient.Instance.EndPoint;
1818
#if DEBUG
@@ -21,28 +21,25 @@ protected SocketBasedTests(bool integrationTest, bool doDispose)
2121
if (integrationTest)
2222
{
2323
TracingAdbSocket tracingSocket = new(EndPoint) { DoDispose = doDispose };
24-
25-
Factories.AdbSocketFactory = (endPoint) => tracingSocket;
24+
AdbSocketFactory = (endPoint) => tracingSocket;
2625
}
2726
else
2827
{
2928
DummyAdbSocket socket = new();
30-
Factories.AdbSocketFactory = (endPoint) => socket;
29+
AdbSocketFactory = (endPoint) => socket;
3130
}
3231

3332
IntegrationTest = integrationTest;
3433
#else
3534
// In release mode (e.g. on the build server),
3635
// never run integration tests.
3736
DummyAdbSocket socket = new();
38-
Factories.AdbSocketFactory = (endPoint) => socket;
37+
AdbSocketFactory = (endPoint) => socket;
3938
IntegrationTest = false;
4039
#endif
41-
Socket = (IDummyAdbSocket)Factories.AdbSocketFactory(EndPoint);
42-
43-
TestClient = new AdbClient();
40+
Socket = (IDummyAdbSocket)AdbSocketFactory(EndPoint);
4441

45-
Factories.Reset();
42+
TestClient = new AdbClient(AdbSocketFactory);
4643
}
4744

4845
protected static AdbResponse[] NoResponses { get; } = [];

AdvancedSharpAdbClient/AdbClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ public AdbClient(string host, int port, Func<EndPoint, IAdbSocket> adbSocketFact
112112
{
113113
}
114114

115+
/// <summary>
116+
/// Initializes a new instance of the <see cref="AdbClient"/> class.
117+
/// </summary>
118+
/// <param name="adbSocketFactory">The <see cref="Func{EndPoint, IAdbSocket}"/> to create <see cref="IAdbSocket"/>.</param>
119+
public AdbClient(Func<EndPoint, IAdbSocket> adbSocketFactory)
120+
: this(new IPEndPoint(IPAddress.Loopback, AdbServerPort), adbSocketFactory)
121+
{
122+
}
123+
115124
/// <summary>
116125
/// Get or set default encoding.
117126
/// </summary>

0 commit comments

Comments
 (0)