mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Refine RouteBuilder test helpers
Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/012f3b3b-acb9-4869-9084-b767cbe1885b Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
2b66bad6b3
commit
e59b9327db
@@ -423,21 +423,21 @@ public sealed class RouteBuilderTests
|
||||
routeBuilder.AddHandler<string, string>((message, context, cancellationToken) =>
|
||||
{
|
||||
invocation.Capture(message, context, cancellationToken);
|
||||
return message.ToUpperInvariant();
|
||||
return NormalizeHandlerResult(message);
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
routeBuilder.AddHandler<string, string>((message, context) =>
|
||||
{
|
||||
invocation.Capture(message, context);
|
||||
return message.ToUpperInvariant();
|
||||
return NormalizeHandlerResult(message);
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
Func<string, IWorkflowContext, CancellationToken, ValueTask<string>> asyncHandlerWithCancellation = (message, context, cancellationToken) =>
|
||||
{
|
||||
invocation.Capture(message, context, cancellationToken);
|
||||
return ValueTask.FromResult(message.ToUpperInvariant());
|
||||
return ValueTask.FromResult(NormalizeHandlerResult(message));
|
||||
};
|
||||
routeBuilder.AddHandler<string, string>(asyncHandlerWithCancellation);
|
||||
break;
|
||||
@@ -445,7 +445,7 @@ public sealed class RouteBuilderTests
|
||||
Func<string, IWorkflowContext, ValueTask<string>> asyncHandler = (message, context) =>
|
||||
{
|
||||
invocation.Capture(message, context);
|
||||
return ValueTask.FromResult(message.ToUpperInvariant());
|
||||
return ValueTask.FromResult(NormalizeHandlerResult(message));
|
||||
};
|
||||
routeBuilder.AddHandler<string, string>(asyncHandler);
|
||||
break;
|
||||
@@ -491,21 +491,21 @@ public sealed class RouteBuilderTests
|
||||
routeBuilder.AddCatchAll<string>((message, context, cancellationToken) =>
|
||||
{
|
||||
invocation.Capture(message, context, cancellationToken);
|
||||
return GetPayloadValue(message).ToUpperInvariant();
|
||||
return NormalizeCatchAllResult(message);
|
||||
});
|
||||
break;
|
||||
case 1:
|
||||
routeBuilder.AddCatchAll<string>((message, context) =>
|
||||
{
|
||||
invocation.Capture(message, context);
|
||||
return GetPayloadValue(message).ToUpperInvariant();
|
||||
return NormalizeCatchAllResult(message);
|
||||
});
|
||||
break;
|
||||
case 2:
|
||||
Func<PortableValue, IWorkflowContext, CancellationToken, ValueTask<string>> asyncCatchAllWithCancellation = (message, context, cancellationToken) =>
|
||||
{
|
||||
invocation.Capture(message, context, cancellationToken);
|
||||
return ValueTask.FromResult(GetPayloadValue(message).ToUpperInvariant());
|
||||
return ValueTask.FromResult(NormalizeCatchAllResult(message));
|
||||
};
|
||||
routeBuilder.AddCatchAll<string>(asyncCatchAllWithCancellation);
|
||||
break;
|
||||
@@ -513,7 +513,7 @@ public sealed class RouteBuilderTests
|
||||
Func<PortableValue, IWorkflowContext, ValueTask<string>> asyncCatchAll = (message, context) =>
|
||||
{
|
||||
invocation.Capture(message, context);
|
||||
return ValueTask.FromResult(GetPayloadValue(message).ToUpperInvariant());
|
||||
return ValueTask.FromResult(NormalizeCatchAllResult(message));
|
||||
};
|
||||
routeBuilder.AddCatchAll<string>(asyncCatchAll);
|
||||
break;
|
||||
@@ -524,6 +524,10 @@ public sealed class RouteBuilderTests
|
||||
|
||||
private static bool UsesCancellationToken(int overload) => overload is 0 or 2;
|
||||
|
||||
private static string NormalizeHandlerResult(string message) => message.ToUpperInvariant();
|
||||
|
||||
private static string NormalizeCatchAllResult(PortableValue message) => GetPayloadValue(message).ToUpperInvariant();
|
||||
|
||||
private static string GetPayloadValue(PortableValue message)
|
||||
{
|
||||
return message.As<TestPayload>() is TestPayload payload
|
||||
|
||||
Reference in New Issue
Block a user