Ejemplo n.º 1
0
        public void Array_Create_BadDateTimeKind()
        {
            // Testing the detection of bad DateTime kind as an array is being created.

            var columns = new List <Item_Array.ArrayColumn>()
            {
                new Item_Array.ArrayColumn(typeof(DateTime), "DateTimeCol")
                {
                    Label       = "Label for DateTime",
                    Description = "Desc for DateTime"
                },
                new Item_Array.ArrayColumn(typeof(double), "DoubleCol")
                {
                    Label       = "Label for double",
                    Description = "Desc for double"
                }
            };

            var arrayItem = new Item_Array(columns);

            // This does not have UTC as the kind
            var dateTime1 = ParseDateTimeInUtc("2019-01-11T00:11:19Z").ToLocalTime();

            try
            {
                arrayItem.Add(dateTime1, -4.2);
                Assert.Fail("Expected an exception");
            }
            catch (XNeut.DateTimeException) { }
        }
Ejemplo n.º 2
0
        private Item_Array CreateArrayForTest()
        {
            // Creating the test array in a separate method to prevent asserting the
            // wrong object

            var columns = new List <Item_Array.ArrayColumn>()
            {
                new Item_Array.ArrayColumn(typeof(bool), "BoolCol")
                {
                    Label       = "Label for bool",
                    Description = "Desc for bool"
                },
                new Item_Array.ArrayColumn(typeof(DateTime), "DateTimeCol")
                {
                    Label       = "Label for DateTime",
                    Description = "Desc for DateTime"
                },
                new Item_Array.ArrayColumn(typeof(double), "DoubleCol", "Cel")
                {
                    Label       = "Label for double",
                    Description = "Desc for double"
                },
                new Item_Array.ArrayColumn(typeof(long), "LongCol")
                {
                    Label       = "Label for long",
                    Description = "Desc for long"
                },
                new Item_Array.ArrayColumn(typeof(string), "StringCol")
                {
                    Label       = "Label for string",
                    Description = "Desc for string"
                },
                new Item_Array.ArrayColumn(typeof(string), "NoLabelOrDescCol")
            };

            var dateTime1 = ParseDateTimeInUtc("2019-01-11T00:11:19Z");
            var dateTime2 = ParseDateTimeInUtc("2019-01-12T00:11:19Z");

            var arrayItem = new Item_Array(columns)
            {
                { true, dateTime1, -4.2, (long)68, "string 1", "emptyname 1" },
                { false, dateTime2, 0.0, (long)0, "string 2", "emptyname 2" },
                { null, null, null, null, null, null },
                { "  ", " ", "   ", " ", " ", "    " }
            };

            // Serialising and deserialising
            return((Item_Array)SerialiseAndReadResultObj(arrayItem, XNeut.Helper.TypeUri_Complex));
        }
Ejemplo n.º 3
0
        public void Array_Read_NoColumns()
        {
            // Testing if reading succeeds when the document has no columns

            var filepath = TestCommon.TestHelper.TestFileFolder + "\\Item_Array_NoColumns.xml";

            // Getting result element
            var resultEl = (XsdNs.DataArrayType)ParseRawResult(filepath);

            var testObject = new Item_Array(resultEl);

            // Asserting counts
            Assert.AreEqual(0, testObject.Columns.Count);
            Assert.AreEqual(2, testObject.RowCount);
        }
Ejemplo n.º 4
0
        public void Array_Create_NoRows()
        {
            // Testing the creation of an array without rows

            var columns = new List <Item_Array.ArrayColumn>()
            {
                new Item_Array.ArrayColumn(typeof(bool), "BoolCol"),
                new Item_Array.ArrayColumn(typeof(long), "CountCol")
            };
            var arrayItem = new Item_Array(columns);

            var arrayItemIn = (Item_Array)SerialiseAndReadResultObj(arrayItem, XNeut.Helper.TypeUri_Complex);

            Assert.AreEqual(2, arrayItemIn.Columns.Count);
            Assert.AreEqual(0, arrayItemIn.RowCount);
        }
Ejemplo n.º 5
0
        public void Array_Create_NoColumns()
        {
            // Testing the creation of an array without columns

            var arrayItem = new Item_Array(new List <Item_Array.ArrayColumn>());

            // Adding 3 empty rows
            arrayItem.Add();
            arrayItem.Add();
            arrayItem.Add();

            var arrayItemIn = (Item_Array)SerialiseAndReadResultObj(arrayItem, XNeut.Helper.TypeUri_Complex);

            Assert.AreEqual(0, arrayItemIn.Columns.Count);
            Assert.AreEqual(3, arrayItemIn.RowCount);
        }
