public void Items_function_works_for_resources() { var program = @" resource testRes 'Test.Rp/readWriteTests@2020-01-01' existing = { name: 'testRes' } var itemsOutput = items(testRes.properties) var singleItemKey = itemsOutput[0].key var singleItemValue = itemsOutput[0].value "; var model = GetSemanticModelForTest(program, BuiltInTestTypes.Create()); GetTypeForNamedSymbol(model, "itemsOutput").Name.Should().Be("object[]"); GetTypeForNamedSymbol(model, "singleItemKey").Name.Should().Be("'readonly' | 'readwrite' | 'required'"); GetTypeForNamedSymbol(model, "singleItemValue").Name.Should().Be("string"); }
public async Task Build_command_should_generate_template_with_symbolic_names_if_enabled() { var diagnosticsListener = new MultipleMessageListener <PublishDiagnosticsParams>(); var features = BicepTestConstants.CreateFeaturesProvider( TestContext, symbolicNameCodegenEnabled: true, assemblyFileVersion: BicepTestConstants.DevAssemblyFileVersion); using var helper = await LanguageServerHelper.StartServerWithClientConnectionAsync( this.TestContext, options => options.OnPublishDiagnostics(diagnosticsParams => diagnosticsListener.AddMessage(diagnosticsParams)), new LanguageServer.Server.CreationOptions( NamespaceProvider: BuiltInTestTypes.Create(), Features: features)); var client = helper.Client; var outputDirectory = FileHelper.SaveEmbeddedResourcesWithPathPrefix( TestContext, typeof(ExamplesTests).Assembly, "Bicep.Core.Samples/Resources_CRLF"); var bicepFilePath = Path.Combine(outputDirectory, "main.bicep"); var expectedJson = File.ReadAllText(Path.Combine(outputDirectory, "main.symbolicnames.json")); client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParamsFromFile(bicepFilePath, 1)); await diagnosticsListener.WaitNext(); await client.Workspace.ExecuteCommand(new Command { Name = "build", Arguments = new JArray { bicepFilePath, } }); var buildCommandOutput = File.ReadAllText(Path.ChangeExtension(bicepFilePath, ".json")); buildCommandOutput.Should().BeEquivalentToIgnoringNewlines(expectedJson); }
public async Task RequestDeploymentGraphShouldReturnDeploymentGraph() { var diagnosticsListener = new MultipleMessageListener <PublishDiagnosticsParams>(); var fileSystemDict = new Dictionary <Uri, string>(); var client = await IntegrationTestHelper.StartServerWithClientConnectionAsync( this.TestContext, options => options.OnPublishDiagnostics(diagnosticsParams => diagnosticsListener.AddMessage(diagnosticsParams)), BuiltInTestTypes.Create(), new InMemoryFileResolver(fileSystemDict)); var mainUri = DocumentUri.FromFileSystemPath("/main.bicep"); fileSystemDict[mainUri.ToUri()] = @" resource res1 'Test.Rp/basicTests@2020-01-01' = { name: 'res1' } resource res2 'Test.Rp/readWriteTests@2020-01-01' = { name: 'res2' properites: { readwrite: mod1.outputs.output1 } } resource unknownRes = { } module mod1 './modules/module1.bicep' = { name: 'mod1' } module mod2 './modules/module2.bicep' = { name: 'mod2' } module nonExistingMod './path/to/nonExistingModule.bicep' = { } "; var module1Uri = DocumentUri.FromFileSystemPath("/modules/module1.bicep"); fileSystemDict[module1Uri.ToUri()] = @" resource res3 'Test.Rp/basicTests@2020-01-01' = { name: 'res3' } output output1 int = 123 "; var module2Uri = DocumentUri.FromFileSystemPath("/modules/module2.bicep"); fileSystemDict[module2Uri.ToUri()] = @" resource res4 'Test.Rp/basicTests@2020-01-01' = { name: 'res4' } module nestedMod './nestedModules/nestedModule.bicep' = [for x in []: { name: 'nestedMod' dependsOn: [ res4 ] }] "; var nestedModuleUri = DocumentUri.FromFileSystemPath("/modules/nestedModules/nestedModule.bicep"); fileSystemDict[nestedModuleUri.ToUri()] = @" resource res5 'Test.Rp/basicTests@2020-01-01' = { name: 'res5' } "; client.TextDocument.DidOpenTextDocument(TextDocumentParamHelper.CreateDidOpenDocumentParams(mainUri, fileSystemDict[mainUri.ToUri()], 1)); await diagnosticsListener.WaitNext(); var deploymentGraph = await client.SendRequest(new BicepDeploymentGraphParams(new TextDocumentIdentifier(mainUri)), default); deploymentGraph.Should().NotBeNull(); deploymentGraph !.Nodes.Should().Equal( new BicepDeploymentGraphNode("mod1", "<module>", false, CreateTextRange(15, 0, 17, 1), true, false, Path.GetFullPath(module1Uri.GetFileSystemPath())), new BicepDeploymentGraphNode("mod1::res3", "Test.Rp/basicTests", false, CreateTextRange(1, 0, 3, 1), false, false, Path.GetFullPath(module1Uri.GetFileSystemPath())), new BicepDeploymentGraphNode("mod2", "<module>", false, CreateTextRange(19, 0, 21, 1), true, false, Path.GetFullPath(module2Uri.GetFileSystemPath())), new BicepDeploymentGraphNode("mod2::nestedMod", "<module>", true, CreateTextRange(5, 0, 9, 1), true, false, Path.GetFullPath(nestedModuleUri.GetFileSystemPath())), new BicepDeploymentGraphNode("mod2::nestedMod::res5", "Test.Rp/basicTests", false, CreateTextRange(1, 0, 3, 1), false, false, Path.GetFullPath(nestedModuleUri.GetFileSystemPath())), new BicepDeploymentGraphNode("mod2::res4", "Test.Rp/basicTests", false, CreateTextRange(1, 0, 3, 1), false, false, Path.GetFullPath(module2Uri.GetFileSystemPath())), new BicepDeploymentGraphNode("nonExistingMod", "<module>", false, CreateTextRange(23, 0, 24, 1), false, true, Path.GetFullPath("/path/to/nonExistingModule.bicep")), new BicepDeploymentGraphNode("res1", "Test.Rp/basicTests", false, CreateTextRange(1, 0, 3, 1), false, false, Path.GetFullPath(mainUri.GetFileSystemPath())), new BicepDeploymentGraphNode("res2", "Test.Rp/readWriteTests", false, CreateTextRange(5, 0, 10, 1), false, true, Path.GetFullPath(mainUri.GetFileSystemPath()))); deploymentGraph !.Edges.Should().Equal( new BicepDeploymentGraphEdge("mod2::nestedMod", "mod2::res4"), new BicepDeploymentGraphEdge("res2", "mod1")); deploymentGraph !.ErrorCount.Should().Be(7); }
public async Task Property_completions_include_descriptions() { var(file, cursors) = ParserHelper.GetFileWithCursors(@" resource testRes 'Test.Rp/readWriteTests@2020-01-01' = { name: 'testRes' properties: { | } } output string test = testRes.| output string test2 = testRes.properties.| "); var syntaxTree = SyntaxTree.Create(new Uri("file:///path/to/main.bicep"), file); var client = await IntegrationTestHelper.StartServerWithTextAsync(file, syntaxTree.FileUri, resourceTypeProvider : BuiltInTestTypes.Create()); var completions = await RequestCompletions(client, syntaxTree, cursors); completions.Should().SatisfyRespectively( x => x !.OrderBy(d => d.SortText).Should().SatisfyRespectively( d => d.Documentation !.MarkupContent !.Value.Should().Contain("This is a property which supports reading AND writing!"), d => d.Documentation !.MarkupContent !.Value.Should().Contain("This is a property which is required."), d => d.Documentation !.MarkupContent !.Value.Should().Contain("This is a property which only supports writing.")), x => x !.OrderBy(d => d.SortText).Should().SatisfyRespectively( d => d.Documentation !.MarkupContent !.Value.Should().Contain("apiVersion property"), d => d.Documentation !.MarkupContent !.Value.Should().Contain("id property"), d => d.Documentation !.MarkupContent !.Value.Should().Contain("name property"), d => d.Documentation !.MarkupContent !.Value.Should().Contain("properties property"), d => d.Documentation !.MarkupContent !.Value.Should().Contain("type property")), x => x !.OrderBy(d => d.SortText).Should().SatisfyRespectively( d => d.Documentation !.MarkupContent !.Value.Should().Contain("This is a property which only supports reading."), d => d.Documentation !.MarkupContent !.Value.Should().Contain("This is a property which supports reading AND writing!"), d => d.Documentation !.MarkupContent !.Value.Should().Contain("This is a property which is required."))); }
private static async Task RunDefinitionScenarioTest(TestContext testContext, string fileWithCursors, Action <List <LocationOrLocationLinks> > assertAction) { var(file, cursors) = ParserHelper.GetFileWithCursors(fileWithCursors); var bicepFile = SourceFileFactory.CreateBicepFile(new Uri("file:///path/to/main.bicep"), file); var client = await IntegrationTestHelper.StartServerWithTextAsync(testContext, file, bicepFile.FileUri, creationOptions : new LanguageServer.Server.CreationOptions(NamespaceProvider: BuiltInTestTypes.Create())); var results = await RequestDefinitions(client, bicepFile, cursors); assertAction(results); }