Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/MockAgentProvider.cs
T
Peter Ibekwe ab3d898979 .NET: Add unit tests for RetrieveConversationMessageExecutor executor (#2232)
* Add unit tests for create conversation executor

* Update indentation and comment typo.

* Added unit tests for declarative executor SetMultipleVariablesExecutor

* Updated comments and syntactic sugar

* Add unit test for declarative executor  RetrieveConversationMessageExecutor

* Removed irrelevant code statements

* Updated based on copilot feedback.
2025-11-20 21:47:42 +00:00

50 lines
1.5 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.AI;
using Moq;
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests;
/// <summary>
/// Mock implementation of <see cref="WorkflowAgentProvider"/> for unit testing purposes.
/// </summary>
internal sealed class MockAgentProvider : Mock<WorkflowAgentProvider>
{
public IList<string> ExistingConversationIds { get; } = [];
public ChatMessage? TestChatMessage { get; set; }
public MockAgentProvider()
{
this.Setup(provider => provider.CreateConversationAsync(It.IsAny<CancellationToken>()))
.Returns(() => Task.FromResult(this.CreateConversationId()));
this.Setup(provider => provider.GetMessageAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<CancellationToken>()))
.Returns(Task.FromResult(this.CreateChatMessage()));
}
private string CreateConversationId()
{
string newConversationId = Guid.NewGuid().ToString("N");
this.ExistingConversationIds.Add(newConversationId);
return newConversationId;
}
private ChatMessage CreateChatMessage()
{
this.TestChatMessage = new ChatMessage(ChatRole.User, Guid.NewGuid().ToString("N"))
{
MessageId = Guid.NewGuid().ToString("N"),
};
return this.TestChatMessage;
}
}