From 93ba20dbe2c92d7626c2218ba7bdd0eef19229fa Mon Sep 17 00:00:00 2001 From: Peter Ibekwe Date: Fri, 5 Jun 2026 16:15:53 -0700 Subject: [PATCH] Added more tests --- .../ObjectModel/ForeachExecutorTest.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs index adfa0babe2..b3b16f149b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs @@ -202,6 +202,35 @@ public sealed class ForeachExecutorTest(ITestOutputHelper output) : WorkflowActi Assert.Equal(1m, currentValue.ToObject()); } + /// + /// Single-field records whose only field is NOT named Value are not Power Fx auto-wraps; + /// they are preserved as records so the field name remains accessible inside the loop body. + /// + [Fact] + public async Task ForeachTakeNextWithSingleFieldNonValueRecordAsync() + { + // Arrange + const string CurrentValueName = "CurrentValue"; + this.SetVariableState(CurrentValueName); + + TableDataValue tableValue = DataValue.TableFromRecords( + DataValue.RecordFromFields(new KeyValuePair("name", new StringDataValue("Alice")))); + + Foreach model = this.CreateModel( + displayName: nameof(ForeachTakeNextWithSingleFieldNonValueRecordAsync), + items: ValueExpression.Literal(tableValue), + valueName: CurrentValueName, + indexName: null); + ForeachExecutor action = new(model, this.State); + + // Act + await this.ExecuteAsync(action, ForeachExecutor.Steps.Next(action.Id), action.TakeNextAsync); + + // Assert + RecordValue currentValue = Assert.IsType(this.State.Get(CurrentValueName), exactMatch: false); + Assert.Equal("Alice", currentValue.GetField("name").ToObject()); + } + [Fact] public async Task ForeachTakeLastAsync() {