mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
a1c19b90cd
Move source and test files from the standalone Hosting.AzureAIResponses project into the Foundry package under a Hosting/ subfolder. This consolidates the Foundry-specific hosting adapter into the main Foundry package. - Source: Microsoft.Agents.AI.Foundry.Hosting namespace - Tests: merged into Foundry.UnitTests/Hosting/ - Conditionally compiled for .NETCoreApp TFMs only (net8.0+) - Deleted standalone Hosting.AzureAIResponses project and test project - Updated sample and solution references Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using Microsoft.Agents.AI.Foundry.Hosting;
|
|
using Azure.AI.AgentServer.Responses;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Moq;
|
|
|
|
namespace Microsoft.Agents.AI.Foundry.UnitTests.Hosting;
|
|
|
|
public class ServiceCollectionExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void AddAgentFrameworkHandler_RegistersResponseHandler()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
services.AddAgentFrameworkHandler();
|
|
|
|
var descriptor = services.FirstOrDefault(
|
|
d => d.ServiceType == typeof(ResponseHandler));
|
|
Assert.NotNull(descriptor);
|
|
Assert.Equal(typeof(AgentFrameworkResponseHandler), descriptor.ImplementationType);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddAgentFrameworkHandler_CalledTwice_RegistersOnce()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
services.AddAgentFrameworkHandler();
|
|
services.AddAgentFrameworkHandler();
|
|
|
|
var count = services.Count(d => d.ServiceType == typeof(ResponseHandler));
|
|
Assert.Equal(1, count);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddAgentFrameworkHandler_NullServices_ThrowsArgumentNullException()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(
|
|
() => AgentFrameworkResponsesServiceCollectionExtensions.AddAgentFrameworkHandler(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void AddAgentFrameworkHandler_WithAgent_RegistersAgentAndHandler()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
var mockAgent = new Mock<AIAgent>();
|
|
|
|
services.AddAgentFrameworkHandler(mockAgent.Object);
|
|
|
|
var handlerDescriptor = services.FirstOrDefault(
|
|
d => d.ServiceType == typeof(ResponseHandler));
|
|
Assert.NotNull(handlerDescriptor);
|
|
|
|
var agentDescriptor = services.FirstOrDefault(
|
|
d => d.ServiceType == typeof(AIAgent));
|
|
Assert.NotNull(agentDescriptor);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddAgentFrameworkHandler_WithNullAgent_ThrowsArgumentNullException()
|
|
{
|
|
var services = new ServiceCollection();
|
|
Assert.Throws<ArgumentNullException>(
|
|
() => services.AddAgentFrameworkHandler(null!));
|
|
}
|
|
}
|