mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
74879489a4
* 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 * Update package --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
87 lines
3.3 KiB
C#
87 lines
3.3 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.Workflows.Declarative.Extensions;
|
|
using Microsoft.Agents.Workflows.Declarative.Interpreter;
|
|
using Microsoft.Agents.Workflows.Declarative.PowerFx;
|
|
using Microsoft.Agents.Workflows.Reflection;
|
|
using Microsoft.Bot.ObjectModel;
|
|
using Microsoft.PowerFx.Types;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace Microsoft.Agents.Workflows.Declarative.UnitTests.ObjectModel;
|
|
|
|
/// <summary>
|
|
/// Base test class for <see cref="DeclarativeActionExecutor"/> implementations.
|
|
/// </summary>
|
|
public abstract class WorkflowActionExecutorTest(ITestOutputHelper output) : WorkflowTest(output)
|
|
{
|
|
internal WorkflowScopes Scopes { get; } = new();
|
|
|
|
internal DeclarativeWorkflowState GetState() => new(RecalcEngineFactory.Create(), this.Scopes);
|
|
|
|
protected ActionId CreateActionId() => new($"{this.GetType().Name}_{Guid.NewGuid():N}");
|
|
|
|
protected string FormatDisplayName(string name) => $"{this.GetType().Name}_{name}";
|
|
|
|
internal async Task<WorkflowEvent[]> Execute(DeclarativeActionExecutor executor)
|
|
{
|
|
TestWorkflowExecutor workflowExecutor = new();
|
|
WorkflowBuilder workflowBuilder = new(workflowExecutor);
|
|
workflowBuilder.AddEdge(workflowExecutor, executor);
|
|
StreamingRun run = await InProcessExecution.StreamAsync(workflowBuilder.Build<WorkflowScopes>(), this.Scopes);
|
|
WorkflowEvent[] events = await run.WatchStreamAsync().ToArrayAsync();
|
|
Assert.Contains(events, e => e is DeclarativeActionInvokeEvent);
|
|
Assert.Contains(events, e => e is DeclarativeActionCompleteEvent);
|
|
return events;
|
|
}
|
|
|
|
internal void VerifyModel(DialogAction model, DeclarativeActionExecutor action)
|
|
{
|
|
Assert.Equal(model.Id, action.Id);
|
|
Assert.Equal(model, action.Model);
|
|
}
|
|
|
|
protected void VerifyState(string variableName, FormulaValue expectedValue) => this.VerifyState(variableName, VariableScopeNames.Topic, expectedValue);
|
|
|
|
internal void VerifyState(string variableName, string scopeName, FormulaValue expectedValue)
|
|
{
|
|
FormulaValue actualValue = this.Scopes.Get(variableName, scopeName);
|
|
Assert.Equal(expectedValue.Format(), actualValue.Format());
|
|
}
|
|
|
|
protected void VerifyUndefined(string variableName) => this.VerifyUndefined(variableName, VariableScopeNames.Topic);
|
|
|
|
internal void VerifyUndefined(string variableName, string scopeName)
|
|
{
|
|
Assert.IsType<BlankValue>(this.Scopes.Get(variableName, scopeName));
|
|
}
|
|
|
|
protected TAction AssignParent<TAction>(DialogAction.Builder actionBuilder) where TAction : DialogAction
|
|
{
|
|
OnActivity.Builder activityBuilder =
|
|
new()
|
|
{
|
|
Id = new("root"),
|
|
};
|
|
|
|
activityBuilder.Actions.Add(actionBuilder);
|
|
|
|
OnActivity model = activityBuilder.Build();
|
|
|
|
return (TAction)model.Actions[0];
|
|
}
|
|
|
|
internal sealed class TestWorkflowExecutor() :
|
|
ReflectingExecutor<TestWorkflowExecutor>(nameof(TestWorkflowExecutor)),
|
|
IMessageHandler<WorkflowScopes>
|
|
{
|
|
public async ValueTask HandleAsync(WorkflowScopes message, IWorkflowContext context)
|
|
{
|
|
await context.SendMessageAsync(new ExecutorResultMessage(this.Id)).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|