Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.Foundry.UnitTests/Hosting/ServiceCollectionExtensionsTests.cs
T
alliscode a1c19b90cd Move Foundry Responses hosting into Microsoft.Agents.AI.Foundry package
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>
2026-04-03 08:00:35 -07:00

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!));
}
}