forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
src/Bicep.Core.IntegrationTests/Scenarios/NameofFunctionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Bicep.Core.UnitTests.Assertions; | ||
using Bicep.Core.UnitTests.Utils; | ||
using FluentAssertions.Execution; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Bicep.Core.IntegrationTests.Scenarios | ||
{ | ||
[TestClass] | ||
public class NameofFunctionTests | ||
{ | ||
[TestMethod] | ||
public void NameofFunction_OnObjectProperty_ReturnsPropertyName() | ||
{ | ||
var result = CompilationHelper.Compile(""" | ||
var obj = { | ||
prop: 'value' | ||
} | ||
var name = nameof(obj.prop) | ||
"""); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
result.Should().NotHaveAnyCompilationBlockingDiagnostics(); | ||
result.Template.Should().HaveValueAtPath("$.variables['name']", "prop"); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void NameofFunction_OnVariable_ReturnsVariableName() | ||
{ | ||
var result = CompilationHelper.Compile(""" | ||
var obj = { | ||
prop: 'value' | ||
} | ||
var name = nameof(obj) | ||
"""); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
result.Should().NotHaveAnyCompilationBlockingDiagnostics(); | ||
result.Template.Should().HaveValueAtPath("$.variables['name']", "obj"); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void NameofFunction_OnResource_ReturnsResourceSymbolicName() | ||
{ | ||
var result = CompilationHelper.Compile(""" | ||
resource myStorage 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'storage123' | ||
} | ||
|
||
var name = nameof(myStorage) | ||
"""); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
result.Should().NotHaveAnyCompilationBlockingDiagnostics(); | ||
result.Template.Should().HaveValueAtPath("$.variables['name']", "myStorage"); | ||
} | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow("name", "name")] | ||
[DataRow("type", "type")] | ||
[DataRow("location", "location")] | ||
[DataRow("properties", "properties")] | ||
[DataRow("properties.sku", "sku")] | ||
public void NameofFunction_OnResourceProperty_ReturnsResourcePropertyName(string resourceProperty, string expectedValue) | ||
{ | ||
var result = CompilationHelper.Compile($$""" | ||
resource myStorage 'Microsoft.Storage/storageAccounts@2019-06-01' = { | ||
name: 'storage123' | ||
} | ||
|
||
var name = nameof(myStorage.{{resourceProperty}}) | ||
|
||
"""); | ||
|
||
using (new AssertionScope()) | ||
{ | ||
result.Should().NotHaveAnyCompilationBlockingDiagnostics(); | ||
result.Template.Should().HaveValueAtPath("$.variables['name']", expectedValue); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters