Пример #1
0
        public void TestXmlFeatureNullValues()
        {
            //Simulate post-#708 SELECTFEATURES and verify reader properly handles null values in response
            var bytes  = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));

            Assert.AreEqual(3, reader.FieldCount);

            reader.ReadNext();

            Assert.IsFalse(reader.IsNull(0));
            Assert.IsFalse(reader.IsNull(1));
            Assert.IsFalse(reader.IsNull(2));

            reader.ReadNext();

            Assert.IsFalse(reader.IsNull(0));
            Assert.IsFalse(reader.IsNull(1));
            Assert.IsTrue(reader.IsNull(2));

            reader.ReadNext();

            Assert.IsFalse(reader.IsNull(0));
            Assert.IsTrue(reader.IsNull(1));
            Assert.IsTrue(reader.IsNull(2));

            Assert.IsFalse(reader.ReadNext()); //end of stream

            //Test the IEnumerable approach
            reader = new XmlFeatureReader(new MemoryStream(bytes));

            int i = 0;

            foreach (var feat in reader)
            {
                switch (i)
                {
                case 0:
                    Assert.IsFalse(feat.IsNull(0));
                    Assert.IsFalse(feat.IsNull(1));
                    Assert.IsFalse(feat.IsNull(2));
                    break;

                case 1:
                    Assert.IsFalse(feat.IsNull(0));
                    Assert.IsFalse(feat.IsNull(1));
                    Assert.IsTrue(feat.IsNull(2));
                    break;

                case 2:
                    Assert.IsFalse(feat.IsNull(0));
                    Assert.IsTrue(feat.IsNull(1));
                    Assert.IsTrue(feat.IsNull(2));
                    break;
                }
                i++;
            }
        }
Пример #2
0
        public void TestXmlFeatureJoinValues()
        {
            var bytes  = Encoding.UTF8.GetBytes(Properties.Resources.FeatureJoinSelectSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));

            Assert.AreEqual(40, reader.FieldCount);

            int count = 0;

            while (reader.ReadNext())
            {
                count++;
            }
            Assert.AreEqual(63, count);
        }
Пример #3
0
        public void TestConcat()
        {
            //Test nested and variadic forms of Concat()

            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());

            var orig = exprReader["Name"].ToString();
            var value = exprReader.Evaluate("Concat(Concat(Name, 'Foo'), 'Bar')");
            var valueV = exprReader.Evaluate("Concat(Name, 'Foo', 'Bar', 'Snafu')");
            Assert.AreEqual(orig + "FooBar", value);
            Assert.AreEqual(orig + "FooBarSnafu", valueV);

            Assert.IsTrue(exprReader.ReadNext());

            var orig2 = exprReader["Name"].ToString();
            var value2 = exprReader.Evaluate("Concat(Concat(Name, 'Foo'), 'Bar')");
            var valueV2 = exprReader.Evaluate("Concat(Name, 'Foo', 'Bar', 'Snafu')");
            Assert.AreEqual(orig2 + "FooBar", value2);
            Assert.AreEqual(orig2 + "FooBarSnafu", valueV2);

            Assert.IsTrue(exprReader.ReadNext());

            var value3 = exprReader.Evaluate("Concat(Concat(Name, 'Foo'), 'Bar')");
            var valueV3 = exprReader.Evaluate("Concat(Name, 'Foo', 'Bar', 'Snafu')");
            Assert.AreEqual("FooBar", value3);
            Assert.AreEqual("FooBarSnafu", valueV3);

            Assert.IsFalse(exprReader.ReadNext());

            exprReader.Close();
        }
Пример #4
0
        public void TestXmlFeatureNullValues()
        {
            //Simulate post-#708 SELECTFEATURES and verify reader properly handles null values in response
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));

            Assert.AreEqual(3, reader.FieldCount);

            reader.ReadNext();

            Assert.IsFalse(reader.IsNull(0));
            Assert.IsFalse(reader.IsNull(1));
            Assert.IsFalse(reader.IsNull(2));

            reader.ReadNext();

            Assert.IsFalse(reader.IsNull(0));
            Assert.IsFalse(reader.IsNull(1));
            Assert.IsTrue(reader.IsNull(2));

            reader.ReadNext();

            Assert.IsFalse(reader.IsNull(0));
            Assert.IsTrue(reader.IsNull(1));
            Assert.IsTrue(reader.IsNull(2));

            Assert.IsFalse(reader.ReadNext()); //end of stream

            //Test the IEnumerable approach
            reader = new XmlFeatureReader(new MemoryStream(bytes));

            int i = 0;
            foreach (var feat in reader)
            {
                switch (i)
                {
                    case 0:
                        Assert.IsFalse(feat.IsNull(0));
                        Assert.IsFalse(feat.IsNull(1));
                        Assert.IsFalse(feat.IsNull(2));
                        break;
                    case 1:
                        Assert.IsFalse(feat.IsNull(0));
                        Assert.IsFalse(feat.IsNull(1));
                        Assert.IsTrue(feat.IsNull(2));
                        break;
                    case 2:
                        Assert.IsFalse(feat.IsNull(0));
                        Assert.IsTrue(feat.IsNull(1));
                        Assert.IsTrue(feat.IsNull(2));
                        break;
                }
                i++;
            }
        }
Пример #5
0
        public void TestXmlFeatureJoinValues()
        {
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.FeatureJoinSelectSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));

            Assert.AreEqual(40, reader.FieldCount);

            int count = 0;
            while (reader.ReadNext())
            {
                count++;
            }
            Assert.AreEqual(63, count);
        }
Пример #6
0
        public void TestTranslate()
        {
            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());
            Assert.IsTrue(exprReader.ReadNext());
            Assert.IsTrue(exprReader.ReadNext());
            Assert.IsFalse(exprReader.ReadNext());

            exprReader.Close();
        }
Пример #7
0
        public void TestNullValue()
        {
            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());

            Assert.IsTrue(!exprReader.IsNull("URL"));

            var url = exprReader["URL"];
            var value = exprReader.Evaluate("NullValue(URL, 'http://www.snafu.com')");
            Assert.NotNull(url);
            Assert.NotNull(value);
            Assert.AreEqual(url.ToString(), value.ToString());

            Assert.IsTrue(exprReader.ReadNext());

            var value2 = exprReader.Evaluate("NullValue(URL, 'http://www.foo.com')");
            Assert.NotNull(value2);
            Assert.AreEqual("http://www.foo.com", value2);

            Assert.IsTrue(exprReader.ReadNext());

            var value3 = exprReader.Evaluate("NullValue(URL, 'http://www.bar.com')");
            Assert.NotNull(value3);
            Assert.AreEqual("http://www.bar.com", value3);

            Assert.IsFalse(exprReader.ReadNext());
            exprReader.Close();
        }
Пример #8
0
        public void TestMismatch()
        {
            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());
            Assert.Catch<ExpressionException>(() => exprReader.Evaluate<bool>("CurrentDate()"));
            Assert.Catch<ExpressionException>(() => exprReader.Evaluate<bool>("'Foobar'"));
            Assert.Catch<ExpressionException>(() => exprReader.Evaluate<bool>("Power(2, 4)"));
            Assert.Catch<ExpressionException>(() => exprReader.Evaluate<string>("Foobar"));

            var dt = exprReader.Evaluate<DateTime>("CurrentDate()");
            var str = exprReader.Evaluate<string>("'Foobar'");
            var num = exprReader.Evaluate<int>("Power(2, 4)");
            var num2 = exprReader.Evaluate<float>("Power(2, 4)");

            exprReader.Close();
        }
Пример #9
0
        public void TestMathPower()
        {
            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());

            var orig = (int)exprReader["ID"];
            var value = Convert.ToDouble(exprReader.Evaluate("Power(ID, 2)"));

            Assert.AreEqual(Math.Pow(orig, 2), value);

            Assert.IsTrue(exprReader.ReadNext());

            var orig2 = (int)exprReader["ID"];
            var value2 = Convert.ToDouble(exprReader.Evaluate("Power(ID, 4)"));

            Assert.AreEqual(Math.Pow(orig2, 4), value2);

            Assert.IsTrue(exprReader.ReadNext());

            var orig3 = (int)exprReader["ID"];
            var value3 = Convert.ToDouble(exprReader.Evaluate("Power(ID, 8)"));

            Assert.AreEqual(Math.Pow(orig3, 8), value3);

            Assert.IsFalse(exprReader.ReadNext());

            exprReader.Close();
        }
Пример #10
0
        public void TestMathAsin()
        {
            //The numbers in this sample are way too large for Asin() so trim them down to size

            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());

            var orig = (int)exprReader["ID"];
            var value = Convert.ToDouble(exprReader.Evaluate("Asin(ID * 0.1)"));

            Assert.AreEqual(Math.Asin(orig * 0.1), value);

            Assert.IsTrue(exprReader.ReadNext());

            var orig2 = (int)exprReader["ID"];
            var value2 = Convert.ToDouble(exprReader.Evaluate("Asin(ID * 0.1)"));

            Assert.AreEqual(Math.Asin(orig2 * 0.1), value2);

            Assert.IsTrue(exprReader.ReadNext());

            var orig3 = (int)exprReader["ID"];
            var value3 = Convert.ToDouble(exprReader.Evaluate("Asin(ID * 0.1)"));

            Assert.AreEqual(Math.Asin(orig3 * 0.1), value3);

            Assert.IsFalse(exprReader.ReadNext());

            exprReader.Close();
        }
Пример #11
0
        public void TestCurrentDateAndAddMonths()
        {
            //TODO: Know how to calculate diffs between 2 DateTimes in months?

            var dtNow = DateTime.Now;

            //Simulate post-#708 SELECTFEATURES output and test our expression engine reader
            var bytes = Encoding.UTF8.GetBytes(Properties.Resources.SelectFeatureSample);
            var reader = new XmlFeatureReader(new MemoryStream(bytes));
            Assert.NotNull(reader.ClassDefinition);
            Assert.AreEqual(3, reader.FieldCount);
            Assert.AreEqual(3, reader.ClassDefinition.Properties.Count);
            Assert.NotNull(reader.ClassDefinition.FindProperty("ID"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("Name"));
            Assert.NotNull(reader.ClassDefinition.FindProperty("URL"));

            var exprReader = new ExpressionFeatureReader(reader);

            Assert.IsTrue(exprReader.ReadNext());

            Thread.Sleep(50);

            var dt1 = exprReader.Evaluate("CurrentDate()");
            Assert.NotNull(dt1);
            Trace.WriteLine("dt1: " + dt1.ToString());
            Assert.AreEqual(typeof(DateTime), dt1.GetType());
            Assert.IsTrue((DateTime)dt1 > dtNow);

            var fut1 = exprReader.Evaluate("AddMonths(CurrentDate(), 3)");
            Assert.NotNull(fut1);
            Trace.WriteLine("fut1: " + fut1.ToString());

            var past1 = exprReader.Evaluate("AddMonths(CurrentDate(), -3)");
            Assert.NotNull(past1);
            Trace.WriteLine("past1: " + past1.ToString());

            Thread.Sleep(50);

            Assert.IsTrue(exprReader.ReadNext());

            var dt2 = exprReader.Evaluate("CurrentDate()");
            Assert.NotNull(dt2);
            Trace.WriteLine("dt2: " + dt2.ToString());
            Assert.AreEqual(typeof(DateTime), dt2.GetType());
            Assert.IsTrue((DateTime)dt2 > (DateTime)dt1);

            var fut2 = exprReader.Evaluate("AddMonths(CurrentDate(), 3)");
            Assert.NotNull(fut2);
            Trace.WriteLine("fut2: " + fut2.ToString());

            var past2 = exprReader.Evaluate("AddMonths(CurrentDate(), -3)");
            Assert.NotNull(past2);
            Trace.WriteLine("past2: " + past2.ToString());

            Thread.Sleep(50);

            Assert.IsTrue(exprReader.ReadNext());

            var dt3 = exprReader.Evaluate("CurrentDate()");
            Assert.NotNull(dt3);
            Trace.WriteLine("dt2: " + dt3.ToString());
            Assert.AreEqual(typeof(DateTime), dt3.GetType());
            Assert.IsTrue((DateTime)dt3 > (DateTime)dt2);

            var fut3 = exprReader.Evaluate("AddMonths(CurrentDate(), 3)");
            Assert.NotNull(fut3);
            Trace.WriteLine("fut3: " + fut3.ToString());

            var past3 = exprReader.Evaluate("AddMonths(CurrentDate(), -3)");
            Assert.NotNull(past3);
            Trace.WriteLine("past3: " + past3.ToString());

            Thread.Sleep(50);

            Assert.IsFalse(exprReader.ReadNext()); //end of stream

            exprReader.Close();
        }