mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
06827e9f1a
* Closure * Verified * Update dotnet/src/Microsoft.Agents.Workflows.Declarative/Interpreter/DeclarativeWorkflowContext.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Sample folder * System scope fix * Fix link * Integrate Foundry SDK fix * File naming fix * Update dotnet/src/Microsoft.Agents.Workflows.Declarative/Interpreter/DeclarativeWorkflowContext.cs Co-authored-by: Tao Chen <taochen@microsoft.com> * Namespace * Optimize bind --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Tao Chen <taochen@microsoft.com>
72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.Workflows.Declarative.Interpreter;
|
|
using Microsoft.Agents.Workflows.Reflection;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Microsoft.Agents.Workflows.Declarative.UnitTests.Interpreter;
|
|
|
|
/// <summary>
|
|
/// Tests execution of workflow created by <see cref="DeclarativeWorkflowModel"/>.
|
|
/// </summary>
|
|
public sealed class DeclarativeWorkflowModelTest(ITestOutputHelper output) : WorkflowTest(output)
|
|
{
|
|
[Fact]
|
|
public void GetDepthForDefault()
|
|
{
|
|
DeclarativeWorkflowModel model = new(CreateExecutor("root"));
|
|
Assert.Equal(0, model.GetDepth(null));
|
|
}
|
|
|
|
[Fact]
|
|
public void GetDepthForMissingNode()
|
|
{
|
|
DeclarativeWorkflowModel model = new(CreateExecutor("root"));
|
|
Assert.Throws<DeclarativeModelException>(() => model.GetDepth("missing"));
|
|
}
|
|
|
|
[Fact]
|
|
public void ConnectMissingNode()
|
|
{
|
|
TestExecutor rootExecutor = CreateExecutor("root");
|
|
DeclarativeWorkflowModel model = new(rootExecutor);
|
|
model.AddLink("root", "missing");
|
|
WorkflowBuilder workflowBuilder = new(rootExecutor);
|
|
Assert.Throws<DeclarativeModelException>(() => model.ConnectNodes(workflowBuilder));
|
|
}
|
|
|
|
[Fact]
|
|
public void AddToMissingParent()
|
|
{
|
|
DeclarativeWorkflowModel model = new(CreateExecutor("root"));
|
|
Assert.Throws<DeclarativeModelException>(() => model.AddNode(CreateExecutor("next"), "missing"));
|
|
}
|
|
|
|
[Fact]
|
|
public void LinkFromMissingSource()
|
|
{
|
|
DeclarativeWorkflowModel model = new(CreateExecutor("root"));
|
|
Assert.Throws<DeclarativeModelException>(() => model.AddLink("missing", "anything"));
|
|
}
|
|
|
|
[Fact]
|
|
public void LocateMissingParent()
|
|
{
|
|
DeclarativeWorkflowModel model = new(CreateExecutor("root"));
|
|
Assert.Null(model.LocateParent<TestExecutor>(null));
|
|
Assert.Throws<DeclarativeModelException>(() => model.LocateParent<TestExecutor>("missing"));
|
|
}
|
|
|
|
private static TestExecutor CreateExecutor(string id) => new(id);
|
|
|
|
internal sealed class TestExecutor(string actionId) :
|
|
ReflectingExecutor<TestExecutor>(actionId),
|
|
IMessageHandler<string>
|
|
{
|
|
public async ValueTask HandleAsync(string message, IWorkflowContext context) =>
|
|
await context.SendMessageAsync($"{this.Id}: {DateTime.UtcNow:t}").ConfigureAwait(false);
|
|
}
|
|
}
|