Files
microsoft--agent-framework/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/AggregatingExecutorTests.cs
T
wehub-resource-sync db620d33df
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:25 +08:00

78 lines
2.8 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Threading.Tasks;
using FluentAssertions;
namespace Microsoft.Agents.AI.Workflows.UnitTests;
public class AggregatingExecutorTests
{
[Fact]
public async Task AggregatingExecutor_HandleAsync_AggregatesIncrementallyAsync()
{
AggregatingExecutor<string, string> executor = new("sum", (aggregate, input) =>
aggregate == null ? input : $"{aggregate}+{input}");
TestWorkflowContext context = new(executor.Id);
string? result1 = await executor.HandleAsync("a", context, default);
string? result2 = await executor.HandleAsync("b", context, default);
string? result3 = await executor.HandleAsync("c", context, default);
result1.Should().Be("a");
result2.Should().Be("a+b");
result3.Should().Be("a+b+c");
}
[Fact]
public async Task AggregatingExecutor_HandleAsync_FirstCallReceivesNullAggregateAsync()
{
string? receivedAggregate = "sentinel";
AggregatingExecutor<string, string> executor = new("first-call", (aggregate, input) =>
{
receivedAggregate = aggregate;
return input;
});
TestWorkflowContext context = new(executor.Id);
await executor.HandleAsync("hello", context, default);
receivedAggregate.Should().BeNull("the first invocation should receive a null aggregate for reference types");
}
[Fact]
public async Task AggregatingExecutor_HandleAsync_AggregatorReturningNullClearsStateAsync()
{
AggregatingExecutor<string, string> executor = new("nullable", (aggregate, input) =>
input == "clear" ? null : (aggregate ?? "") + input);
TestWorkflowContext context = new(executor.Id);
string? result1 = await executor.HandleAsync("a", context, default);
result1.Should().Be("a");
string? result2 = await executor.HandleAsync("clear", context, default);
result2.Should().BeNull("the aggregator returned null to clear the state");
// After clearing, the next call should receive null aggregate again
string? result3 = await executor.HandleAsync("b", context, default);
result3.Should().Be("b", "the aggregate should restart from null after being cleared");
}
[Fact]
public async Task AggregatingExecutor_HandleAsync_PersistsStateBetweenCallsAsync()
{
AggregatingExecutor<string, string> executor = new("counter", (aggregate, _) =>
aggregate == null ? "1" : $"{int.Parse(aggregate) + 1}");
TestWorkflowContext context = new(executor.Id);
for (int i = 1; i <= 5; i++)
{
string? result = await executor.HandleAsync("tick", context, default);
result.Should().Be($"{i}", "the aggregate should increment with each call");
}
}
}