Exemple #1
0
 public void DefaultTargetNameBinding()
 {
     foreach (var targetObject in _TargetObject)
     {
         PipelineHookActions.BindTargetName(null, false, targetObject);
     }
 }
Exemple #2
0
 public void NestedTargetNameBinding()
 {
     foreach (var targetObject in _TargetObject)
     {
         PipelineHookActions.BindTargetName(
             propertyNames: new string[] { "TargetName", "Name" },
             caseSensitive: true,
             targetObject: targetObject
             );
     }
 }
Exemple #3
0
        public void DeserializeObjectsPowerShellData()
        {
            var actual = PipelineReceiverActions.ConvertFromPowerShellData(GetDataContent(), PipelineReceiverActions.PassThru).ToArray();

            Assert.Single(actual);
            Assert.Equal("TestObject1", actual[0].PropertyValue <string>("targetName"));
            Assert.Equal("Test", actual[0].PropertyValue("spec").PropertyValue("properties").PropertyValue <string>("kind"));
            Assert.Equal(1, actual[0].PropertyValue("spec").PropertyValue("properties").PropertyValue <int>("value1"));
            Assert.Equal(2, actual[0].PropertyValue("spec").PropertyValue("properties").PropertyValue <Array>("array").Length);
            Assert.Equal("TestObject1", PipelineHookActions.BindTargetName(null, false, actual[0]));
        }
Exemple #4
0
        public void DeserializeObjectsYaml()
        {
            var actual = PipelineReceiverActions.ConvertFromYaml(GetYamlContent(), PipelineReceiverActions.PassThru).ToArray();

            Assert.Equal(2, actual.Length);
            Assert.Equal("TestObject1", actual[0].PropertyValue <string>("targetName"));
            Assert.Equal("Test", actual[0].PropertyValue("spec").PropertyValue("properties").PropertyValue <string>("kind"));
            Assert.Equal(2, actual[1].PropertyValue("spec").PropertyValue("properties").PropertyValue <int>("value2"));
            Assert.Equal(2, actual[1].PropertyValue("spec").PropertyValue("properties").PropertyValue <PSObject[]>("array").Length);
            Assert.Equal("TestObject1", PipelineHookActions.BindTargetName(null, false, actual[0]));
        }
Exemple #5
0
        public void UnboundObjectTargetName()
        {
            var testObject1 = new TestModel1 {
                NotName = "TestObject1"
            };
            var testObject2 = new TestModel2 {
                NotName = "TestObject1"
            };
            var pso1 = PSObject.AsPSObject(testObject1);
            var pso2 = PSObject.AsPSObject(testObject2);

            PipelineContext.CurrentThread = PipelineContext.New(option: new PSRuleOption(), hostContext: null, binder: new TargetBinder(null, null, null, null), baseline: null, unresolved: null);
            var actual1 = PipelineHookActions.BindTargetName(null, false, pso1);
            var actual2 = PipelineHookActions.BindTargetName(null, false, pso2);

            Assert.Equal(expected: "f209c623345144be61087d91f30c17b01c6e86d2", actual: actual1);
            Assert.Equal(expected: "f209c623345144be61087d91f30c17b01c6e86d2", actual: actual2);
        }
Exemple #6
0
        public void DeserializeObjectsJson()
        {
            var actual = PipelineReceiverActions.ConvertFromJson(GetJsonContent(), PipelineReceiverActions.PassThru).ToArray();

            Assert.Equal(2, actual.Length);
            Assert.Equal("TestObject1", actual[0].PropertyValue <string>("targetName"));
            Assert.Equal("Test", actual[0].PropertyValue("spec").PropertyValue("properties").PropertyValue <string>("kind"));
            Assert.Equal(2, actual[1].PropertyValue("spec").PropertyValue("properties").PropertyValue <int>("value2"));
            Assert.Equal(2, actual[1].PropertyValue("spec").PropertyValue("properties").PropertyValue <PSObject[]>("array").Length);
            Assert.Equal("TestObject1", PipelineHookActions.BindTargetName(null, false, actual[0]));

            // Single item
            actual = PipelineReceiverActions.ConvertFromJson(GetJsonContent("Single"), PipelineReceiverActions.PassThru).ToArray();
            Assert.Single(actual);
            Assert.Equal("TestObject1", actual[0].PropertyValue <string>("targetName"));
            Assert.Equal("Test", actual[0].PropertyValue("spec").PropertyValue("properties").PropertyValue <string>("kind"));

            // Malformed item
            Assert.Throws <PipelineSerializationException>(() => PipelineReceiverActions.ConvertFromJson("{", PipelineReceiverActions.PassThru).ToArray());
            Assert.Throws <PipelineSerializationException>(() => PipelineReceiverActions.ConvertFromJson("{ \"key\": ", PipelineReceiverActions.PassThru).ToArray());
        }