Exemple #1
0
        public void DeserializeBodyTest()
        {
            List <BaseColumnModel>      columnModels;
            IList <QueryTablePacketDTO> bodyPackets = new List <QueryTablePacketDTO>();

            using (var manager = new DbManager(new SqlDataProvider(), Config.GetSetting("TestConnectionString")))
            {
                using (IDbCommand command = manager.Connection.CreateCommand())
                {
                    command.CommandText = @"select  * from dbo.AVR_HumanCaseReport";
                    using (IDataReader reader = command.ExecuteReader())
                    {
                        columnModels = BinarySerializer.GetSchemaColumnModels(reader.GetSchemaTable());
                        BinarySerializer.SerializeHeader(columnModels, false);
                        QueryTablePacketDTO packet = BinarySerializer.SerializeBodyPacket(reader, columnModels, false, 10);
                        while (packet.RowCount != 0)
                        {
                            bodyPackets.Add(packet);
                            packet = BinarySerializer.SerializeBodyPacket(reader, columnModels, false, 10);
                        }
                    }
                }
            }
            Assert.AreEqual(4, bodyPackets.Count);
            Type[] types = columnModels.Select(c => c.FinalType).ToArray();

            AvrDataTable array = new AvrDataTable(new DataTable());

            for (int i = 0; i < 4; i++)
            {
                BinarySerializer.DeserializeBodyPacket(bodyPackets[i], types, array);
            }
            array.AcceptChanges();
            Assert.AreEqual(31, array.Count);
            Assert.AreEqual(54, array[0].Count);

            AvrDataRowEx row3 = (AvrDataRowEx)array[3];

            Assert.AreEqual(typeof(string), row3[53].GetType());
            Assert.AreEqual("2", row3[53].ToString());

            AvrDataRowEx row5 = (AvrDataRowEx)array[5];

            Assert.AreEqual(typeof(DateTime), row5[50].GetType());
            Assert.AreEqual(2010, ((DateTime)row5[50]).Year);

            AvrDataRowEx row8 = (AvrDataRowEx)array[8];

            Assert.AreEqual(typeof(decimal), row8[52].GetType());
            Assert.AreEqual(0m, row8[52]);

            AvrDataRowEx row = (AvrDataRowEx)array[30];

            Assert.AreEqual(new DateTime(1990, 02, 01), row[0]);
            Assert.AreEqual(23, row[1]);
            Assert.AreEqual(DBNull.Value, row[3]);
            Assert.AreEqual("xxx", row[4]);
            Assert.AreEqual("Male", row[6]);
            Assert.AreEqual(DBNull.Value, row[7]);
            Assert.AreEqual(DateTime.Now.Year, ((DateTime)row[50]).Year);
            Assert.AreEqual(DateTime.Now.Year, row[51]);
            Assert.AreEqual(25460000000m, row[52]);
            Assert.AreEqual("Yes", row[53]);
        }
Exemple #2
0
        public void SerializeIntegrationTest()
        {
            QueryTableModel tableModel;

            using (var manager = new DbManager(new SqlDataProvider(), Config.GetSetting("TestConnectionString")))
            {
                using (DbManager command = manager.SetCommand(@"select  * from dbo.AVR_HumanCaseReport"))
                {
                    tableModel = BinarySerializer.SerializeFromCommand(command, 123, "en", false, 10);
                }
            }

            Assert.AreEqual(54, tableModel.Header.RowCount);
            Assert.AreEqual(false, tableModel.UseArchivedData);
            Assert.AreEqual(false, tableModel.Header.IsArchive);

            QueryTablePacketDTO zippedHeader = BinaryCompressor.Zip(tableModel.Header);

            Assert.AreEqual(false, zippedHeader.IsArchive);
            List <QueryTablePacketDTO> zippedBody = tableModel.BodyPackets.Select(BinaryCompressor.Zip).ToList();

            Assert.IsFalse(zippedBody.Any(p => p.IsArchive));

            QueryTablePacketDTO unzipedHeader = BinaryCompressor.Unzip(zippedHeader);

            Assert.AreEqual(false, unzipedHeader.IsArchive);
            List <QueryTablePacketDTO> unzippedBody = zippedBody.Select(BinaryCompressor.Unzip).ToList();

            Assert.IsFalse(unzippedBody.Any(p => p.IsArchive));

            List <BaseColumnModel> resultHeader = BinarySerializer.DeserializeHeader(unzipedHeader);

            Assert.IsTrue(resultHeader.Exists(c => c.Name == "sflHC_PatientDOB"));
            Assert.IsTrue(resultHeader.Exists(c => c.Name == "sflHC_PatientSex_ID"));
            Assert.IsTrue(resultHeader.Exists(c => c.Name == "sflHC_LabDiagBasis"));
            Assert.AreEqual(typeof(DateTime), resultHeader.Find(c => c.Name == "sflHC_PatientDOB").FinalType);
            Assert.AreEqual(typeof(long), resultHeader.Find(c => c.Name == "sflHC_PatientSex_ID").FinalType);
            Assert.AreEqual(typeof(string), resultHeader.Find(c => c.Name == "sflHC_LabDiagBasis").FinalType);

            Type[] types = resultHeader.Select(c => c.FinalType).ToArray();

            AvrDataTable resultBody = new AvrDataTable(new DataTable());

            foreach (var packetDTO in unzippedBody)
            {
                BinarySerializer.DeserializeBodyPacket(packetDTO, types, resultBody);
            }

            Assert.AreEqual(31, resultBody.Count);
            Assert.AreEqual(54, resultBody[0].Count);

            AvrDataRowEx row = (AvrDataRowEx)resultBody[30];

            Assert.AreEqual(new DateTime(1990, 02, 01), row[0]);
            Assert.AreEqual(23, row[1]);
            Assert.AreEqual(DBNull.Value, row[3]);
            Assert.AreEqual("xxx", row[4]);
            Assert.AreEqual("Male", row[6]);
            Assert.AreEqual(DBNull.Value, row[7]);
            Assert.AreEqual(DateTime.Now.Year, ((DateTime)row[50]).Year);
            Assert.AreEqual(DateTime.Now.Year, row[51]);
            Assert.AreEqual(25460000000m, row[52]);
            Assert.AreEqual("Yes", row[53]);
        }
