コード例 #1
0
        private string ArePoliciesDifferent(IPolicyObjectCollection<IPolicy> lhs, IPolicyObjectCollection<IPolicy> rhs)
        {
            if (lhs.Count != rhs.Count)
            {
                PolicyLogger logger = new PolicyLogger(m_testPath);
                logger.WritePolicies("lhs", lhs);
                logger.WritePolicies("rhs", rhs);
                return string.Format("Expected the resultant policy set to have the same amount of policies as the expected policy set. Expected {0} but got {1}", lhs.Count, rhs.Count);
            }

            System.Collections.IEnumerator lhsPoliciesEnumerator = lhs.GetEnumerator();
            System.Collections.IEnumerator rhsPoliciesEnumerator = rhs.GetEnumerator();
            while (lhsPoliciesEnumerator.MoveNext() && rhsPoliciesEnumerator.MoveNext())
            {
                IPolicy lhsPolicy = lhsPoliciesEnumerator.Current as IPolicy;
                IPolicy rhsPolicy = rhsPoliciesEnumerator.Current as IPolicy;

                string errorMessage = DoConditonsMatch(lhsPolicy.Conditions, rhsPolicy.Conditions);
                if (string.Empty != errorMessage)
                {
                    return errorMessage;
                }

                if (lhsPolicy.Channels.Count != rhsPolicy.Channels.Count)
                {
                    return "The policy channels have not been copied across";
                }
            }

            return string.Empty;
        }
コード例 #2
0
        private string DoConditonsMatch(IPolicyObjectCollection<IPolicyObject> lhsConditions, IPolicyObjectCollection<IPolicyObject> rhsConditions)
        {
            if (lhsConditions.Count != rhsConditions.Count)
            {
                return string.Format("The resultant policy does not contain the expected number of conditions. Expected {0} but got {1}", lhsConditions.Count, rhsConditions.Count);
            }
            
            System.Collections.IEnumerator lhsConditionsEnumerator = lhsConditions.GetEnumerator();
            System.Collections.IEnumerator rhsConditionsEnumerator = rhsConditions.GetEnumerator();
            while (lhsConditionsEnumerator.MoveNext() && rhsConditionsEnumerator.MoveNext())
            {
                IPolicyObject lhsCondition = lhsConditionsEnumerator.Current as IPolicyObject;
                IPolicyObject rhsCondition = rhsConditionsEnumerator.Current as IPolicyObject;

                if (rhsCondition is ICondition)
                {
                    if (0 != string.Compare(lhsCondition.Name.Value, rhsCondition.Name.Value, true))
                    {
                        return "The expression names do not match the expected expression names";
                    }
                    else if (!AreConditionsEqual(lhsCondition as ICondition, rhsCondition as ICondition))
                    {
                        return "The expression date do not match the expected expression data";
                    }
                }
                else if (rhsCondition is IConditionGroup)
                {
                    string errorMessage = DoConditonsMatch((lhsCondition as IConditionGroup).Conditions, (rhsCondition as IConditionGroup).Conditions);
                    if (string.Empty != errorMessage)
                    {
                        return errorMessage;
                    }
                }
            }
            return string.Empty;
        }