コード例 #1
0
        public async Task Handle_WithValidInput_VerifyNoEntryInDeploymentFileCompilationCache()
        {
            var bicepFileContents       = @"param name string = 'test'
param location string = 'global
resource dnsZone 'Microsoft.Network/dnsZones@2018-05-01' = {
  name: name
  location: location
}";
            var template                = @"{
  ""$schema"": ""https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"",
  ""contentVersion"": ""1.0.0.0"",
  ""metadata"": {
    ""_generator"": {
      ""name"": ""bicep"",
      ""version"": ""0.6.18.56646"",
      ""templateHash"": ""3422964353444461889""
    }
  },
  ""parameters"": {
    ""name"": {
      ""type"": ""string"",
      ""defaultValue"": ""test""
    },
    ""location"": {
      ""type"": ""string"",
      ""defaultValue"": ""global""
    }
  },
  ""resources"": [
    {
      ""type"": ""Microsoft.Network/dnsZones"",
      ""apiVersion"": ""2018-05-01"",
      ""name"": ""[parameters('name')]"",
      ""location"": ""[parameters('location')]""
    }
  ]
}";
            var bicepFilePath           = FileHelper.SaveResultFile(TestContext, "input.bicep", bicepFileContents);
            var documentUri             = DocumentUri.FromFileSystemPath(bicepFilePath);
            var bicepCompilationManager = BicepCompilationManagerHelper.CreateCompilationManager(documentUri, bicepFileContents, true);
            var compilation             = bicepCompilationManager.GetCompilation(documentUri) !.Compilation;

            DeploymentFileCompilationCache.CacheCompilation(documentUri, compilation);
            var bicepDeploymentParametersHandler = new BicepDeploymentParametersHandler(DeploymentFileCompilationCache, Serializer);

            await bicepDeploymentParametersHandler.Handle(bicepFilePath, string.Empty, template, CancellationToken.None);

            Assert.IsNull(DeploymentFileCompilationCache.FindAndRemoveCompilation(documentUri));
        }
コード例 #2
0
        public override Task <BicepDeploymentScopeResponse> Handle(BicepDeploymentScopeParams request, CancellationToken cancellationToken)
        {
            var documentUri = request.TextDocument.Uri;

            Compilation?compilation;

            try
            {
                compilation = GetCompilation(documentUri);

                // Cache the compilation so that it can be reused by BicepDeploymentParametersHandler
                deploymentFileCompilationCache.CacheCompilation(documentUri, compilation);

                var deploymentScope = GetDeploymentScope(compilation.GetEntrypointSemanticModel().TargetScope);

                return(Task.FromResult(new BicepDeploymentScopeResponse(deploymentScope, GetCompiledFile(compilation, documentUri), null)));
            }
            catch (Exception exception)
            {
                return(Task.FromResult(new BicepDeploymentScopeResponse(ResourceScope.None.ToString(), null, exception.Message)));
            }
        }