Exemple #3
0
        public void GetCachedQueryTest()
        {
            AVRFacade facade;

            using (new StopwathTransaction("AVRFacade .ctor"))
            {
                facade = new AVRFacade(m_Container);
            }
            QueryTableHeaderDTO headerDTO;

            using (new StopwathTransaction("GetCachedQueryTableHeader"))
            {
                //fn_AVR_HumanCaseReport
                headerDTO = facade.GetCachedQueryTableHeader(49539640000000, "en", false);
            }
            var headerModel = new QueryTableHeaderModel(headerDTO);

            Assert.AreEqual(m_FieldCount, headerModel.ColumnCount);
            Assert.IsTrue(headerModel.ColumnTypeByName.Exists(c => c.Name == "sflHC_FinalDiagnosis"));
            Type stringType = headerModel.ColumnTypeByName.Find(c => c.Name == "sflHC_FinalDiagnosis").FinalType;

            Assert.AreEqual(typeof(string), stringType);
            Assert.IsTrue(headerModel.ColumnTypeByName.Exists(c => c.Name == "sflHC_FinalDiagnosisDate"));
            stringType = headerModel.ColumnTypeByName.Find(c => c.Name == "sflHC_FinalDiagnosisDate").FinalType;
            Assert.AreEqual(typeof(DateTime), stringType);

            for (int i = 0; i < headerDTO.PacketCount; i++)
            {
                QueryTablePacketDTO packetDTO;
                using (new StopwathTransaction("GetCachedQueryTablePacket " + i))
                {
                    packetDTO = facade.GetCachedQueryTablePacket(headerModel.QueryCacheId, i, headerDTO.PacketCount);
                }
                QueryTablePacketDTO unzipped;
                using (new StopwathTransaction(string.Format("-Unzip Packet #{0}", i)))
                {
                    unzipped = BinaryCompressor.Unzip(packetDTO);
                }
                StreamTablePacketDTO unzippedStream;
                using (new StopwathTransaction(string.Format("-Unzip Packet #{0} into stream", i)))
                {
                    unzippedStream = BinaryCompressor.UnzipStream(packetDTO);
                }

                AvrDataTable deserialized = new AvrDataTable(headerModel, 10240);
                using (new StopwathTransaction(string.Format("--Deserialize Packet #{0}", i)))
                {
                    BinarySerializer.DeserializeBodyPacket(unzipped, headerModel.ColumnTypes, deserialized);
                }

                AvrDataTable deserializedStream = new AvrDataTable(headerModel, 10240);
                using (new StopwathTransaction(string.Format("--Deserialize Packet #{0} into stream", i)))
                {
                    BinarySerializer.DeserializeBodyPacket(unzippedStream, headerModel.ColumnTypes, deserializedStream);
                }

                Assert.AreNotSame(deserialized, deserializedStream);
                Assert.AreEqual(deserialized.Count, deserializedStream.Count);
                Assert.AreEqual(deserialized.Columns.Count, deserializedStream.Columns.Count);

                int diagnosisIndex = headerModel.ColumnTypeByName
                                     .Select(c => c.Name)
                                     .TakeWhile(key => key != "sflHC_FinalDiagnosis")
                                     .Count();

                bool found = false;
                for (int j = 0; j < deserialized.Count; j++)
                {
                    var row       = (AvrDataRowEx)deserialized[j];
                    var rowStream = (AvrDataRowEx)deserializedStream[j];

                    Assert.AreNotSame(row, rowStream);
                    Assert.AreEqual(row.Count, rowStream.Count);
                    for (int k = 0; k < row.Count; k++)
                    {
                        Assert.AreEqual(row[k], rowStream[k]);
                    }

                    if (row[diagnosisIndex].ToString() == "Smallpox")
                    {
                        found = true;
                    }
                }

                Assert.IsTrue(found);
            }
        }