예제 #1
0
        public void SimpleEnumerateInstance()
        {
            MI_Operation operation = null;

            this.Session.EnumerateInstances(MI_OperationFlags.MI_OPERATIONFLAGS_DEFAULT_RTTI,
                                            MI_OperationOptions.Null,
                                            TestEnumerateInstanceNamespace,
                                            TestEnumerateInstanceClassName,
                                            false,
                                            null,
                                            out operation);

            bool        moreResults    = true;
            MI_Instance clonedInstance = null;

            MI_Result   secondaryResult;
            string      errorMessage = null;
            MI_Instance instanceOut  = null;
            MI_Instance errorDetails = null;
            var         res          = operation.GetInstance(out instanceOut, out moreResults, out secondaryResult, out errorMessage, out errorDetails);

            MIAssert.Succeeded(res, "Expect the first GetInstance call to succeed");
            MIAssert.Succeeded(secondaryResult, "Expect the logical result of the GetInstance call to succeed");

            if (!instanceOut.IsNull)
            {
                res = instanceOut.Clone(out clonedInstance);
                MIAssert.Succeeded(res, "Expect the clone to succeed");
            }

            while (moreResults)
            {
                res = operation.GetInstance(out instanceOut, out moreResults, out secondaryResult, out errorMessage, out errorDetails);
                MIAssert.Succeeded(res, "Expect GetInstance to succeed even if we don't want the result");
                MIAssert.Succeeded(secondaryResult, "Expect the logical result of the GetInstance call to succeed even if we don't want the result");
            }

            res = operation.Close();
            MIAssert.Succeeded(res, "Expect operation to close successfully");

            string className = null;

            res = clonedInstance.GetClassName(out className);
            MIAssert.Succeeded(res, "Expect GetClassName to succeed");
            Assert.Equal(TestEnumerateInstanceClassName, className, "Expect the class name to be the one we queried");

            MI_Value elementValue = null;
            MI_Type  elementType;
            MI_Flags elementFlags;
            UInt32   elementIndex;

            res = clonedInstance.GetElement(TestEnumerateInstanceStringPropertyName, out elementValue, out elementType, out elementFlags, out elementIndex);
            MIAssert.Succeeded(res, "Expect GetElement to succeed");

            Assert.Equal(MI_Type.MI_STRING, elementType, "Expect that the property is registered as a string");
            Assert.Equal(TestEnumerateInstanceStringPropertyFlags,
                         elementFlags, "Expect the element flags to also be properly available from the query");
            Assert.Equal(TestEnumerateInstanceStringPropertyValue, elementValue.String, "Expect the machine name to have survived the whole journey");
        }
예제 #2
0
        private void TestValueRoundtrip()
        {
            Assert.True(this.value.Type.HasValue, "Expect value to have a value before calling helper");
            string propertyName = this.value.Type.ToString();
            var    res          = this.instance.AddElement(propertyName, this.value, this.value.Type.Value, MI_Flags.MI_FLAG_BORROW);

            MIAssert.Succeeded(res, "Expect add element to succeed");

            MI_Value returnedValue = null;
            MI_Type  elementType;
            MI_Flags elementFlags = 0;
            UInt32   elementIndex = 0;

            res = instance.GetElement(propertyName, out returnedValue, out elementType, out elementFlags, out elementIndex);
            MIAssert.Succeeded(res, "Expect to get element by name");
            var testproperty = new TestMIProperty(returnedValue, elementType, elementFlags);

            MIAssert.MIPropertiesEqual(new TestMIProperty(this.value, this.value.Type.Value, MI_Flags.None), testproperty, propertyName);
        }