Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public async Task KernelFunctionCanceledExceptionIncludeRequestInfoAsync()
catch (KernelFunctionCanceledException ex)
{
Assert.Equal("The invocation of function 'updateRepair' was canceled.", ex.Message);
Assert.Equal("Patch", ex.Data["http.request.method"]);
Assert.Equal("https://piercerepairsapi.azurewebsites.net/repairs", ex.Data["url.full"]);
Assert.NotNull(ex.InnerException);
Assert.Equal("Patch", ex.InnerException.Data["http.request.method"]);
Assert.Equal("https://piercerepairsapi.azurewebsites.net/repairs", ex.InnerException.Data["url.full"]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
Expand Down Expand Up @@ -432,7 +433,12 @@ private static void HandleException(
// visible to a consumer if that's needed.
if (ex is OperationCanceledException cancelEx)
{
throw new KernelFunctionCanceledException(kernel, kernelFunction, arguments, result, cancelEx);
KernelFunctionCanceledException kernelEx = new(kernel, kernelFunction, arguments, result, cancelEx);
foreach (DictionaryEntry entry in cancelEx.Data)
{
kernelEx.Data.Add(entry.Key, entry.Value);
Comment thread
markwallace-microsoft marked this conversation as resolved.
}
throw kernelEx;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -814,13 +814,13 @@ async Task AssertParameterType<T>(T expected)
{
var d = (T actual) =>
{
//Check the argument is of the expected type
//Check the argument is of the operationCancelled type
if (actual is not null)
{
Assert.IsType<T>(actual);
}

//Check the argument value is the expected value
//Check the argument value is the operationCancelled value
Assert.Equal(expected, actual);
};

Expand Down Expand Up @@ -1375,6 +1375,25 @@ public async Task ItCanDeserializeThirdPartyJsonPrimitivesAsync()
Assert.Equal(28, actualArgValue.Id);
}

[Fact]
public async Task ItThrowsKernelFunctionCanceledExceptionWhenOperationIsCanceledAsync()
{
// Arrange
var arguments = new KernelArguments();
var operationCancelled = new OperationCanceledException("OperationCanceledException");
operationCancelled.Data.Add("Key", "Value");
KernelFunction func = KernelFunctionFactory.CreateFromMethod(() => { throw operationCancelled; });

// Act
Exception actual = await Record.ExceptionAsync(() => func.InvokeAsync(this._kernel, arguments));

// Assert
Assert.NotNull(actual);
Assert.True(actual is KernelFunctionCanceledException);
Assert.True(actual.Data.Contains("Key"));
Assert.Equal("Value", actual.Data["Key"]);
}

#pragma warning disable CA1812 // Avoid uninstantiated internal classes
private sealed class CustomTypeForJsonTests
#pragma warning restore CA1812 // Avoid uninstantiated internal classes
Expand Down