public bool Eval(object val)
        {
            if (!(val is Hashtable))
            {
                message = "Expected Hashtable but was " + val.GetType().FullName;
                return false;
            }

            Hashtable obtained = val as Hashtable;

            if (expected.Keys.Count != obtained.Keys.Count)
            {
                message = string.Format("Expected {0} keys but found {1}", expected.Keys.Count, obtained.Keys.Count);
                return false;
            }

            foreach (object expectedKey in expected.Keys)
            {
                if (!obtained.ContainsKey(expectedKey))
                {
                    message = "Expected to contain key " + expectedKey;
                    return false;
                }

                if (expected[expectedKey] is IConstraint)
                {
                    IConstraint ic = (IConstraint) expected[expectedKey];
                    bool constraint = ic.Eval(obtained[expectedKey]);
                    message = ic.Message;
                    return constraint;
                }

                if (expected[expectedKey] is Array)
                {
                    ArrayConstraint ac = new ArrayConstraint((object[]) expected[expectedKey]);
                    bool constraint = ac.Eval(obtained[expectedKey]);
                    message = ac.Message;
                    return constraint;
                }

                if (!object.Equals(expected[expectedKey], obtained[expectedKey]))
                {
                    message =
                        string.Format("Expected {0} to be {1} but was {2}", expectedKey, expected[expectedKey], obtained[expectedKey]);
                    return false;
                }
            }

            return true;
        }
        public bool Eval(object val)
        {
            if (!(val is Hashtable))
            {
                message = "Expected Hashtable but was " + val.GetType().FullName;
                return(false);
            }

            Hashtable obtained = val as Hashtable;

            if (expected.Keys.Count != obtained.Keys.Count)
            {
                message = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Expected {0} keys but found {1}", expected.Keys.Count, obtained.Keys.Count);
                return(false);
            }

            foreach (object expectedKey in expected.Keys)
            {
                if (!obtained.ContainsKey(expectedKey))
                {
                    message = "Expected to contain key " + expectedKey;
                    return(false);
                }

                if (expected[expectedKey] is IConstraint)
                {
                    IConstraint ic         = (IConstraint)expected[expectedKey];
                    bool        constraint = ic.Eval(obtained[expectedKey]);
                    message = ic.Message;
                    return(constraint);
                }

                if (expected[expectedKey] is Array)
                {
                    ArrayConstraint ac         = new ArrayConstraint((object[])expected[expectedKey]);
                    bool            constraint = ac.Eval(obtained[expectedKey]);
                    message = ac.Message;
                    return(constraint);
                }

                if (!object.Equals(expected[expectedKey], obtained[expectedKey]))
                {
                    message =
                        string.Format(System.Globalization.CultureInfo.CurrentCulture, "Expected {0} to be {1} but was {2}", expectedKey, expected[expectedKey], obtained[expectedKey]);
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        public bool Eval(object val)
        {
            if (!(val is Array))
            {
                message = "Expected Array but was " + val.GetType().FullName;
                return false;
            }

            object[] obtained = (object[]) val;

            if (expected.Length != obtained.Length)
            {
                message = string.Format("Expected {0} values but found {1}", expected.Length, obtained.Length);
                return false;
            }

            for (int i = 0; i < expected.Length; i++)
            {
                if (expected[i] is IConstraint)
                {
                    IConstraint ic = (IConstraint) expected[i];
                    bool constraint = ic.Eval(obtained[i]);
                    message = ic.Message;
                    return constraint;
                }

                if (expected[i] is Array)
                {
                    ArrayConstraint ac = new ArrayConstraint((object[]) expected[i]);
                    bool constraint = ac.Eval(obtained[i]);
                    message = ac.Message;
                    return constraint;
                }

                if (!expected[i].Equals(obtained[i]))
                {
                    message = string.Format("Expected {0} but was {1}", expected[i], obtained[i]);
                    return false;
                }
            }
            return true;
        }
예제 #4
0
        public bool Eval(object val)
        {
            if (!(val is Array))
            {
                message = "Expected Array but was " + val.GetType().FullName;
                return(false);
            }

            object[] obtained = (object[])val;

            if (expected.Length != obtained.Length)
            {
                message = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Expected {0} values but found {1}", expected.Length, obtained.Length);
                return(false);
            }

            for (int i = 0; i < expected.Length; i++)
            {
                if (expected[i] is IConstraint)
                {
                    IConstraint ic         = (IConstraint)expected[i];
                    bool        constraint = ic.Eval(obtained[i]);
                    message = ic.Message;
                    return(constraint);
                }

                if (expected[i] is Array)
                {
                    ArrayConstraint ac         = new ArrayConstraint((object[])expected[i]);
                    bool            constraint = ac.Eval(obtained[i]);
                    message = ac.Message;
                    return(constraint);
                }

                if (!expected[i].Equals(obtained[i]))
                {
                    message = string.Format(System.Globalization.CultureInfo.CurrentCulture, "Expected {0} but was {1}", expected[i], obtained[i]);
                    return(false);
                }
            }
            return(true);
        }