4
4
// ------------------------------------------------------------
5
5
6
6
using System ;
7
- using System . Collections . Concurrent ;
8
- using System . Net . Http ;
9
7
using System . Threading ;
10
8
using System . Threading . Tasks ;
11
9
using Dapr . Actors . Client ;
@@ -16,107 +14,96 @@ namespace Dapr.Actors.Test
16
14
{
17
15
public class ApiTokenTests
18
16
{
19
- [ Fact ( Skip = "Failing due to #573" ) ]
20
- public void CreateProxyWithRemoting_WithApiToken ( )
17
+ [ Fact ]
18
+ public async Task CreateProxyWithRemoting_WithApiToken ( )
21
19
{
20
+ await using var client = TestClient . CreateForMessageHandler ( ) ;
21
+
22
22
var actorId = new ActorId ( "abc" ) ;
23
- var handler = new TestHttpClientHandler ( ) ;
24
23
var options = new ActorProxyOptions
25
24
{
26
25
DaprApiToken = "test_token" ,
27
26
} ;
28
- var factory = new ActorProxyFactory ( options , handler ) ;
29
- var proxy = factory . CreateActorProxy < ITestActor > ( actorId , "TestActor" ) ;
30
- var task = proxy . SetCountAsync ( 1 , new CancellationToken ( ) ) ;
31
27
32
- handler . Requests . TryDequeue ( out var entry ) . Should ( ) . BeTrue ( ) ;
33
- var headerValues = entry . Request . Headers . GetValues ( "dapr-api-token" ) ;
28
+ var request = await client . CaptureHttpRequestAsync ( async handler =>
29
+ {
30
+ var factory = new ActorProxyFactory ( options , handler ) ;
31
+ var proxy = factory . CreateActorProxy < ITestActor > ( actorId , "TestActor" ) ;
32
+ await proxy . SetCountAsync ( 1 , new CancellationToken ( ) ) ;
33
+ } ) ;
34
+
35
+ request . Dismiss ( ) ;
36
+
37
+ var headerValues = request . Request . Headers . GetValues ( "dapr-api-token" ) ;
34
38
headerValues . Should ( ) . Contain ( "test_token" ) ;
35
39
}
36
40
37
- [ Fact ( Skip = "Failing due to #573" ) ]
38
- public void CreateProxyWithRemoting_WithNoApiToken ( )
41
+ [ Fact ]
42
+ public async Task CreateProxyWithRemoting_WithNoApiToken ( )
39
43
{
44
+ await using var client = TestClient . CreateForMessageHandler ( ) ;
45
+
40
46
var actorId = new ActorId ( "abc" ) ;
41
- var handler = new TestHttpClientHandler ( ) ;
42
- var factory = new ActorProxyFactory ( null , handler ) ;
43
- var proxy = factory . CreateActorProxy < ITestActor > ( actorId , "TestActor" ) ;
44
- var task = proxy . SetCountAsync ( 1 , new CancellationToken ( ) ) ;
45
-
46
- handler . Requests . TryDequeue ( out var entry ) . Should ( ) . BeTrue ( ) ;
47
- Action action = ( ) => entry . Request . Headers . GetValues ( "dapr-api-token" ) ;
48
- action . Should ( ) . Throw < InvalidOperationException > ( ) ;
47
+
48
+ var request = await client . CaptureHttpRequestAsync ( async handler =>
49
+ {
50
+ var factory = new ActorProxyFactory ( null , handler ) ;
51
+ var proxy = factory . CreateActorProxy < ITestActor > ( actorId , "TestActor" ) ;
52
+ await proxy . SetCountAsync ( 1 , new CancellationToken ( ) ) ;
53
+ } ) ;
54
+
55
+ request . Dismiss ( ) ;
56
+
57
+ Assert . Throws < InvalidOperationException > ( ( ) =>
58
+ {
59
+ request . Request . Headers . GetValues ( "dapr-api-token" ) ;
60
+ } ) ;
49
61
}
50
62
51
- [ Fact ( Skip = "Failing due to #573" ) ]
52
- public void CreateProxyWithNoRemoting_WithApiToken ( )
63
+ [ Fact ]
64
+ public async Task CreateProxyWithNoRemoting_WithApiToken ( )
53
65
{
66
+ await using var client = TestClient . CreateForMessageHandler ( ) ;
67
+
54
68
var actorId = new ActorId ( "abc" ) ;
55
- var handler = new TestHttpClientHandler ( ) ;
56
69
var options = new ActorProxyOptions
57
70
{
58
71
DaprApiToken = "test_token" ,
59
72
} ;
60
- var factory = new ActorProxyFactory ( options , handler ) ;
61
- var proxy = factory . Create ( actorId , "TestActor" ) ;
62
- var task = proxy . InvokeMethodAsync ( "SetCountAsync" , 1 , new CancellationToken ( ) ) ;
63
-
64
- handler . Requests . TryDequeue ( out var entry ) . Should ( ) . BeTrue ( ) ;
65
- var headerValues = entry . Request . Headers . GetValues ( "dapr-api-token" ) ;
66
- headerValues . Should ( ) . Contain ( "test_token" ) ;
67
- }
68
73
69
- [ Fact ( Skip = "Failing due to #573" ) ]
70
- public void CreateProxyWithNoRemoting_WithNoApiToken ( )
71
- {
72
- var actorId = new ActorId ( "abc" ) ;
73
- var handler = new TestHttpClientHandler ( ) ;
74
- var factory = new ActorProxyFactory ( null , handler ) ;
75
- var proxy = factory . Create ( actorId , "TestActor" ) ;
76
- var task = proxy . InvokeMethodAsync ( "SetCountAsync" , 1 , new CancellationToken ( ) ) ;
77
-
78
- handler . Requests . TryDequeue ( out var entry ) . Should ( ) . BeTrue ( ) ;
79
- Action action = ( ) => entry . Request . Headers . GetValues ( "dapr-api-token" ) ;
80
- action . Should ( ) . Throw < InvalidOperationException > ( ) ;
81
- }
82
-
83
-
84
- public class Entry
85
- {
86
- public Entry ( HttpRequestMessage request )
74
+ var request = await client . CaptureHttpRequestAsync ( async handler =>
87
75
{
88
- this . Request = request ;
76
+ var factory = new ActorProxyFactory ( options , handler ) ;
77
+ var proxy = factory . Create ( actorId , "TestActor" ) ;
78
+ await proxy . InvokeMethodAsync ( "SetCountAsync" , 1 , new CancellationToken ( ) ) ;
79
+ } ) ;
89
80
90
- this . Completion = new TaskCompletionSource < HttpResponseMessage > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
91
- }
81
+ request . Dismiss ( ) ;
92
82
93
- public TaskCompletionSource < HttpResponseMessage > Completion { get ; }
94
-
95
- public HttpRequestMessage Request { get ; }
83
+ var headerValues = request . Request . Headers . GetValues ( "dapr-api-token" ) ;
84
+ headerValues . Should ( ) . Contain ( "test_token" ) ;
96
85
}
97
86
98
- private class TestHttpClientHandler : HttpClientHandler
87
+ [ Fact ]
88
+ public async Task CreateProxyWithNoRemoting_WithNoApiToken ( )
99
89
{
100
- public TestHttpClientHandler ( )
101
- {
102
- this . Requests = new ConcurrentQueue < Entry > ( ) ;
103
- }
90
+ await using var client = TestClient . CreateForMessageHandler ( ) ;
104
91
105
- public ConcurrentQueue < Entry > Requests { get ; }
92
+ var actorId = new ActorId ( "abc" ) ;
93
+
94
+ var request = await client . CaptureHttpRequestAsync ( async handler =>
95
+ {
96
+ var factory = new ActorProxyFactory ( null , handler ) ;
97
+ var proxy = factory . Create ( actorId , "TestActor" ) ;
98
+ await proxy . InvokeMethodAsync ( "SetCountAsync" , 1 , new CancellationToken ( ) ) ;
99
+ } ) ;
106
100
107
- public Action < Entry > Handler { get ; set ; }
101
+ request . Dismiss ( ) ;
108
102
109
- protected override async Task < HttpResponseMessage > SendAsync ( HttpRequestMessage request , CancellationToken cancellationToken )
103
+ Assert . Throws < InvalidOperationException > ( ( ) =>
110
104
{
111
- var entry = new Entry ( request ) ;
112
- this . Handler ? . Invoke ( entry ) ;
113
- this . Requests . Enqueue ( entry ) ;
114
-
115
- using ( cancellationToken . Register ( ( ) => entry . Completion . TrySetCanceled ( ) ) )
116
- {
117
- return await entry . Completion . Task . ConfigureAwait ( false ) ;
118
- }
119
- }
105
+ request . Request . Headers . GetValues ( "dapr-api-token" ) ;
106
+ } ) ;
120
107
}
121
108
}
122
109
}
0 commit comments