Skip to content

Commit

Permalink
add test to show ColumnNames usage with External.ArrayAndObject untyp…
Browse files Browse the repository at this point in the history
…ed object types
  • Loading branch information
spanopoulos-msft committed Aug 13, 2024
1 parent aa26cfa commit 7956123
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ public void PadUntypedObject2MutationTest()
Assert.Equal(97m, result.ToObject());
}

[Fact]
public void PadUntypedObject2ColumnNamesTest()
{
var uo = new PadUntypedObject2(GetDataTable());
var uov = new UntypedObjectValue(IRContext.NotInSource(FormulaType.UntypedObject), uo);

PowerFxConfig config = new PowerFxConfig(Features.PowerFxV1);
RecalcEngine engine = new RecalcEngine(config);

engine.Config.SymbolTable.EnableMutationFunctions();
engine.UpdateVariable("padTable", uov, new SymbolProperties() { CanMutate = true, CanSetMutate = true });

var result = engine.Eval(@"ColumnNames(Index(padTable, 1))");

// would expect not to be an error value
Assert.IsType<ErrorValue>(result);
}

private DataTable GetDataTable()
{
var dt = new DataTable("someTable");
Expand Down Expand Up @@ -513,7 +531,7 @@ public override string GetUntypedNumber()
{
throw new NotImplementedException();
}

public string[] GetPropertyNames()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -547,6 +565,13 @@ public override bool TryGetProperty(string propertyName, out IUntypedObject resu
public override bool TryGetPropertyNames(out IEnumerable<string> result)
{
result = null;

if (DataRow != null)
{
result = DataRow.Table.Columns.Cast<DataColumn>().Select(dc => dc.ColumnName);
return true;
}

return false;
}

Expand Down

0 comments on commit 7956123

Please sign in to comment.