Files
Copilot c72455508b .NET: Add comprehensive test classes for extension methods in Microsoft.Agents.AI.Workflows.Declarative (#1555)
* Initial plan

* Add test classes for extension methods

Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>

* Fix test issues and document bug in ExpandoObjectExtensions

Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>

* Address code review feedback - shorten Skip messages and add explanatory comments

Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>

* Replace Fields.ToDictionary with GetField calls and fix ExpandoObjectExtensions bug

Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>

* Update dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Extensions/DataValueExtensionsTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/Extensions/DataValueExtensionsTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove unused using statement from DialogBaseExtensionsTests

Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>

* Add proper WrapWithBot tests using AdaptiveDialog and OnActivity

Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>

* Cleanup

* Better

* Better

* One more test

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: crickman <66376200+crickman@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Chris Rickman <crickman@microsoft.com>
2025-10-20 15:21:46 +00:00

70 lines
2.4 KiB
C#

// 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
FormulaValue sourceValue = FormulaValue.New(string.Empty);
StringValue stringValue = Assert.IsType<StringValue>(sourceValue);
// Act
FormulaValue result = UserMessage.Execute(stringValue);
// Assert
Assert.IsType<BlankValue>(result);
}
[Fact]
public void Execute_ReturnsExpectedRecord_ForNonEmptyInput()
{
const string Text = "Hello";
FormulaValue sourceValue = FormulaValue.New(Text);
StringValue stringValue = Assert.IsType<StringValue>(sourceValue);
FormulaValue result = UserMessage.Execute(stringValue);
RecordValue recordResult = Assert.IsType<RecordValue>(result, exactMatch: false);
// Discriminator
FormulaValue discriminator = recordResult.GetField(TypeSchema.Discriminator);
StringValue discriminatorValue = Assert.IsType<StringValue>(discriminator);
Assert.Equal(nameof(ChatMessage), discriminatorValue.Value);
// Role
FormulaValue role = recordResult.GetField(TypeSchema.Message.Fields.Role);
StringValue roleValue = Assert.IsType<StringValue>(role);
Assert.Equal(ChatRole.User.Value, roleValue.Value);
// Content table
FormulaValue content = recordResult.GetField(TypeSchema.Message.Fields.Content);
TableValue table = Assert.IsType<TableValue>(content, exactMatch: false);
List<RecordValue> rows = table.Rows.Select(value => value.Value).ToList();
Assert.Single(rows);
StringValue contentType = Assert.IsType<StringValue>(rows[0].GetField(TypeSchema.Message.Fields.ContentType));
Assert.Equal(TypeSchema.Message.ContentTypes.Text, contentType.Value);
StringValue contentValue = Assert.IsType<StringValue>(rows[0].GetField(TypeSchema.Message.Fields.ContentValue));
Assert.Equal(Text, contentValue.Value);
}
}