Beispiel #1
0
        public void WriteTraceIrregular()
        {
            // All database changes should be directed into these temp tables, since the tested methods
            // use SqlBulkCopy, which is not subject to transaction scope.
            CreateTempTables();

            DateTime startDate = DateTime.Parse("2/10/2000");
            DateTime endDate = DateTime.Parse("2/10/2002");
            int      timeStepCount = 40;
            int      id, traceNumber = 27;

            String extraParamNames  = "TimeSeriesType, Unit_Id, RunGUID, VariableType, VariableName, RunElementGUID";
            String extraParamValues = "0, 1, 'A0101010-AAAA-BBBB-2222-3E3E3E3E3E3E', 0, 'eraseme', '00000000-0000-0000-0000-000000000000'";

            id = _lib.WriteParametersIrregular(_connxNumber, GetSbyte(_TestParamTableName), GetSbyte(_TestTraceTableName),
                                               timeStepCount, startDate, endDate, GetSbyte(extraParamNames), GetSbyte(extraParamValues));

            TSDateValueStruct[] dateValArray = new TSDateValueStruct[timeStepCount],
            testDateValArray = new TSDateValueStruct[timeStepCount];
            double   x       = 10.0;
            double   y       = 1.0;
            DateTime curDate = startDate;

            for (int i = 0; i < timeStepCount; i++)
            {
                dateValArray[i].Value = x;
                dateValArray[i].Date  = curDate;
                x      *= 1.2;
                y      += 0.5;
                curDate = curDate.AddDays(y);
            }
            // The method being tested
            _lib.WriteTraceIrregular(_connxNumber, GetSbyte(_TestParamTableName), GetSbyte(_TestTraceTableName),
                                     id, traceNumber, dateValArray);
            _lib.CommitTraceWrites(_connxNumber, GetSbyte(_TestParamTableName), GetSbyte(_TestTraceTableName));

            String comm = String.Format("select * from {0} where TimeSeries_Id={1} and TraceNumber={2}",
                                        _TestTraceTableName, id, traceNumber);

            // SqlDataAdapter object will use the query to fill the DataTable
            using (SqlDataAdapter adp = new SqlDataAdapter(comm, _connx))
            {
                DataTable dTable = new DataTable();
                // Execute the query to fill the DataTable object
                adp.Fill(dTable);
                DataRow row  = dTable.Rows[0];
                byte[]  blob = row.Field <byte[]>("ValueBlob");
                TSBlobCoder.ConvertBlobToArrayIrregular(timeStepCount,
                                                        false, 0, startDate, startDate, blob, testDateValArray, TSBlobCoder.currentCompressionCode);
                //
                for (int i = 0; i < timeStepCount; i++)
                {
                    Assert.AreEqual(dateValArray[i], testDateValArray[i]);
                }
            }
        }
        // Note--this test class was created primarily b/c we wanted to individually test the different
        // compression methods.  Hence, we have created the test methods below.  The class TSBlobCoder
        // certainly deserves full test coverage, but that can be developed later.  In the meantime,
        // it is generally expected that TSBlobCoder has adequate test coverage via TSLibraryTest.

        #region Test Methods for ConvertBlobToListAll() and ConvertListToBlob()
        // The series of tests below is for ConvertBlobToListAll and ConvertListToBlob.
        // The tests take advantage of the fact that the methods are designed so that
        // the series that is put into the BLOB must be identical to the series that
        // comes out of the BLOB.

        // This method is re-used by the actual test methods that follow.
        public void ConvertBlobAll(List <TimeSeriesValue> inList,
                                   TSDateCalculator.TimeStepUnitCode timeStepUnit, short timeStepQuantity,
                                   DateTime blobStartDate, int compressionCode)
        {
            TSLibrary tsLib = new TSLibrary();

            var traceObject = new TSTrace
            {
                TraceNumber   = 1,
                TimeStepCount = inList.Count,
                EndDate       = inList.Last().Date
            };

            if (timeStepUnit == TSDateCalculator.TimeStepUnitCode.Irregular)
            {
                var    inArray  = inList.Select(v => (TSDateValueStruct)v).ToArray();
                var    outArray = new TSDateValueStruct[inList.Count];
                byte[] blobData = TSBlobCoder.ConvertArrayToBlobIrregular(inArray,
                                                                          compressionCode, traceObject);

                int ret = TSBlobCoder.ConvertBlobToArrayIrregular(inList.Count,
                                                                  false, 0, blobStartDate, blobStartDate,
                                                                  blobData, outArray, compressionCode);

                // The return value of the function must match the number of items in the original list
                Assert.AreEqual(ret, inList.Count);
                // the count in both lists must match
                Assert.AreEqual(inArray.Length, outArray.Length);
                // now check each item in the two lists
                Boolean AreEqual = true;
                for (int i = 0; i < ret; i++)
                {
                    if (outArray[i].Date != inArray[i].Date || outArray[i].Value != inArray[i].Value)
                    {
                        AreEqual = false;
                    }
                }
                Assert.IsTrue(AreEqual);
            }
            else
            {
                var    inArray  = inList.Select(v => v.Value).ToArray();
                var    outArray = new Double[inList.Count];
                byte[] blobData = TSBlobCoder.ConvertArrayToBlobRegular(inArray,
                                                                        compressionCode, traceObject);

                int ret = TSBlobCoder.ConvertBlobToArrayRegular(timeStepUnit, timeStepQuantity,
                                                                inList.Count, blobStartDate,
                                                                false, 0, blobStartDate, blobStartDate,
                                                                blobData, outArray, compressionCode);

                // The return value of the function must match the number of items in the original list
                Assert.AreEqual(ret, inList.Count);
                // the count in both lists must match
                Assert.AreEqual(inArray.Length, outArray.Length);
                // now check each item in the two lists
                Boolean AreEqual = true;
                for (int i = 0; i < ret; i++)
                {
                    if (outArray[i] != inArray[i])
                    {
                        AreEqual = false;
                    }
                }
                Assert.IsTrue(AreEqual);
            }
        }