public void AvrDataTableCloneTest() { QueryTableHeaderModel model = GetQueryTableHeaderModel(); var original = new AvrDataTable(model, 1024); original.Rows.Add(original.NewRow(new object[original.Columns.DistinctCount])); original.Rows.Add(original.NewRow(new object[original.Columns.DistinctCount])); Assert.AreEqual(2, original.Rows.Count); AvrDataTable clone = original.Clone(); Assert.IsNotNull(clone); Assert.AreNotSame(clone, original); Assert.AreEqual(0, clone.Rows.Count); Assert.AreEqual(original.TableName, clone.TableName); Assert.AreEqual(clone.Columns.Count, original.Columns.Count); Assert.AreEqual(clone.Columns.DistinctCount, original.Columns.DistinctCount); Assert.AreEqual(clone.Columns.Properties.Count, original.Columns.Properties.Count); foreach (var column in original.Columns) { Assert.IsTrue(clone.Columns.Contains(column.ColumnName)); Assert.IsFalse(clone.Columns.Contains(column)); } }
public void AvrDataTableCopyTest() { QueryTableHeaderModel model = GetQueryTableHeaderModel(); var original = new AvrDataTable(model, 1024); original.Rows.Add(original.NewRow(new object[original.Columns.DistinctCount])); Assert.AreEqual(1, original.Rows.Count); AvrDataTable copy = original.Copy(); Assert.IsNotNull(copy); Assert.AreEqual(original.TableName, copy.TableName); Assert.AreNotSame(copy, original); Assert.IsTrue(copy.Rows.Count > 0); for (int i = 0; i < original.Count; i++) { var row = (AvrDataRow)original[i]; var copyRow = (AvrDataRow)copy[i]; Assert.AreNotSame(row, copyRow); Assert.IsNotNull(row.Array); Assert.IsNotNull(copyRow.Array); Assert.AreNotSame(row.Array, copyRow.Array); Assert.AreEqual(row.Count, copyRow.Count); for (int j = 0; j < row.Count; j++) { Assert.AreEqual(row[j], copyRow[j]); } } }
public void AvrDataRowExCopyTest() { var originalTable = new AvrDataTable(); var rowDTO = new AvrDataRowDTO(1, 2, 2); rowDTO.SetInt(0, 1); rowDTO.SetInt(1, 2); rowDTO.SetObject(2, "xx"); rowDTO.SetObject(3, true); rowDTO.SetDateTime(4, new DateTime(2000, 1, 1)); AvrDataRowEx original = originalTable.NewRow(rowDTO); Assert.AreEqual(1, original[0]); Assert.AreEqual(2, original[1]); Assert.AreEqual("xx", original[2]); Assert.AreEqual(true, original[3]); Assert.AreEqual(new DateTime(2000, 1, 1), original[4]); AvrDataRowEx copy = (AvrDataRowEx)original.Clone(); Assert.IsNotNull(copy); Assert.AreNotSame(copy, original); Assert.AreEqual(original.Count, copy.Count); for (int i = 0; i < original.Count; i++) { Assert.AreEqual(original[i], copy[i]); } }
public void AvrDataTableRejectChangesTest() { QueryTableHeaderModel model = GetQueryTableHeaderModel(); var table = new AvrDataTable(model, 1024); table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount])); table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount])); Assert.AreEqual(2, table.Rows.Count); table.RejectChanges(); Assert.AreEqual(0, table.Rows.Count); table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount])); table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount])); Assert.AreEqual(2, table.Rows.Count); table.AcceptChanges(); table.RejectChanges(); Assert.AreEqual(2, table.Rows.Count); table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount])); Assert.AreEqual(3, table.Rows.Count); table.RejectChanges(); Assert.AreEqual(2, table.Rows.Count); table.Rows.Add(table.NewRow(new object[table.Columns.DistinctCount])); Assert.AreEqual(3, table.Rows.Count); table.AcceptChanges(); table.RejectChanges(); Assert.AreEqual(3, table.Rows.Count); }
public void AvrDataRowCopyTest() { var originalTable = new AvrDataTable(); var array = new[] { 1, 2, (object)"xx", true, new DateTime(2000, 1, 1) }; AvrDataRow original = originalTable.NewRow(array); AvrDataRow copy = (AvrDataRow)original.Clone(); Assert.IsNotNull(copy); Assert.AreNotSame(copy, original); Assert.AreEqual(original.Count, copy.Count); Assert.AreNotSame(original.Array, copy.Array); for (int i = 0; i < original.Count; i++) { Assert.AreEqual(original[i], copy[i]); } }
private static AvrPivotGridData GetTestData() { var table = new AvrDataTable(); for (int i = 0; i < 10; i++) { var rowDTO = new AvrDataRowDTO(1, 2, 2); rowDTO.SetInt(0, i); rowDTO.SetInt(1, 2 * i); rowDTO.SetObject(2, "xx_" + i); rowDTO.SetObject(3, true); rowDTO.SetDateTime(4, new DateTime(2000, 1, i + 1)); AvrDataRowEx row = table.NewRow(rowDTO); table.ThreadSafeAdd(row); } table.AcceptChanges(); return(new AvrPivotGridData(table)); }
public static void DeserializeBodyPacket(int rowsCount, Type[] types, AvrDataTable table, Func <Stream> streamCreator) { Utils.CheckNotNull(types, "types"); Utils.CheckNotNull(streamCreator, "streamCreator"); Stream stream = streamCreator(); if (stream == null) { throw new AvrException("Could not deserialize avr table packet: stream creator is null"); } int colsCount = types.Length; var internIndexes = new int[colsCount]; var internStrings = new string[colsCount][]; for (int i = 0; i < internStrings.Length; i++) { internStrings[i] = new string[sbyte.MaxValue]; } ExpressionEvaluator filter = null; if (!string.IsNullOrEmpty(table.RowFilterExpression)) { var descriptor = new AvrRowEvaluatorContextDescriptor(table); var criteriaOperator = CriteriaOperator.Parse(table.RowFilterExpression); filter = new ExpressionEvaluator(descriptor, criteriaOperator); } var rowDTO = CreateAvrDataRowDTO(types); using (var reader = new BinaryReader(stream)) { for (int i = 0; i < rowsCount; i++) { for (int j = 0; j < colsCount; j++) { sbyte status = reader.ReadSByte(); if (status > 0) { Type type = types[j]; if (type == m_TypeOfString) { string val; var internIndex = internIndexes[j]; if (internIndex < sbyte.MaxValue) { if (status == 1) { val = reader.ReadString(); internStrings[j][internIndex] = val; internIndexes[j] = internIndex + 1; } else { val = internStrings[j][status - 2]; } } else { val = reader.ReadString(); } rowDTO.SetObject(j, val); } else if (type == m_TypeOfDateTime) { var value = new DateTime(reader.ReadInt64()); rowDTO.SetDateTime(j, value); } else if (type == m_TypeOfInt32) { rowDTO.SetInt(j, reader.ReadInt32()); } else if (type == m_TypeOfInt64) { rowDTO.SetObject(j, reader.ReadInt64()); } else if (type == m_TypeOfInt16) { rowDTO.SetObject(j, reader.ReadInt16()); } else if (type == m_TypeOfDouble) { rowDTO.SetObject(j, reader.ReadDouble()); } else if (type == m_TypeOfDecimal) { rowDTO.SetObject(j, reader.ReadDecimal()); } else if (type == m_TypeOfSingle) { rowDTO.SetObject(j, reader.ReadSingle()); } else if (type == m_TypeOfBoolean) { rowDTO.SetObject(j, reader.ReadBoolean()); } else if (type == m_TypeOfByte) { rowDTO.SetObject(j, reader.ReadByte()); } } } AvrDataRowBase newRow = table.NewRow(rowDTO); if (filter == null || filter.Fit(newRow)) { table.ThreadSafeAdd(newRow); } rowDTO.Reset(); } } stream.Dispose(); }
public void AvrDataRowFilterTest() { var table = new AvrDataTable(); table.Columns.Add("sflHC_CaseID", typeof(string)); table.Columns.Add("sflHC_EnteredDate", typeof(DateTime)); var row = table.NewRow(new object[] { "b", new DateTime(2000, 01, 01) }); var op = CriteriaOperator.Parse(@"[fieldsflHC_EnteredDate_idfLayoutSearchField_57595750000000] >= #2000-01-01#"); var evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); var isFit = evaluator.Fit(row); Assert.IsTrue(isFit); op = CriteriaOperator.Parse( @"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Is Not Null And [fieldsflHC_EnteredDate_idfLayoutSearchField_57595750000000] > #2016-02-01#"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); op = CriteriaOperator.Parse( @"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Is Not Null And [fieldsflHC_EnteredDate_idfLayoutSearchField_57595750000000] < #2016-02-01#"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //atomic string criterias tests: //Is Null op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Is Null"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); //Is not Null op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Is Not Null"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //== op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] = 'b'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //!= op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] <> 'a'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //> op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] > 'a'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //>= op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] >= 'a'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //< op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] < 'a'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] < 'c'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //<= op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] <= 'a'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] <= 'b'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] <= 'c'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //Contains op = CriteriaOperator.Parse(@"Contains([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'a')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); op = CriteriaOperator.Parse(@"Contains([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'b')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //Not Contains op = CriteriaOperator.Parse(@"Not Contains([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'a')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); op = CriteriaOperator.Parse(@"Not Contains([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'b')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); //StatrsWith op = CriteriaOperator.Parse(@"StartsWith([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'a')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); op = CriteriaOperator.Parse(@"StartsWith([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'b')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); //EndsWith op = CriteriaOperator.Parse(@"EndsWith([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'b')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); op = CriteriaOperator.Parse(@"EndsWith([fieldsflHC_CaseID_idfLayoutSearchField_57595670000000], 'a')"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); //Like op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Like 'b%'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Like 'c%'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); //Not Like op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Not Like 'a%'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsTrue(isFit); op = CriteriaOperator.Parse(@"[fieldsflHC_CaseID_idfLayoutSearchField_57595670000000] Not Like 'b%'"); evaluator = new ExpressionEvaluator(new AvrRowEvaluatorContextDescriptor(table), op); isFit = evaluator.Fit(row); Assert.IsFalse(isFit); }