Files
agent-framework/dotnet/tests/Microsoft.Agents.Workflows.Declarative.UnitTests/PowerFx/RecalcEngineFactoryTests.cs
T
Chris fb513c38a6 .NET Workflow - Declarative State Consolidation (#759)
* Checkpoint

* Update workflows/DeepResearch.yaml

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Comment

* Fix comment

* Update package version

* Fix nuget haxx

* Checkpoint

* Code complete

* Testing

* Message content workaround

* Add sequential flow

* Checkpoint

* Integration test project

* Checkpoint

* Checkpoint cleanup

* Complete

* Checkpoint

* Fix tests

* Comment cleanup

* Namespace

* Formatting

* Analyzer updates

* Workflow update

* Fixed!

* Update dotnet/tests/Microsoft.Agents.Workflows.Declarative.UnitTests/DeclarativeWorkflowTest.cs

Co-authored-by: Tao Chen <taochen@microsoft.com>

* Fix build error

* Purge "immutable" set and dictionary

* Fix as task

* Collection expression

* Another

* Frozen => Readonly (perf)

* Fix

* Namespace

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Tao Chen <taochen@microsoft.com>
2025-09-16 03:09:12 +00:00

129 lines
4.1 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using Microsoft.Agents.Workflows.Declarative.Extensions;
using Microsoft.Agents.Workflows.Declarative.PowerFx;
using Microsoft.PowerFx;
using Microsoft.PowerFx.Types;
using Xunit.Abstractions;
namespace Microsoft.Agents.Workflows.Declarative.UnitTests.PowerFx;
public class RecalcEngineFactoryTests(ITestOutputHelper output) : WorkflowTest(output)
{
[Fact]
public void VariableUpdateTest()
{
RecalcEngine engine = RecalcEngineFactory.Create();
FormulaValue evalResult;
engine.UpdateVariable("single", FormulaValue.New(1));
evalResult = engine.Eval("single");
Console.WriteLine($"# {evalResult.Format()}");
RecordValue recordSub =
FormulaValue.NewRecordFromFields(
new NamedValue("sub", FormulaValue.New(3.14)));
RecordValue recordRoot =
FormulaValue.NewRecordFromFields(
new NamedValue("another", FormulaValue.NewBlank()),
new NamedValue("val", FormulaValue.New(2.82)),
new NamedValue("root", recordSub));
engine.DeleteFormula("Topic");
engine.UpdateVariable("Topic", recordRoot);
evalResult = engine.Eval("Topic");
Console.WriteLine($"# {evalResult.Format()}");
evalResult = engine.Eval("Topic.val");
Console.WriteLine($"# {evalResult.Format()}");
evalResult = engine.Eval("Topic.root");
Console.WriteLine($"# {evalResult.Format()}");
evalResult = engine.Eval("Topic.root.sub");
Console.WriteLine($"# {evalResult.Format()}");
//recordRoot.UpdateField("another", FormulaValue.New("abc"));
RecordValue recordRoot2 =
FormulaValue.NewRecordFromFields(
new NamedValue("another", FormulaValue.New("abc")),
new NamedValue("val", FormulaValue.New(2.82)),
new NamedValue("root", recordSub));
engine.DeleteFormula("Topic");
engine.UpdateVariable("Topic", recordRoot2);
evalResult = engine.Eval("Topic.another");
Console.WriteLine($"# {evalResult.Format()}");
engine.UpdateVariable("Topic.another", FormulaValue.New(-1));
evalResult = engine.Eval("Topic.another");
Console.WriteLine($"# {evalResult.Format()}");
}
[Fact]
public void DefaultNotNull()
{
// Act
RecalcEngine engine = RecalcEngineFactory.Create();
// Assert
Assert.NotNull(engine);
}
[Fact]
public void NewInstanceEachTime()
{
// Act
RecalcEngine engine1 = RecalcEngineFactory.Create();
RecalcEngine engine2 = RecalcEngineFactory.Create();
// Assert
Assert.NotNull(engine1);
Assert.NotNull(engine2);
Assert.NotSame(engine1, engine2);
}
[Fact]
public void HasSetFunctionEnabled()
{
// Arrange
RecalcEngine engine = RecalcEngineFactory.Create();
// Act
CheckResult result = engine.Check("1+1");
// Assert
Assert.True(result.IsSuccess);
}
[Fact]
public void HasCorrectMaximumExpressionLength()
{
// Arrange
RecalcEngine engine = RecalcEngineFactory.Create(2000, 3);
// Assert
Assert.Equal(2000, engine.Config.MaximumExpressionLength);
Assert.Equal(3, engine.Config.MaxCallDepth);
// Act: Create a long expression that is within the limit
string goodExpression = string.Concat(GenerateExpression(999));
CheckResult goodResult = engine.Check(goodExpression);
// Assert
Assert.True(goodResult.IsSuccess);
// Act: Create a long expression that exceeds the limit
string longExpression = string.Concat(GenerateExpression(1001));
CheckResult longResult = engine.Check(longExpression);
// Assert
Assert.False(longResult.IsSuccess);
static IEnumerable<string> GenerateExpression(int elements)
{
yield return "1";
for (int i = 0; i < elements - 1; i++)
{
yield return "+1";
}
}
}
}