Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/RetrieveConversationMessagesExecutorTest.cs
Chris 75a8335af5 .NET - [Breaking]: Update Declarative Object Model + Dependencies (#3017)
* Builds locally and tests pass

* Fix typo

* Reverted nuget config change to remove internal feed and map to new public object model package with renames.

* Renaming Bot object model in additional sample.

---------

Co-authored-by: Peter Ibekwe <peibekwe@microsoft.com>
2026-01-28 20:00:37 +00:00

114 lines
3.5 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Threading.Tasks;
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
using Microsoft.Agents.ObjectModel;
using Xunit.Abstractions;
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel;
/// <summary>
/// Tests for <see cref="RetrieveConversationMessagesExecutor"/>.
/// </summary>
public sealed class RetrieveConversationMessagesExecutorTest(ITestOutputHelper output) : WorkflowActionExecutorTest(output)
{
[Fact]
public async Task RetrieveAllMessagesSuccessfullyAsync()
{
// Arrange, Act, Assert
await this.ExecuteTestAsync(
nameof(RetrieveAllMessagesSuccessfullyAsync),
"TestMessages",
"TestConversationId");
}
[Fact]
public async Task RetrieveMessagesWithOptionalValuesAsync()
{
// Arrange, Act, Assert
await this.ExecuteTestAsync(
nameof(RetrieveMessagesWithOptionalValuesAsync),
"TestMessages",
"TestConversationId",
limit: IntExpression.Literal(2),
after: StringExpression.Literal("11/01/2025"),
before: StringExpression.Literal("12/01/2025"),
sortOrder: EnumExpression<AgentMessageSortOrderWrapper>.Literal(AgentMessageSortOrderWrapper.Get(AgentMessageSortOrder.NewestFirst)));
}
private async Task ExecuteTestAsync(
string displayName,
string variableName,
string conversationId,
IntExpression? limit = null,
StringExpression? after = null,
StringExpression? before = null,
EnumExpression<AgentMessageSortOrderWrapper>? sortOrder = null)
{
// Arrange
MockAgentProvider mockAgentProvider = new();
RetrieveConversationMessages model = this.CreateModel(
this.FormatDisplayName(displayName),
FormatVariablePath(variableName),
conversationId,
limit,
after,
before,
sortOrder);
RetrieveConversationMessagesExecutor action = new(model, mockAgentProvider.Object, this.State);
// Act
await this.ExecuteAsync(action);
// Assert
var testMessages = mockAgentProvider.TestMessages;
Assert.NotNull(testMessages);
VerifyModel(model, action);
this.VerifyState(variableName, testMessages.ToTable());
}
private RetrieveConversationMessages CreateModel(
string displayName,
string variableName,
string conversationId,
IntExpression? limit,
StringExpression? after,
StringExpression? before,
EnumExpression<AgentMessageSortOrderWrapper>? sortOrder)
{
RetrieveConversationMessages.Builder actionBuilder =
new()
{
Id = this.CreateActionId(),
DisplayName = this.FormatDisplayName(displayName),
Messages = PropertyPath.Create(variableName),
ConversationId = StringExpression.Literal(conversationId)
};
if (limit is not null)
{
actionBuilder.Limit = limit;
}
if (after is not null)
{
actionBuilder.MessageAfter = after;
}
if (before is not null)
{
actionBuilder.MessageBefore = before;
}
if (sortOrder is not null)
{
actionBuilder.SortOrder = sortOrder;
}
return AssignParent<RetrieveConversationMessages>(actionBuilder);
}
}