Ejemplo n.º 6
0
        public void Array_Read_LabelAndDescription()
        {
            // Testing the reading of label and description of columns

            var filepath = TestCommon.TestHelper.TestFileFolder + "\\Item_Array_LabelAndDesc.xml";

            var resultEl   = (XsdNs.DataArrayType)ParseRawResult(filepath);
            var testObject = new Item_Array(resultEl);

            Assert.AreEqual(5, testObject.Columns.Count);

            // Testing description and label for each supported column type
            Assert.AreEqual("Boolean col", testObject.Columns[0].Label);
            Assert.AreEqual("Time col", testObject.Columns[1].Label);
            Assert.AreEqual("Count col", testObject.Columns[2].Label);
            Assert.AreEqual("Measurement col", testObject.Columns[3].Label);
            Assert.AreEqual("Text col", testObject.Columns[4].Label);
            Assert.AreEqual("Boolean desc", testObject.Columns[0].Description);
            Assert.AreEqual("Time desc", testObject.Columns[1].Description);
            Assert.AreEqual("Count desc", testObject.Columns[2].Description);
            Assert.AreEqual("Measurement desc", testObject.Columns[3].Description);
            Assert.AreEqual("Text desc", testObject.Columns[4].Description);
        }
Ejemplo n.º 7
0
        public void Array_Read()
        {
            // Testing a typical read with all data types included

            var filepath = TestCommon.TestHelper.TestFileFolder + "\\Item_Array.xml";

            // Getting result element
            var resultEl = (XsdNs.DataArrayType)ParseRawResult(filepath);

            var testObject = new Item_Array(resultEl);

            // Asserting counts
            Assert.AreEqual(6, testObject.Columns.Count);
            Assert.AreEqual(3, testObject.RowCount);

            var col1 = testObject.Columns[0];
            var col2 = testObject.Columns[1];
            var col3 = testObject.Columns[2];
            var col4 = testObject.Columns[3];
            var col5 = testObject.Columns[4];
            var col6 = testObject.Columns[5];

            // Asserting columns types
            Assert.AreEqual(typeof(bool), col1.DataType);
            Assert.AreEqual(typeof(DateTime), col2.DataType);
            Assert.AreEqual(typeof(long), col3.DataType);
            Assert.AreEqual(typeof(double), col4.DataType);
            Assert.AreEqual(typeof(string), col5.DataType);
            Assert.AreEqual(typeof(string), col6.DataType); // Unsupported column type maps to string

            // Asserting if datatype is supported
            Assert.IsTrue(col1.DataTypeSupported);
            Assert.IsTrue(col2.DataTypeSupported);
            Assert.IsTrue(col3.DataTypeSupported);
            Assert.IsTrue(col4.DataTypeSupported);
            Assert.IsTrue(col5.DataTypeSupported);
            Assert.IsFalse(col6.DataTypeSupported);

            // Asserting column names
            Assert.AreEqual("BooleanCol", col1.Name);
            Assert.AreEqual("TimeCol", col2.Name);
            Assert.AreEqual("CountCol", col3.Name);
            Assert.AreEqual("MeasurementCol", col4.Name);
            Assert.AreEqual("TextCol", col5.Name);
            Assert.AreEqual("CategoryRangeCol", col6.Name);

            // Asserting boolean values
            Assert.IsTrue((bool)testObject[0][0]);
            Assert.IsFalse((bool)testObject[1][0]);

            // Asserting DateTime values
            AssertDateTime(ParseDateTimeInUtc("2018-02-06T09:58:44.00Z"), (DateTime)testObject[0][1]);
            AssertDateTime(ParseDateTimeInUtc("2018-02-06T09:58:45.00Z"), (DateTime)testObject[1][1]);

            // Asserting long values
            Assert.AreEqual(3, (long)testObject[0][2]);
            Assert.AreEqual(-5, (long)testObject[1][2]);

            // Asserting double values
            Assert.AreEqual(-0.12, (double)testObject[0][3], 0.00001);
            Assert.AreEqual(14, (double)testObject[1][3], 0.00001);

            // Asserting unit of measure
            Assert.AreEqual("cm", testObject.Columns[3].UnitOfMeasure);

            // Asserting string values
            Assert.AreEqual("abc", testObject[0][4]);

            // Asserting category range values (unsupported data types are presented as string)
            Assert.AreEqual("a o", testObject[0][5]);

            // Asserting empty (null) values
            Assert.IsNull(testObject[1][4]);
            Assert.IsNull(testObject[2][0]);
            Assert.IsNull(testObject[2][1]);
            Assert.IsNull(testObject[2][2]);
            Assert.IsNull(testObject[2][3]);
            Assert.IsNull(testObject[2][4]);
            Assert.IsNull(testObject[2][5]);
        }