@@ -4,9 +4,9 @@ namespace DotNet.Testcontainers.Clients
4
4
using System . Collections . Generic ;
5
5
using System . Globalization ;
6
6
using System . IO ;
7
- using System . Linq ;
8
7
using System . Threading ;
9
8
using System . Threading . Tasks ;
9
+ using Docker . DotNet ;
10
10
using Docker . DotNet . Models ;
11
11
using DotNet . Testcontainers . Configurations ;
12
12
using DotNet . Testcontainers . Containers ;
@@ -24,37 +24,53 @@ public DockerContainerOperations(Guid sessionId, IDockerEndpointAuthenticationCo
24
24
25
25
public async Task < IEnumerable < ContainerListResponse > > GetAllAsync ( CancellationToken ct = default )
26
26
{
27
- return ( await Docker . Containers . ListContainersAsync ( new ContainersListParameters { All = true } , ct )
28
- . ConfigureAwait ( false ) ) . ToArray ( ) ;
27
+ return await Docker . Containers . ListContainersAsync ( new ContainersListParameters { All = true } , ct )
28
+ . ConfigureAwait ( false ) ;
29
+ }
30
+
31
+ public async Task < IEnumerable < ContainerListResponse > > GetAllAsync ( FilterByProperty filters , CancellationToken ct = default )
32
+ {
33
+ return await Docker . Containers . ListContainersAsync ( new ContainersListParameters { All = true , Filters = filters } , ct )
34
+ . ConfigureAwait ( false ) ;
29
35
}
30
36
31
- public Task < ContainerListResponse > ByIdAsync ( string id , CancellationToken ct = default )
37
+ public Task < ContainerInspectResponse > ByIdAsync ( string id , CancellationToken ct = default )
32
38
{
33
39
return ByPropertyAsync ( "id" , id , ct ) ;
34
40
}
35
41
36
- public Task < ContainerListResponse > ByNameAsync ( string name , CancellationToken ct = default )
42
+ public Task < ContainerInspectResponse > ByNameAsync ( string name , CancellationToken ct = default )
37
43
{
38
44
return ByPropertyAsync ( "name" , name , ct ) ;
39
45
}
40
46
41
- public async Task < ContainerListResponse > ByPropertyAsync ( string property , string value , CancellationToken ct = default )
47
+ public async Task < ContainerInspectResponse > ByPropertyAsync ( string property , string value , CancellationToken ct = default )
42
48
{
43
- var filters = new FilterByProperty { { property , value } } ;
44
- return ( await Docker . Containers . ListContainersAsync ( new ContainersListParameters { All = true , Filters = filters } , ct )
45
- . ConfigureAwait ( false ) ) . FirstOrDefault ( ) ;
49
+ try
50
+ {
51
+ return await Docker . Containers . InspectContainerAsync ( value , ct )
52
+ . ConfigureAwait ( false ) ;
53
+ }
54
+ catch ( DockerApiException )
55
+ {
56
+ return null ;
57
+ }
46
58
}
47
59
48
60
public async Task < bool > ExistsWithIdAsync ( string id , CancellationToken ct = default )
49
61
{
50
- return await ByIdAsync ( id , ct )
51
- . ConfigureAwait ( false ) != null ;
62
+ var response = await ByIdAsync ( id , ct )
63
+ . ConfigureAwait ( false ) ;
64
+
65
+ return response != null ;
52
66
}
53
67
54
68
public async Task < bool > ExistsWithNameAsync ( string name , CancellationToken ct = default )
55
69
{
56
- return await ByNameAsync ( name , ct )
57
- . ConfigureAwait ( false ) != null ;
70
+ var response = await ByNameAsync ( name , ct )
71
+ . ConfigureAwait ( false ) ;
72
+
73
+ return response != null ;
58
74
}
59
75
60
76
public async Task < long > GetExitCodeAsync ( string id , CancellationToken ct = default )
@@ -214,10 +230,5 @@ public async Task<string> RunAsync(IContainerConfiguration configuration, Cancel
214
230
_logger . DockerContainerCreated ( createContainerResponse . ID ) ;
215
231
return createContainerResponse . ID ;
216
232
}
217
-
218
- public Task < ContainerInspectResponse > InspectAsync ( string id , CancellationToken ct = default )
219
- {
220
- return Docker . Containers . InspectContainerAsync ( id , ct ) ;
221
- }
222
233
}
223
234
}
0 commit comments