// Copyright (c) Microsoft. All rights reserved. using System; using Aspire.Hosting.ApplicationModel; using Moq; namespace Aspire.Hosting.AgentFramework.DevUI.UnitTests; /// /// Unit tests for the class. /// public class AgentServiceAnnotationTests { #region Constructor Validation Tests /// /// Verifies that passing null for agentService throws ArgumentNullException. /// [Fact] public void Constructor_NullAgentService_ThrowsArgumentNullException() { // Act & Assert Assert.Throws(() => new AgentServiceAnnotation(null!)); } /// /// Verifies that a valid agentService can be used to create the annotation. /// [Fact] public void Constructor_ValidAgentService_CreatesAnnotation() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("test-service"); // Act var annotation = new AgentServiceAnnotation(mockResource.Object); // Assert Assert.NotNull(annotation); Assert.Same(mockResource.Object, annotation.AgentService); } #endregion #region Property Tests /// /// Verifies that AgentService property returns the value passed to constructor. /// [Fact] public void AgentService_ReturnsConstructorValue() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("my-service"); // Act var annotation = new AgentServiceAnnotation(mockResource.Object); // Assert Assert.Same(mockResource.Object, annotation.AgentService); } /// /// Verifies that EntityIdPrefix returns null when not specified. /// [Fact] public void EntityIdPrefix_NotSpecified_ReturnsNull() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("test-service"); // Act var annotation = new AgentServiceAnnotation(mockResource.Object); // Assert Assert.Null(annotation.EntityIdPrefix); } /// /// Verifies that EntityIdPrefix returns the value passed to constructor. /// [Fact] public void EntityIdPrefix_Specified_ReturnsValue() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("test-service"); // Act var annotation = new AgentServiceAnnotation(mockResource.Object, entityIdPrefix: "custom-prefix"); // Assert Assert.Equal("custom-prefix", annotation.EntityIdPrefix); } /// /// Verifies that Agents returns empty collection when not specified. /// [Fact] public void Agents_NotSpecified_ReturnsEmptyCollection() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("test-service"); // Act var annotation = new AgentServiceAnnotation(mockResource.Object); // Assert Assert.NotNull(annotation.Agents); Assert.Empty(annotation.Agents); } /// /// Verifies that Agents returns the list passed to constructor. /// [Fact] public void Agents_Specified_ReturnsValue() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("test-service"); var agents = new[] { new AgentEntityInfo("agent1"), new AgentEntityInfo("agent2") }; // Act var annotation = new AgentServiceAnnotation(mockResource.Object, agents: agents); // Assert Assert.Equal(2, annotation.Agents.Count); Assert.Equal("agent1", annotation.Agents[0].Id); Assert.Equal("agent2", annotation.Agents[1].Id); } #endregion #region Full Constructor Tests /// /// Verifies that all constructor parameters are correctly stored. /// [Fact] public void Constructor_AllParameters_SetsAllProperties() { // Arrange var mockResource = new Mock(); mockResource.Setup(r => r.Name).Returns("full-service"); var agents = new[] { new AgentEntityInfo("writer", "Writes stories") }; // Act var annotation = new AgentServiceAnnotation( mockResource.Object, entityIdPrefix: "writer-backend", agents: agents); // Assert Assert.Same(mockResource.Object, annotation.AgentService); Assert.Equal("writer-backend", annotation.EntityIdPrefix); Assert.Single(annotation.Agents); Assert.Equal("writer", annotation.Agents[0].Id); Assert.Equal("Writes stories", annotation.Agents[0].Description); } #endregion }