12
12
using Tingle . EventBus ;
13
13
using Tingle . EventBus . Transports . InMemory ;
14
14
using Xunit ;
15
- using Xunit . Abstractions ;
16
15
17
16
namespace Tingle . AzureCleaner . Tests ;
18
17
@@ -25,18 +24,18 @@ await TestAsync(async (harness, client) =>
25
24
{
26
25
// without Authorization header
27
26
var request = new HttpRequestMessage ( HttpMethod . Post , "/webhooks/azure" ) ;
28
- var response = await client . SendAsync ( request ) ;
27
+ var response = await client . SendAsync ( request , TestContext . Current . CancellationToken ) ;
29
28
Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
30
- Assert . Empty ( await response . Content . ReadAsStringAsync ( ) ) ;
31
- Assert . Empty ( await harness . PublishedAsync ( ) ) ; // Ensure no event was published
29
+ Assert . Empty ( await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
30
+ Assert . Empty ( await harness . PublishedAsync ( cancellationToken : TestContext . Current . CancellationToken ) ) ; // Ensure no event was published
32
31
33
32
// with wrong value for Authorization header
34
33
request = new HttpRequestMessage ( HttpMethod . Post , "/webhooks/azure" ) ;
35
34
request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( "vsts:burp-bump5" ) ) ) ;
36
- response = await client . SendAsync ( request ) ;
35
+ response = await client . SendAsync ( request , TestContext . Current . CancellationToken ) ;
37
36
Assert . Equal ( HttpStatusCode . Unauthorized , response . StatusCode ) ;
38
- Assert . Empty ( await response . Content . ReadAsStringAsync ( ) ) ;
39
- Assert . Empty ( await harness . PublishedAsync ( ) ) ; // Ensure no event was published
37
+ Assert . Empty ( await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
38
+ Assert . Empty ( await harness . PublishedAsync ( cancellationToken : TestContext . Current . CancellationToken ) ) ; // Ensure no event was published
40
39
} ) ;
41
40
}
42
41
@@ -47,10 +46,10 @@ await TestAsync(async (harness, client) =>
47
46
{
48
47
var request = new HttpRequestMessage ( HttpMethod . Post , "/webhooks/azure" ) ;
49
48
request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( "vsts:burp-bump" ) ) ) ;
50
- var response = await client . SendAsync ( request ) ;
49
+ var response = await client . SendAsync ( request , TestContext . Current . CancellationToken ) ;
51
50
Assert . Equal ( HttpStatusCode . BadRequest , response . StatusCode ) ;
52
- Assert . Empty ( await response . Content . ReadAsStringAsync ( ) ) ;
53
- Assert . Empty ( await harness . PublishedAsync ( ) ) ; // Ensure no event was published
51
+ Assert . Empty ( await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
52
+ Assert . Empty ( await harness . PublishedAsync ( cancellationToken : TestContext . Current . CancellationToken ) ) ; // Ensure no event was published
54
53
} ) ;
55
54
}
56
55
@@ -62,16 +61,16 @@ await TestAsync(async (harness, client) =>
62
61
var request = new HttpRequestMessage ( HttpMethod . Post , "/webhooks/azure" ) ;
63
62
request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( "vsts:burp-bump" ) ) ) ;
64
63
request . Content = new StringContent ( "{}" , Encoding . UTF8 , "application/json" ) ;
65
- var response = await client . SendAsync ( request ) ;
64
+ var response = await client . SendAsync ( request , TestContext . Current . CancellationToken ) ;
66
65
Assert . Equal ( HttpStatusCode . BadRequest , response . StatusCode ) ;
67
- var body = await response . Content . ReadAsStringAsync ( ) ;
66
+ var body = await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ;
68
67
Assert . Contains ( "\" type\" :\" https://tools.ietf.org/html/rfc9110#section-15.5.1\" " , body ) ;
69
68
Assert . Contains ( "\" title\" :\" One or more validation errors occurred.\" " , body ) ;
70
69
Assert . Contains ( "\" status\" :400" , body ) ;
71
70
Assert . Contains ( "\" SubscriptionId\" :[\" The SubscriptionId field is required.\" ]" , body ) ;
72
71
Assert . Contains ( "\" EventType\" :[\" The EventType field is required.\" ]" , body ) ;
73
72
Assert . Contains ( "\" Resource\" :[\" The Resource field is required.\" ]" , body ) ;
74
- Assert . Empty ( await harness . PublishedAsync ( ) ) ; // Ensure no event was published
73
+ Assert . Empty ( await harness . PublishedAsync ( cancellationToken : TestContext . Current . CancellationToken ) ) ; // Ensure no event was published
75
74
} ) ;
76
75
}
77
76
@@ -84,10 +83,10 @@ await TestAsync(async (harness, client) =>
84
83
var request = new HttpRequestMessage ( HttpMethod . Post , "/webhooks/azure" ) ;
85
84
request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( "vsts:burp-bump" ) ) ) ;
86
85
request . Content = new StreamContent ( stream ) ;
87
- var response = await client . SendAsync ( request ) ;
86
+ var response = await client . SendAsync ( request , TestContext . Current . CancellationToken ) ;
88
87
Assert . Equal ( HttpStatusCode . UnsupportedMediaType , response . StatusCode ) ;
89
- Assert . Empty ( await response . Content . ReadAsStringAsync ( ) ) ;
90
- Assert . Empty ( await harness . PublishedAsync ( ) ) ; // Ensure no event was published
88
+ Assert . Empty ( await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
89
+ Assert . Empty ( await harness . PublishedAsync ( cancellationToken : TestContext . Current . CancellationToken ) ) ; // Ensure no event was published
91
90
} ) ;
92
91
}
93
92
@@ -101,15 +100,15 @@ await TestAsync(async (harness, client) =>
101
100
request . Headers . Authorization = new System . Net . Http . Headers . AuthenticationHeaderValue ( "Basic" , Convert . ToBase64String ( Encoding . ASCII . GetBytes ( "vsts:burp-bump" ) ) ) ;
102
101
request . Content = new StreamContent ( stream ) ;
103
102
request . Content . Headers . ContentType = new System . Net . Http . Headers . MediaTypeHeaderValue ( "application/json" , "utf-8" ) ;
104
- var response = await client . SendAsync ( request ) ;
103
+ var response = await client . SendAsync ( request , TestContext . Current . CancellationToken ) ;
105
104
Assert . Equal ( HttpStatusCode . OK , response . StatusCode ) ;
106
105
107
106
// Ensure event was published
108
- var evt_ctx = Assert . IsType < EventContext < AzdoCleanupEvent > > ( Assert . Single ( await harness . PublishedAsync ( ) ) ) ;
107
+ var evt_ctx = Assert . IsType < EventContext < AzdoCleanupEvent > > ( Assert . Single ( await harness . PublishedAsync ( cancellationToken : TestContext . Current . CancellationToken ) ) ) ;
109
108
Assert . Equal ( 1 , evt_ctx . Event . PullRequestId ) ;
110
109
Assert . Equal ( "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam" , evt_ctx . Event . RemoteUrl ) ;
111
110
Assert . Equal ( "https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c" , evt_ctx . Event . RawProjectUrl ) ;
112
- Assert . Empty ( await response . Content . ReadAsStringAsync ( ) ) ;
111
+ Assert . Empty ( await response . Content . ReadAsStringAsync ( TestContext . Current . CancellationToken ) ) ;
113
112
} ) ;
114
113
}
115
114
@@ -154,7 +153,7 @@ private async Task TestAsync(Func<InMemoryTestHarness, HttpClient, Task> logic)
154
153
155
154
using var scope = server . Services . CreateScope ( ) ;
156
155
var provider = scope . ServiceProvider ;
157
-
156
+
158
157
var client = server . CreateClient ( ) ;
159
158
160
159
var harness = provider . GetRequiredService < InMemoryTestHarness > ( ) ;
0 commit comments