public void Test_FieldTypes(string fieldTypeAlias, string calc, string equalTo, Type databaseType, Type cellDataType) { // Define type EntityType type = new EntityType(); // Define calculated field Field field = Entity.Create(new EntityRef(fieldTypeAlias)).As <Field>(); field.IsCalculatedField = true; field.FieldCalculation = calc; type.Fields.Add(field); type.Save(); // Create instance Resource inst = Entity.Create(type.Id).As <Resource>(); inst.Name = "Name1"; inst.Save(); // Define structured query var sq = new SQ.StructuredQuery(); sq.RootEntity = new SQ.ResourceEntity(new EntityRef(type.Id)); var column = new SQ.SelectColumn(); column.Expression = new SQ.ResourceDataColumn(sq.RootEntity, new EntityRef(field.Id)); sq.SelectColumns.Add(column); // Run report var settings = new SQ.QuerySettings(); var queryResult = Factory.QueryRunner.ExecuteQuery(sq, settings); // Check results Assert.That(queryResult.Columns[0].ColumnType, Is.TypeOf(databaseType)); var row = queryResult.DataTable.Rows[0]; object data = row[0]; Assert.That(data, Is.InstanceOf(cellDataType)); if (equalTo == "*") { Assert.That(data.ToString(), Is.Not.Null.And.Not.Empty); } else { Assert.That(data.ToString(), Is.EqualTo(equalTo)); } }
public void Test_InvalidateWhen_ReferencedDataChanged() { EntityType type = null; Field field; Resource inst; try { // Define type type = new EntityType(); // Define calculated field field = Entity.Create(new EntityRef("core:stringField")).As <Field>(); field.IsCalculatedField = true; field.FieldCalculation = "'Value '+Description"; type.Fields.Add(field); type.Save(); // Create instance inst = Entity.Create(type.Id).As <Resource>(); inst.Name = "Name1"; inst.Description = "One"; inst.Save(); // Define structured query var sq = new SQ.StructuredQuery(); sq.RootEntity = new SQ.ResourceEntity(new EntityRef(type.Id)); var column = new SQ.SelectColumn(); column.Expression = new SQ.ResourceDataColumn(sq.RootEntity, new EntityRef(field.Id)); sq.SelectColumns.Add(column); // Run report var settings = new SQ.QuerySettings(); var queryResult = Factory.QueryRunner.ExecuteQuery(sq, settings); // Check results var row = queryResult.DataTable.Rows[0]; object data = row[0]; Assert.That(data, Is.EqualTo("Value One")); // Modify data inst.Description = "Two"; inst.Save(); // Rerun report queryResult = Factory.QueryRunner.ExecuteQuery(sq, settings); // Recheck results row = queryResult.DataTable.Rows[0]; data = row[0]; Assert.That(data, Is.EqualTo("Value Two")); } finally { if (type != null) { type.Delete(); } // Using RunWithTransaction causes this test to fail } }