db620d33df
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
121 lines
3.5 KiB
C#
121 lines
3.5 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
|
|
using Microsoft.Agents.ObjectModel;
|
|
using Microsoft.PowerFx.Types;
|
|
|
|
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel;
|
|
|
|
/// <summary>
|
|
/// Tests for <see cref="ParseValueExecutor"/>.
|
|
/// </summary>
|
|
public sealed class ParseValueExecutorTest(ITestOutputHelper output) : WorkflowActionExecutorTest(output)
|
|
{
|
|
[Fact]
|
|
public async Task ParseRecordAsync()
|
|
{
|
|
// Arrange
|
|
RecordDataType.Builder recordBuilder =
|
|
new()
|
|
{
|
|
Properties =
|
|
{
|
|
{"key1", new PropertyInfo.Builder() { Type = DataType.String } },
|
|
}
|
|
};
|
|
|
|
// Act & Assert
|
|
await this.ExecuteTestAsync(
|
|
this.FormatDisplayName(nameof(ParseRecordAsync)),
|
|
recordBuilder,
|
|
@"{ ""key1"": ""val1"" }",
|
|
FormulaValue.NewRecordFromFields(new NamedValue("key1", FormulaValue.New("val1"))));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ParseTableAsync()
|
|
{
|
|
// Arrange, Act & Assert
|
|
await this.ExecuteTestAsync(
|
|
this.FormatDisplayName(nameof(ParseTableAsync)),
|
|
DataType.EmptyTable,
|
|
@"[""apple"",""banana"",""cat""]",
|
|
FormulaValue.NewSingleColumnTable(FormulaValue.New("apple"), FormulaValue.New("banana"), FormulaValue.New("cat")));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ParseBooleanAsync()
|
|
{
|
|
// Arrange, Act & Assert
|
|
await this.ExecuteTestAsync(
|
|
this.FormatDisplayName(nameof(ParseBooleanAsync)),
|
|
new BooleanDataType.Builder(),
|
|
"True",
|
|
FormulaValue.New(true));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ParseNumberAsync()
|
|
{
|
|
// Arrange, Act & Assert
|
|
await this.ExecuteTestAsync(
|
|
this.FormatDisplayName(nameof(ParseNumberAsync)),
|
|
new NumberDataType.Builder(),
|
|
"42",
|
|
FormulaValue.New(42));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ParseStringAsync()
|
|
{
|
|
// Arrange, Act & Assert
|
|
await this.ExecuteTestAsync(
|
|
this.FormatDisplayName(nameof(ParseStringAsync)),
|
|
new StringDataType.Builder(),
|
|
"Hello, World!",
|
|
FormulaValue.New("Hello, World!"));
|
|
}
|
|
|
|
private async Task ExecuteTestAsync(
|
|
string displayName,
|
|
DataType.Builder dataBuilder,
|
|
string sourceText,
|
|
FormulaValue expectedValue)
|
|
{
|
|
ParseValue model =
|
|
this.CreateModel(
|
|
displayName,
|
|
"Target",
|
|
dataBuilder,
|
|
sourceText);
|
|
|
|
// Act
|
|
ParseValueExecutor action = new(model, this.State);
|
|
await this.ExecuteAsync(action);
|
|
|
|
// Assert
|
|
VerifyModel(model, action);
|
|
this.VerifyState("Target", expectedValue);
|
|
}
|
|
|
|
private ParseValue CreateModel(
|
|
string displayName,
|
|
string variableName,
|
|
DataType.Builder typeBuilder,
|
|
string sourceText)
|
|
{
|
|
ParseValue.Builder actionBuilder =
|
|
new()
|
|
{
|
|
Id = this.CreateActionId(),
|
|
DisplayName = this.FormatDisplayName(displayName),
|
|
ValueType = typeBuilder,
|
|
Variable = PropertyPath.TopicVariable(variableName),
|
|
Value = new ValueExpression.Builder(ValueExpression.Literal(StringDataValue.Create(sourceText))),
|
|
};
|
|
|
|
return AssignParent<ParseValue>(actionBuilder);
|
|
}
|
|
}
|