Пример #1
0
        public void EntityFromPSObject_WhenBaseObjectIsNotPSO_ReturnsSingleValueEntity(object expected)
        {
            var pso = new PSObject(expected);

            var entity = PwshRunner.EntityFromPSObject(pso);

            Assert.NotNull(entity);

            var val = entity.TryGetValue(Entity.PrimitiveKey).Value.ObjectValue;

            Assert.Equal(expected, val);
        }
Пример #2
0
        public void EntityFromPSObject_WhenBaseObjectIsArray_ReturnsEntity()
        {
            var arr = new object[] { "value1", 2 };
            var pso = new PSObject(arr);

            var entity = PwshRunner.EntityFromPSObject(pso);

            Assert.NotNull(entity);

            var actual =
                entity.Dictionary[Entity.PrimitiveKey].BestValue.ObjectValue as
                ImmutableList <EntityValue>;

            Assert.Equal(arr[0], actual ![0].ObjectValue);
Пример #3
0
        public void EntityFromPSObject_WhenBaseObjectIsHashtable_ReturnsEntity()
        {
            var pso = new PSObject(new Hashtable {
                { "prop1", "value1" }, { "prop2", 2 }
            });

            var entity = PwshRunner.EntityFromPSObject(pso);

            Assert.NotNull(entity);

            var val1 = entity.TryGetValue("prop1").Map(x => x.GetPrimitiveString());
            var val2 = entity.TryGetValue("prop2").Map(x => x.ObjectValue);

            Assert.Equal(2, entity.Count());
            Assert.Equal("value1", val1);
            Assert.Equal(2, val2);
        }
Пример #4
0
        public void EntityFromPSObject_WhenBaseObjectIsPSO_ReturnsMultiValueEntity()
        {
            var pso = new PSObject();

            pso.Properties.Add(new PSNoteProperty("prop1", "value1"));
            pso.Properties.Add(new PSNoteProperty("prop2", "value2"));

            var entity = PwshRunner.EntityFromPSObject(pso);

            Assert.NotNull(entity);

            var val1 = entity.TryGetValue("prop1").Map(x => x.GetPrimitiveString());
            var val2 = entity.TryGetValue("prop2").Map(x => x.GetPrimitiveString());

            Assert.Equal(2, entity.Count());
            Assert.Equal("value1", val1 !.ToString());
            Assert.Equal("value2", val2 !.ToString());
        }