|
10 | 10 | using FluentAssertions;
|
11 | 11 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Commands.Executors;
|
12 | 12 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Constants;
|
| 13 | +using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.FileHandlers; |
13 | 14 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common.Templates.Builders;
|
14 | 15 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.EntityExtractors;
|
15 | 16 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extractor.Models;
|
@@ -155,5 +156,77 @@ public async Task GenerateApiTemplates_ProperlyLaysTheInformation()
|
155 | 156 | apiTemplate.TypedResources.ApiOperationsPolicies.Count().Should().Be(2);
|
156 | 157 | apiTemplate.TypedResources.ApiOperations.All(x => x.Properties is not null).Should().BeTrue();
|
157 | 158 | }
|
| 159 | + |
| 160 | + [Fact] |
| 161 | + public async Task GenerateGraphQLApiTemplates() |
| 162 | + { |
| 163 | + FileReader fileReader = new FileReader(); |
| 164 | + string fileLocation = Path.Combine("Resources", "Schemas", "schema.gql"); |
| 165 | + |
| 166 | + Task<string> fileReadingTask = fileReader.RetrieveFileContentsAsync(fileLocation); |
| 167 | + |
| 168 | + // arrange |
| 169 | + var currentTestDirectory = Path.Combine(this.OutputDirectory, nameof(GenerateGraphQLApiTemplates)); |
| 170 | + |
| 171 | + var extractorConfig = this.GetDefaultExtractorConsoleAppConfiguration( |
| 172 | + sourceApimName: string.Empty, |
| 173 | + destinationApimName: string.Empty, |
| 174 | + resourceGroup: string.Empty, |
| 175 | + fileFolder: string.Empty, |
| 176 | + apiName: string.Empty); |
| 177 | + var extractorParameters = new ExtractorParameters(extractorConfig); |
| 178 | + |
| 179 | + // mocked clients |
| 180 | + var mockedApiClient = MockApisClient.GetMockedApiClientWithDefaultValues(); |
| 181 | + var mockedProductClient = MockProductsClient.GetMockedApiClientWithDefaultValues(); |
| 182 | + var mockedApiSchemaClient = MockApiSchemaClient.GetMockedApiClientWithGraphQLSchemaValues(); |
| 183 | + var mockedPolicyClient = MockPolicyClient.GetMockedApiClientWithDefaultValues(); |
| 184 | + var mockedTagClient = MockTagClient.GetMockedApiClientWithDefaultValues(); |
| 185 | + var mockedApiOperationClient = MockApiOperationClient.GetMockedApiClientWithDefaultValues(); |
| 186 | + var mockedDiagnosticClient = MockDiagnosticClient.GetMockedClientWithApiDependentValues(); |
| 187 | + |
| 188 | + // mocked extractors |
| 189 | + var mockedDiagnosticExtractor = new DiagnosticExtractor(this.GetTestLogger<DiagnosticExtractor>(), mockedDiagnosticClient); |
| 190 | + var mockedApiSchemaExtractor = new ApiSchemaExtractor(this.GetTestLogger<ApiSchemaExtractor>(), mockedApiSchemaClient); |
| 191 | + var mockedPolicyExtractor = new PolicyExtractor(this.GetTestLogger<PolicyExtractor>(), mockedPolicyClient, new TemplateBuilder()); |
| 192 | + var mockedProductApisExtractor = new ProductApisExtractor(this.GetTestLogger<ProductApisExtractor>(), mockedProductClient, mockedApiClient, new TemplateBuilder()); |
| 193 | + var mockedTagExtractor = new TagExtractor(this.GetTestLogger<TagExtractor>(), mockedTagClient, new TemplateBuilder()); |
| 194 | + var mockedApiOperationExtractor = new ApiOperationExtractor(this.GetTestLogger<ApiOperationExtractor>(), mockedApiOperationClient); |
| 195 | + |
| 196 | + var apiExtractor = new ApiExtractor( |
| 197 | + this.GetTestLogger<ApiExtractor>(), |
| 198 | + new TemplateBuilder(), |
| 199 | + mockedApiClient, |
| 200 | + mockedDiagnosticExtractor, |
| 201 | + mockedApiSchemaExtractor, |
| 202 | + mockedPolicyExtractor, |
| 203 | + mockedProductApisExtractor, |
| 204 | + mockedTagExtractor, |
| 205 | + mockedApiOperationExtractor); |
| 206 | + |
| 207 | + var extractorExecutor = ExtractorExecutor.BuildExtractorExecutor( |
| 208 | + this.GetTestLogger<ExtractorExecutor>(), |
| 209 | + apiExtractor: apiExtractor); |
| 210 | + extractorExecutor.SetExtractorParameters(extractorParameters); |
| 211 | + |
| 212 | + // act |
| 213 | + var apiTemplate = await extractorExecutor.GenerateApiTemplateAsync( |
| 214 | + singleApiName: It.IsAny<string>(), |
| 215 | + multipleApiNames: It.IsAny<List<string>>(), |
| 216 | + currentTestDirectory); |
| 217 | + |
| 218 | + // assert |
| 219 | + File.Exists(Path.Combine(currentTestDirectory, apiTemplate.TypedResources.FileName)).Should().BeTrue(); |
| 220 | + |
| 221 | + //schema name |
| 222 | + string schemaContentType = "application/vnd.ms-azure-apim.graphql.schema"; |
| 223 | + |
| 224 | + // api schemas |
| 225 | + apiTemplate.TypedResources.ApiSchemas.Count().Should().Be(2); |
| 226 | + apiTemplate.TypedResources.ApiSchemas.All(x => x.Type == ResourceTypeConstants.APISchema).Should().BeTrue(); |
| 227 | + apiTemplate.TypedResources.ApiSchemas.All(x => x.Properties is not null).Should().BeTrue(); |
| 228 | + apiTemplate.TypedResources.ApiSchemas.All(x => x.Properties.Document.Value.ToString().Equals(fileReadingTask.Result.ToString())).Should().BeTrue(); |
| 229 | + apiTemplate.TypedResources.ApiSchemas.All(x => x.Properties.ContentType.Equals(schemaContentType)).Should().BeTrue(); |
| 230 | + } |
158 | 231 | }
|
159 | 232 | }
|
0 commit comments