Beispiel #1
0
        internal static void InstancesEqual(MI_Instance expected, MI_Instance actual, string propertyName)
        {
            uint expectedElementCount;

            expected.GetElementCount(out expectedElementCount);
            uint actualElementCount;

            actual.GetElementCount(out actualElementCount);
            Assert.Equal(expectedElementCount, actualElementCount);
            for (uint i = 0; i < expectedElementCount; i++)
            {
                MI_Flags expectedElementFlags;
                MI_Type  expectedElementType;
                string   expectedElementName  = null;
                MI_Value expectedElementValue = null;
                expected.GetElementAt(i, out expectedElementName, out expectedElementValue, out expectedElementType, out expectedElementFlags);

                MI_Flags actualElementFlags;
                MI_Value actualElementValue = null;
                MI_Type  actualElementType;
                string   actualElementName = null;
                actual.GetElementAt(i, out actualElementName, out actualElementValue, out actualElementType, out actualElementFlags);

                Assert.Equal(expectedElementName, actualElementName, "Expect the element names to be the same within the instances");
                MIAssert.MIPropertiesEqual(new TestMIProperty(expectedElementValue, expectedElementType, expectedElementFlags),
                                           new TestMIProperty(actualElementValue, actualElementType, actualElementFlags), propertyName);
            }
        }
Beispiel #2
0
        internal static void MIPropertiesEqual(TestMIProperty expectedProperty, TestMIProperty actualProperty, string propertyName)
        {
            // Note that we do not check the flags - the behavior is too inconsistent across scenarios to be worth
            // the current amount of effort, and it's not a marshalling issue

            Assert.Equal(expectedProperty.Type, actualProperty.Type, "Expect the property types to be the same");
            if ((expectedProperty.Flags & MI_Flags.MI_FLAG_NULL) != 0)
            {
                return;
            }

            if (expectedProperty.Type == MI_Type.MI_DATETIME)
            {
                MI_Datetime expected = (MI_Datetime)expectedProperty.Value;
                var         actual   = (MI_Datetime)actualProperty.Value;
                if (expected.isTimestamp)
                {
                    MIAssert.MIDatetimesEqual(expected, actual);
                }
            }
            else if (expectedProperty.Type == MI_Type.MI_DATETIMEA)
            {
                MI_Datetime[] expected = (MI_Datetime[])expectedProperty.Value;
                var           actual   = (MI_Datetime[])actualProperty.Value;
                Assert.Equal(expected.Length, actual.Length, "Expect the MI_DATETIME arrays to be of the same length");
                for (int i = 0; i < expected.Length; i++)
                {
                    MIAssert.MIDatetimesEqual(expected[i], (MI_Datetime)actual[i]);
                }
            }
            else if (expectedProperty.Type == MI_Type.MI_INSTANCE || expectedProperty.Type == MI_Type.MI_REFERENCE)
            {
                MI_Instance expected = (MI_Instance)expectedProperty.Value;
                MI_Instance actual   = actualProperty.Value as MI_Instance;
                MIAssert.InstancesEqual(expected, actual, propertyName);
            }
            else if (expectedProperty.Type == MI_Type.MI_INSTANCEA || expectedProperty.Type == MI_Type.MI_REFERENCEA)
            {
                MI_Instance[] expectedArray = (MI_Instance[])expectedProperty.Value;
                MI_Instance[] actualArray   = actualProperty.Value as MI_Instance[];
                Assert.Equal(expectedArray.Length, actualArray.Length, "Expect instance/reference arrays to have the same length");
                for (int j = 0; j < expectedArray.Length; j++)
                {
                    MI_Instance expected = expectedArray[j];
                    MI_Instance actual   = actualArray[j];
                    uint        expectedElementCount;
                    expected.GetElementCount(out expectedElementCount);
                    uint actualElementCount;
                    actual.GetElementCount(out actualElementCount);
                    Assert.Equal(expectedElementCount, actualElementCount, "Expect the instance/references arrays to be of the same length");
                    for (uint i = 0; i < expectedElementCount; i++)
                    {
                        MI_Flags expectedElementFlags;
                        MI_Value expectedElementValue = null;
                        MI_Type  expectedElementType;
                        string   expectedElementName = null;
                        expected.GetElementAt(i, out expectedElementName, out expectedElementValue, out expectedElementType, out expectedElementFlags);

                        MI_Flags actualElementFlags;
                        MI_Value actualElementValue = null;
                        MI_Type  actualElementType;
                        string   actualElementName = null;
                        actual.GetElementAt(i, out actualElementName, out actualElementValue, out actualElementType, out actualElementFlags);

                        Assert.Equal(expectedElementName, actualElementName, "Expect the element names to be the same within the instances");
                        MIAssert.MIPropertiesEqual(new TestMIProperty(expectedElementValue, expectedElementType, expectedElementFlags),
                                                   new TestMIProperty(actualElementValue, actualElementType, actualElementFlags), propertyName);
                    }
                }
            }
            else if ((expectedProperty.Type & MI_TypeFlags.MI_ARRAY) == MI_TypeFlags.MI_ARRAY)
            {
                ICollection collectionValue = actualProperty.Value as ICollection;
                Assert.NotNull(collectionValue, "Expect the property value to be an ICollection since it was an MI_ARRAY");
                Assert.Equal(expectedProperty.Value as ICollection, collectionValue);
            }
            else
            {
                Assert.Equal(expectedProperty.Value, actualProperty.Value, "Expect the simple MI property values to match");
            }
        }