forked from microsoft/PSRule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectPathTests.cs
34 lines (30 loc) · 1.24 KB
/
ObjectPathTests.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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.IO;
using System.Linq;
using System.Management.Automation;
using PSRule.Pipeline;
using Xunit;
namespace PSRule
{
public sealed class ObjectPathTests
{
[Fact]
public void UseObjectPath()
{
var actual = PipelineReceiverActions.ConvertFromYaml(GetYamlContent(),
(sourceObject) => PipelineReceiverActions.ReadObjectPath(sourceObject, PipelineReceiverActions.PassThru, "items", true)
).ToArray();
Assert.Equal(2, actual.Length);
Assert.Equal("TestObject1", actual[0].Value.Properties["targetName"].Value);
Assert.Equal("Test", actual[0].Value.PropertyValue<PSObject>("spec").PropertyValue<PSObject>("properties").PropertyValue<string>("kind"));
Assert.Equal(2, actual[1].Value.PropertyValue<PSObject>("spec").PropertyValue<PSObject>("properties").PropertyValue<int>("value2"));
}
private TargetObject GetYamlContent()
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ObjectFromNestedFile.yaml");
return new TargetObject(new PSObject(File.ReadAllText(path)));
}
}
}