db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
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
61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
|
|
using Microsoft.Agents.ObjectModel;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel;
|
|
|
|
/// <summary>
|
|
/// Tests for <see cref="SendActivityExecutor"/>.
|
|
/// </summary>
|
|
public sealed class SendActivityExecutorTest(ITestOutputHelper output) : WorkflowActionExecutorTest(output)
|
|
{
|
|
[Fact]
|
|
public async Task CaptureActivityAsync()
|
|
{
|
|
// Arrange
|
|
SendActivity model =
|
|
this.CreateModel(
|
|
this.FormatDisplayName(nameof(CaptureActivityAsync)),
|
|
"Test activity message");
|
|
|
|
// Act
|
|
SendActivityExecutor action = new(model, this.State);
|
|
WorkflowEvent[] events = await this.ExecuteAsync(action);
|
|
|
|
// Assert
|
|
VerifyModel(model, action);
|
|
Assert.Contains(events, e => e is MessageActivityEvent);
|
|
|
|
// The executor must also emit an AgentResponseEvent carrying the activity text
|
|
// so workflow consumers (hosting runtime, UIs) can surface it as an agent turn.
|
|
AgentResponseEvent agentEvent = Assert.Single(events.OfType<AgentResponseEvent>());
|
|
Assert.Equal(action.Id, agentEvent.ExecutorId);
|
|
ChatMessage message = Assert.Single(agentEvent.Response.Messages);
|
|
Assert.Equal(ChatRole.Assistant, message.Role);
|
|
Assert.Equal("Test activity message", message.Text);
|
|
}
|
|
|
|
private SendActivity CreateModel(string displayName, string activityMessage, string? summary = null)
|
|
{
|
|
MessageActivityTemplate.Builder activityBuilder =
|
|
new()
|
|
{
|
|
Summary = summary,
|
|
Text = { TemplateLine.Parse(activityMessage) },
|
|
};
|
|
SendActivity.Builder actionBuilder =
|
|
new()
|
|
{
|
|
Id = this.CreateActionId(),
|
|
DisplayName = this.FormatDisplayName(displayName),
|
|
Activity = activityBuilder.Build(),
|
|
};
|
|
|
|
return AssignParent<SendActivity>(actionBuilder);
|
|
}
|
|
}
|