// Copyright (c) Microsoft. All rights reserved. using System.Collections.Generic; using System.Linq; using Microsoft.Agents.AI.Workflows.Declarative.PowerFx; using Microsoft.Agents.AI.Workflows.Declarative.PowerFx.Functions; using Microsoft.Extensions.AI; using Microsoft.PowerFx.Types; namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.PowerFx.Functions; public class UserMessageTests { [Fact] public void Construct_Function() { UserMessage function = new(); Assert.NotNull(function); } [Fact] public void Execute_ReturnsBlank_ForEmptyInput() { // Arrange StringValue sourceValue = FormulaValue.New(string.Empty); // Act FormulaValue result = UserMessage.Execute(sourceValue); // Assert Assert.IsType(result); } [Fact] public void Execute_ReturnsExpectedRecord_ForNonEmptyInput() { const string Text = "Hello"; FormulaValue sourceValue = FormulaValue.New(Text); StringValue stringValue = Assert.IsType(sourceValue); FormulaValue result = UserMessage.Execute(stringValue); RecordValue recordResult = Assert.IsType(result, exactMatch: false); // Discriminator FormulaValue discriminator = recordResult.GetField(TypeSchema.Discriminator); StringValue discriminatorValue = Assert.IsType(discriminator); Assert.Equal(nameof(ChatMessage), discriminatorValue.Value); // Role FormulaValue role = recordResult.GetField(TypeSchema.Message.Fields.Role); StringValue roleValue = Assert.IsType(role); Assert.Equal(ChatRole.User.Value, roleValue.Value); // Content table FormulaValue content = recordResult.GetField(TypeSchema.Message.Fields.Content); TableValue table = Assert.IsType(content, exactMatch: false); List rows = table.Rows.Select(value => value.Value).ToList(); Assert.Single(rows); StringValue contentType = Assert.IsType(rows[0].GetField(TypeSchema.MessageContent.Fields.Type)); Assert.Equal(TypeSchema.MessageContent.ContentTypes.Text, contentType.Value); StringValue contentValue = Assert.IsType(rows[0].GetField(TypeSchema.MessageContent.Fields.Value)); Assert.Equal(Text, contentValue.Value); } }