1- using BervProject . WebApi . Integration . Test . Fixtures ;
1+ namespace BervProject . WebApi . Integration . Test ;
2+
3+ using Fixtures ;
24using Hangfire ;
35using Microsoft . AspNetCore . Mvc . Testing ;
46
5- namespace BervProject . WebApi . Integration . Test
7+
8+ [ Collection ( "Webapp" ) ]
9+ public class CronControllerTest : IDisposable
610{
7- [ Collection ( "Webapp" ) ]
8- public class CronControllerTest : IDisposable
11+ private readonly WebApplicationFactory < Program > _applicationFactory ;
12+ private readonly List < string > _registeredRecurring = new ( ) ;
13+ public CronControllerTest ( WebAppFixture webAppFixtures )
914 {
10- private readonly WebApplicationFactory < Program > _applicationFactory ;
11- private readonly List < string > _registeredRecurring = new List < string > ( ) ;
12- public CronControllerTest ( WebAppFixture webAppFixtures )
13- {
14- this . _applicationFactory = webAppFixtures . WebApp ;
15- }
15+ _applicationFactory = webAppFixtures . WebApp ;
16+ }
1617
17- public void Dispose ( )
18- {
19- RemoveRecurringJob ( ) ;
20- }
18+ public void Dispose ( )
19+ {
20+ RemoveRecurringJob ( ) ;
21+ }
2122
22- private void RemoveRecurringJob ( )
23+ private void RemoveRecurringJob ( )
24+ {
25+ var cronClient = ( IRecurringJobManager ? ) this . _applicationFactory . Services . GetService ( typeof ( IRecurringJobManager ) ) ;
26+ if ( cronClient != null )
2327 {
24- var cronClient = ( IRecurringJobManager ? ) this . _applicationFactory . Services . GetService ( typeof ( IRecurringJobManager ) ) ;
25- if ( cronClient != null )
28+ foreach ( var cronId in _registeredRecurring )
2629 {
27- foreach ( var cronId in _registeredRecurring )
28- {
29- cronClient . RemoveIfExists ( cronId ) ;
30- }
30+ cronClient . RemoveIfExists ( cronId ) ;
3131 }
3232 }
33+ }
3334
34- [ Fact ]
35- public async Task SuccessCreateCronOnceTest ( )
35+ [ Fact ]
36+ public async Task SuccessCreateCronOnceTest ( )
37+ {
38+ var client = _applicationFactory . CreateClient ( ) ;
39+ var response = await client . PostAsync ( "/api/v1.0/cron/CreateCronOnce" , null ) ;
40+ Assert . True ( response . IsSuccessStatusCode ) ;
41+ var stringResponse = await response . Content . ReadAsStringAsync ( ) ;
42+ Assert . NotEmpty ( stringResponse ) ;
43+ var cronClient = ( IBackgroundJobClient ? ) this . _applicationFactory . Services . GetService ( typeof ( IBackgroundJobClient ) ) ;
44+ if ( cronClient != null )
3645 {
37- var client = _applicationFactory . CreateClient ( ) ;
38- var response = await client . PostAsync ( "/api/v1.0/cron/CreateCronOnce" , null ) ;
39- Assert . True ( response . IsSuccessStatusCode ) ;
40- var stringResponse = await response . Content . ReadAsStringAsync ( ) ;
41- Assert . NotEmpty ( stringResponse ) ;
42- var cronClient = ( IBackgroundJobClient ? ) this . _applicationFactory . Services . GetService ( typeof ( IBackgroundJobClient ) ) ;
43- if ( cronClient != null )
44- {
45- var deleted = cronClient . Delete ( stringResponse ) ;
46- Assert . True ( deleted ) ;
47- }
46+ var deleted = cronClient . Delete ( stringResponse ) ;
47+ Assert . True ( deleted ) ;
4848 }
49+ }
4950
50- [ Fact ]
51- public async Task SuccessCreateRecuranceTest ( )
52- {
53- var client = _applicationFactory . CreateClient ( ) ;
54- var response = await client . PostAsync ( "/api/v1.0/cron/CreateRecurance" , null ) ;
55- Assert . True ( response . IsSuccessStatusCode ) ;
56- var stringResponse = await response . Content . ReadAsStringAsync ( ) ;
57- Assert . NotEmpty ( stringResponse ) ;
58- _registeredRecurring . Add ( stringResponse ) ;
59- }
51+ [ Fact ]
52+ public async Task SuccessCreateRecuranceTest ( )
53+ {
54+ var client = _applicationFactory . CreateClient ( ) ;
55+ var response = await client . PostAsync ( "/api/v1.0/cron/CreateRecurance" , null ) ;
56+ Assert . True ( response . IsSuccessStatusCode ) ;
57+ var stringResponse = await response . Content . ReadAsStringAsync ( ) ;
58+ Assert . NotEmpty ( stringResponse ) ;
59+ _registeredRecurring . Add ( stringResponse ) ;
6060 }
6161}
0 commit comments