forked from Azure/PSRule.Rules.Azure
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBicepScopeTests.cs
36 lines (30 loc) · 1.83 KB
/
BicepScopeTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Linq;
using Newtonsoft.Json.Linq;
namespace PSRule.Rules.Azure.Bicep.ScopeTestCases;
/// <summary>
/// Tests for validating resource scopes and IDs are generated correctly.
/// </summary>
public sealed class BicepScopeTests : TemplateVisitorTestsBase
{
[Fact]
public void ProcessTemplate_WhenManagementGroupAtTenant_ShouldReturnCompleteProperties()
{
var resources = ProcessTemplate(GetSourcePath("Bicep/ScopeTestCases/Tests.Bicep.1.json"), null, out _);
Assert.NotNull(resources);
var actual = resources.Where(r => r["name"].Value<string>() == "mg-01").FirstOrDefault();
Assert.Equal("Microsoft.Management/managementGroups", actual["type"].Value<string>());
Assert.Equal("/providers/Microsoft.Management/managementGroups/mg-01", actual["id"].Value<string>());
Assert.Equal("/", actual["scope"].Value<string>());
Assert.Equal("mg-01", actual["properties"]["displayName"].Value<string>());
Assert.Equal("ffffffff-ffff-ffff-ffff-ffffffffffff", actual["properties"]["tenantId"].Value<string>());
actual = resources.Where(r => r["name"].Value<string>() == "mg-02").FirstOrDefault();
Assert.Equal("Microsoft.Management/managementGroups", actual["type"].Value<string>());
Assert.Equal("/providers/Microsoft.Management/managementGroups/mg-02", actual["id"].Value<string>());
Assert.Equal("/", actual["scope"].Value<string>());
Assert.Equal("mg-02", actual["properties"]["displayName"].Value<string>());
Assert.Equal("ffffffff-ffff-ffff-ffff-ffffffffffff", actual["properties"]["tenantId"].Value<string>());
Assert.Equal("/providers/Microsoft.Management/managementGroups/mg-01", actual["properties"]["details"]["parent"]["id"].Value<string>());
}
}