Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/PowerFx/Functions/MessageTextTests.cs
Ren Finlayson 539852f81c
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
Python - Merge - Tests / paths-filter (push) Has been cancelled
Python - Merge - Tests / Python Tests - Core (integration, ubuntu-latest, 3.10) (push) Has been cancelled
Python - Merge - Tests / Python Tests - Azure AI (integration, ubuntu-latest, 3.10) (push) Has been cancelled
Python - Merge - Tests / python-integration-tests-check (push) Has been cancelled
Python - Lab Tests / paths-filter (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.10) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.11) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.12) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.13) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.14) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.10) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.11) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.12) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.13) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.14) (push) Has been cancelled
Check .md links / markdown-link-check (push) Has been cancelled
test
2026-01-24 03:05:12 +11:00

114 lines
3.2 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
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 sealed class MessageTextTests
{
[Fact]
public void Construct_Function()
{
MessageText.StringInput function1 = new();
Assert.NotNull(function1);
MessageText.RecordInput function2 = new();
Assert.NotNull(function2);
MessageText.TableInput function3 = new();
Assert.NotNull(function3);
}
[Fact]
public void Execute_ReturnsEmpty_ForEmptyInput()
{
// Arrange
StringValue sourceValue = FormulaValue.New(string.Empty);
// Act
FormulaValue result = MessageText.StringInput.Execute(sourceValue);
// Assert
StringValue stringResult = Assert.IsType<StringValue>(result);
Assert.Empty(stringResult.Value);
}
[Fact]
public void Execute_ReturnsText_ForStringInput()
{
// Arrange
StringValue sourceValue = FormulaValue.New("wowsie");
// Act
FormulaValue result = MessageText.StringInput.Execute(sourceValue);
// Assert
StringValue stringResult = Assert.IsType<StringValue>(result);
Assert.Equal(sourceValue.Value, stringResult.Value);
}
[Fact]
public void Execute_ReturnsText_ForMessageInput()
{
// Arrange
RecordValue sourceValue = new ChatMessage(ChatRole.User, "test message").ToRecord();
// Act
FormulaValue result = MessageText.RecordInput.Execute(sourceValue);
// Assert
StringValue stringResult = Assert.IsType<StringValue>(result);
Assert.Equal("test message", stringResult.Value);
}
[Fact]
public void Execute_ReturnsEmpty_ForUnknownInput()
{
// Arrange
RecordValue sourceValue = FormulaValue.NewRecordFromFields(new NamedValue("Anything", FormulaValue.New(333)));
// Act
FormulaValue result = MessageText.RecordInput.Execute(sourceValue);
// Assert
StringValue stringResult = Assert.IsType<StringValue>(result);
Assert.Empty(stringResult.Value);
}
[Fact]
public void Execute_ReturnsText_ForMessagesInput()
{
// Arrange
TableValue sourceValue = new ChatMessage[]
{
new(ChatRole.User, "test message 1"),
new(ChatRole.User, "test message 2"),
}.ToTable();
// Act
FormulaValue result = MessageText.TableInput.Execute(sourceValue);
// Assert
StringValue stringResult = Assert.IsType<StringValue>(result);
Assert.Equal("test message 1\ntest message 2", stringResult.Value);
}
[Fact]
public void Execute_ReturnsEmpty_ForEmptyList()
{
// Arrange
TableValue sourceValue = Array.Empty<ChatMessage>().ToTable();
// Act
FormulaValue result = MessageText.TableInput.Execute(sourceValue);
// Assert
StringValue stringResult = Assert.IsType<StringValue>(result);
Assert.Empty(stringResult.Value);
}
}