@@ -175,7 +175,7 @@ public async Task GenerateProductsTemplates_GeneratesTemplatesCorrectly_GivenApi
175175 ) ;
176176
177177 //default values
178- var mockedGroupsClient = MockGroupsClient . GetMockedApiClientWithEmptyValues ( ) ;
178+ var mockedGroupsClient = MockGroupsClient . GetMockedApiClientWithDefaultValues ( ) ;
179179 var mockedTagClient = MockTagClient . GetMockedApiClientWithEmptytValues ( ) ;
180180
181181 var mockedPolicyClient = MockPolicyClient . GetMockedApiClientWithEmptyValues ( ) ;
@@ -212,6 +212,68 @@ public async Task GenerateProductsTemplates_GeneratesTemplatesCorrectly_GivenApi
212212 productResources . Count . Should ( ) . Be ( 2 ) ;
213213 productResources . Any ( x => x . OriginalName == "unlimited" ) . Should ( ) . BeTrue ( ) ;
214214 productResources . Any ( x => x . OriginalName == "starter" ) . Should ( ) . BeTrue ( ) ;
215+
216+ var attachedGroups = templateResources . Where ( x => x . Type == ResourceTypeConstants . ProductGroup ) . ToList ( ) ;
217+ attachedGroups . Count . Should ( ) . Be ( 4 ) ;
218+ }
219+
220+ [ Fact ]
221+ public async Task GenerateProductsTemplates_GeneratesTemplatesCorrectly_GivenConsumptionSku ( )
222+ {
223+ // arrange
224+ var currentTestDirectory = Path . Combine ( this . OutputDirectory , nameof ( GenerateProductsTemplates_GeneratesTemplatesCorrectly_GivenConsumptionSku ) ) ;
225+ var extractorConfig = this . GetDefaultExtractorConsoleAppConfiguration (
226+ apiName : null
227+ ) ;
228+ var extractorParameters = new ExtractorParameters ( extractorConfig ) ;
229+ extractorParameters . SetSkuType ( SKUTypes . Consumption ) ;
230+
231+ var getAlldProductsResponseFileLocation = Path . Combine ( MockClientUtils . ApiClientJsonResponsesPath , "ApiManagementListProducts_success_response.json" ) ;
232+ var mockedProductsClient = await MockProductsClient . GetMockedHttpProductClient (
233+ new MockClientConfiguration ( responseFileLocation : getAlldProductsResponseFileLocation , urlPath : $ "{ MockSourceApimName } /products?api-version={ GlobalConstants . ApiVersion } ")
234+ ) ;
235+
236+ //default values
237+ var mockedGroupsClient = MockGroupsClient . GetMockedApiClientWithDefaultValues ( ) ;
238+ var mockedTagClient = MockTagClient . GetMockedApiClientWithEmptytValues ( ) ;
239+
240+ var mockedPolicyClient = MockPolicyClient . GetMockedApiClientWithEmptyValues ( ) ;
241+ var mockedPolicyExtractor = new PolicyExtractor ( this . GetTestLogger < PolicyExtractor > ( ) , mockedPolicyClient , new TemplateBuilder ( ) ) ;
242+
243+ var productExtractor = new ProductExtractor (
244+ this . GetTestLogger < ProductExtractor > ( ) ,
245+ mockedPolicyExtractor ,
246+ mockedProductsClient ,
247+ mockedGroupsClient ,
248+ mockedTagClient ,
249+ new TemplateBuilder ( ) ) ;
250+
251+ var extractorExecutor = ExtractorExecutor . BuildExtractorExecutor (
252+ this . GetTestLogger < ExtractorExecutor > ( ) ,
253+ productExtractor : productExtractor ) ;
254+ extractorExecutor . SetExtractorParameters ( extractorParameters ) ;
255+
256+ // act
257+ var productTemplate = await extractorExecutor . GenerateProductsTemplateAsync (
258+ singleApiName : null ,
259+ currentTestDirectory ) ;
260+
261+ // assert
262+ // generated product template files
263+ File . Exists ( Path . Combine ( currentTestDirectory , extractorParameters . FileNames . Products ) ) . Should ( ) . BeTrue ( ) ;
264+
265+ var templateParameters = productTemplate . Parameters ;
266+ templateParameters . Should ( ) . ContainKey ( ParameterNames . ApimServiceName ) ;
267+
268+ var templateResources = productTemplate . Resources ;
269+ // product resource
270+ var productResources = templateResources . Where ( x => x . Type == ResourceTypeConstants . Product ) . ToList ( ) ;
271+ productResources . Count . Should ( ) . Be ( 2 ) ;
272+ productResources . Any ( x => x . OriginalName == "unlimited" ) . Should ( ) . BeTrue ( ) ;
273+ productResources . Any ( x => x . OriginalName == "starter" ) . Should ( ) . BeTrue ( ) ;
274+
275+ var attachedGroups = templateResources . Where ( x => x . Type == ResourceTypeConstants . ProductGroup ) . ToList ( ) ;
276+ attachedGroups . Count . Should ( ) . Be ( 0 ) ;
215277 }
216278 }
217279}
0 commit comments