// Copyright (c) Microsoft. All rights reserved. using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.Agents.AI; using Microsoft.Extensions.AI; using Moq; namespace Microsoft.Agents.Orchestration.UnitTest; /// /// Mock definition of . /// internal sealed class MockAgent(int index) : AIAgent { public static MockAgent CreateWithResponse(int index, string response) => new(index) { Response = [new(ChatRole.Assistant, response)] }; public int InvokeCount { get; private set; } public IReadOnlyList Response { get; set; } = []; public override string? Name => $"testagent{index}"; public override string? Description => $"test {index}"; public override AgentThread GetNewThread() => new Mock().Object; public override AgentThread DeserializeThread(System.Text.Json.JsonElement serializedThread, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null) => new Mock().Object; public override Task RunAsync(IEnumerable messages, AgentThread? thread = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) { this.InvokeCount++; return Task.FromResult(new AgentRunResponse(messages: [.. this.Response])); } public override IAsyncEnumerable RunStreamingAsync(IEnumerable messages, AgentThread? thread = null, AgentRunOptions? options = null, CancellationToken cancellationToken = default) { this.InvokeCount++; return this.Response.Select(message => new AgentRunResponseUpdate(message.Role, message.Text)).ToAsyncEnumerable(); } }