22using Cake . Core . Configuration ;
33using Cake . Core . Diagnostics ;
44using Cake . Core . IO ;
5- using VerifyTests . Http ;
65
76namespace ARI . Tests . Extensions ;
87
@@ -14,14 +13,14 @@ public static IServiceCollection AddCakeFakes(
1413 )
1514 {
1615 var configuration = new FakeConfiguration ( ) ;
17-
16+
1817 var environment = FakeEnvironment . CreateUnixEnvironment ( ) ;
19-
18+
2019 var fileSystem = new FakeFileSystem ( environment ) ;
2120 configureFileSystem ? . Invoke ( fileSystem ) ;
2221
2322 var globber = new Globber ( fileSystem , environment ) ;
24-
23+
2524 var log = new FakeLog ( ) ;
2625
2726 var Context = Substitute . For < ICakeContext > ( ) ;
@@ -40,123 +39,4 @@ public static IServiceCollection AddCakeFakes(
4039 . AddSingleton < ICakeRuntime > ( environment . Runtime )
4140 . AddSingleton < ICakeContext > ( Context ) ;
4241 }
43-
44- public static IServiceCollection AddMockHttpClient ( this IServiceCollection services )
45- {
46- static HttpResponseMessage GetMockJsonResponse ( string response )
47- => new ( )
48- {
49- Content = new StringContent (
50- response ,
51- Encoding . UTF8 ,
52- Constants . MediaType . Json
53- )
54- } ;
55-
56- static MockHttpClient CreateClient ( )
57- => new (
58- request => request switch
59- {
60- {
61- Method . Method : Constants . Request . Method . Get ,
62- RequestUri . AbsoluteUri : Constants . Request . Uri . Tenants
63- } => GetMockJsonResponse ( Constants . Response . Json . TenantsServicePrinciple ) ,
64-
65- {
66- Method . Method : Constants . Request . Method . Get ,
67- RequestUri . AbsoluteUri : Constants . Request . Uri . GraphOrg
68- } => GetMockJsonResponse ( Constants . Response . Json . GraphOrg ) ,
69-
70- {
71- Method . Method : Constants . Request . Method . Get ,
72- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscriptions
73- } => GetMockJsonResponse ( Constants . Response . Json . Subscriptions ) ,
74-
75- {
76- Method . Method : Constants . Request . Method . Get ,
77- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroups
78- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroups ) ,
79-
80- {
81- Method . Method : Constants . Request . Method . Get ,
82- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription2 . ResourceGroups
83- } => GetMockJsonResponse ( Constants . Response . Json . Subscription2 . ResourceGroups ) ,
84-
85- {
86- Method . Method : Constants . Request . Method . Get ,
87- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup1 . Resources
88- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup1 . Resources ) ,
89-
90- {
91- Method . Method : Constants . Request . Method . Get ,
92- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup2 . Resources
93- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup2 . Resources ) ,
94-
95- {
96- Method . Method : Constants . Request . Method . Get ,
97- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup3 . Resources
98- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup3 . Resources ) ,
99-
100- {
101- Method . Method : Constants . Request . Method . Get ,
102- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription2 . ResourceGroup1 . Resources
103- } => GetMockJsonResponse ( Constants . Response . Json . Subscription2 . ResourceGroup1 . Resources ) ,
104-
105- {
106- Method . Method : Constants . Request . Method . Get ,
107- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup1 . Site . Config
108- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup1 . Site . Config ) ,
109-
110- {
111- Method . Method : Constants . Request . Method . Get ,
112- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup2 . Site . Config
113- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup2 . Site . Config ) ,
114-
115- {
116- Method . Method : Constants . Request . Method . Get ,
117- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup3 . Site . Config
118- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup3 . Site . Config ) ,
119-
120- {
121- Method . Method : Constants . Request . Method . Post ,
122- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup1 . Site . Settings
123- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup1 . Site . Settings ) ,
124-
125- {
126- Method . Method : Constants . Request . Method . Post ,
127- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup2 . Site . Settings
128- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup2 . Site . Settings ) ,
129-
130- {
131- Method . Method : Constants . Request . Method . Post ,
132- RequestUri . AbsoluteUri : Constants . Request . Uri . Subscription1 . ResourceGroup3 . Site . Settings
133- } => GetMockJsonResponse ( Constants . Response . Json . Subscription1 . ResourceGroup3 . Site . Settings ) ,
134-
135- _ => new HttpResponseMessage
136- {
137- StatusCode = System . Net . HttpStatusCode . NotFound
138- }
139- }
140- ) ;
141-
142- return services
143- . AddSingleton < HttpClient > (
144- _ => CreateClient ( )
145- )
146- . AddSingleton < IHttpClientFactory > (
147- _ =>
148- {
149- var httpClientFactory = Substitute . For < IHttpClientFactory > ( ) ;
150- httpClientFactory
151- . CreateClient ( null ! )
152- . ReturnsForAnyArgs ( _ => CreateClient ( ) ) ;
153-
154- httpClientFactory
155- . CreateClient ( )
156- . Returns ( _ => CreateClient ( ) ) ;
157-
158- return httpClientFactory ;
159- }
160- ) ; ;
161- }
16242}
0 commit comments