Exemple #1
0
        public void Evaluate_NullSourceObjects_ExpectedResult()
        {
            bool actualValue =
                (bool)OPathNavigator.Evaluate(null, OPathExpression.Compile("true()"));

            Assert.AreEqual(true, actualValue, "true()");
        }
Exemple #2
0
 public void Evaluate_ExpressionMethodException_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"ExceptionThrower\.Method\(\).*Method exception"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"ExceptionThrower.Method() = null"));
     });
 }
Exemple #3
0
 public void Evaluate_SingleValuePropertyException_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"ExceptionThrower\.Property.*Property exception"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"ExceptionThrower.Property"));
     });
 }
Exemple #4
0
 public void Evaluate_NullReferenceInObjectPath_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"NullObject.*null"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"NullObject.Property = null"));
     });
 }
Exemple #5
0
 public void Evaluate_UnclosedBracket_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"\(true\(\) = false\(\).*has an invalid token"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"(true() = false()"));
     });
 }
Exemple #6
0
 public void Evaluate_UnclosedIndexer_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"Invalid character in indexer"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"NonEmptyIntList[0 = 0"));
     });
 }
Exemple #7
0
 public void Evaluate_UnclosedString_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"Unclosed string"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"NonEmptyString = X"""));
     });
 }
Exemple #8
0
 public void Evaluate_NonExistantStringIndex_ExpectedExpectation()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"EmptyDictionary\[""Lucifer""\].*EmptyDictionary.*Lucifer.*key not found"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"EmptyDictionary[""Lucifer""] = 0"));
     });
 }
Exemple #9
0
 public void Evaluate_ArrayIndexOutOfBounds_ExpectedExpectation()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"EmptyIntArray\[616\].*EmptyIntArray.*616.*index out of range"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile("EmptyIntArray[616] = 0"));
     });
 }
Exemple #10
0
 public void Evaluate_NonExistantIntIndexer_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"EmptyString\[0\].*EmptyString.*System\.String.*int indexer"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument, OPathExpression.Compile(@"EmptyString[0] = 0"));
     });
 }
Exemple #11
0
 public void Evaluate_UnspecifiedObject_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"UnspecifiedObject"),
                   () =>
     {
         OPathNavigator.Evaluate(new OPathDocument(), OPathExpression.Compile("UnspecifiedObject = 0"));
     });
 }
Exemple #12
0
 public void Evaluate_NonExistantEmptyMethod_ExpectedException()
 {
     Assert.Throws(Is.TypeOf <OPathException>()
                   .And.Message.Matches(@"EmptyString\.NonExistantEmptyMethod().*EmptyString.*System\.String.*NonExistantEmptyMethod"),
                   () =>
     {
         OPathNavigator.Evaluate(m_OPathDocument,
                                 OPathExpression.Compile("EmptyString.NonExistantEmptyMethod() = 0"));
     });
 }
Exemple #13
0
        private void AssertExpressionEquals(object expectedValue, string expression,
                                            OPathOptions opathOptions, object defaultValue)
        {
            OPathExpression opathExpression = OPathExpression.Compile(expression);

            object actualValue =
                OPathNavigator.Evaluate(m_OPathDocument, opathExpression, opathOptions, defaultValue,
                                        (string message) => Console.WriteLine(message));

            Assert.AreEqual(expectedValue, actualValue, expression);
        }
Exemple #14
0
        public void TestOPathPerformance()
        {
            HiPerfTimer rawTimer = new HiPerfTimer();

            rawTimer.Start();

            for (int i = 0; i < EVALUATION_COUNT; i++)
            {
                OPathExpression opathExpression = OPathExpression.Compile(EXPRESSION);

                OPathDocument opathDocument = new OPathDocument();
                opathDocument.Add("listDictionary", m_ListDictionary);

                OPathNavigator opathNavigator = OPathNavigator.CreateNavigator(opathDocument);

                opathNavigator.Evaluate(opathExpression);
            }

            rawTimer.Stop();

            Console.WriteLine("Uncompiled OPath performance {0} evaluations in {1:0.000} millis",
                              EVALUATION_COUNT, (rawTimer.Duration * 1000));

            HiPerfTimer cachedTimer = new HiPerfTimer();

            cachedTimer.Start();

            OPathExpression cachedOPathExpression = OPathExpression.Compile(EXPRESSION);

            for (int i = 0; i < EVALUATION_COUNT; i++)
            {
                OPathDocument opathDocument = new OPathDocument();
                opathDocument.Add("listDictionary", m_ListDictionary);

                OPathNavigator opathNavigator = OPathNavigator.CreateNavigator(opathDocument);

                opathNavigator.Evaluate(cachedOPathExpression);
            }

            cachedTimer.Stop();

            Console.WriteLine("Compiled OPath performance {0} evaluations in {1:0.000} millis",
                              EVALUATION_COUNT, (cachedTimer.Duration * 1000));
        }