-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Add missing XxFromFunctions members (#4549)
Following the same pattern used by FromType and FromObject
- Loading branch information
1 parent
b7defcf
commit 0772d01
Showing
8 changed files
with
305 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
dotnet/src/SemanticKernel.UnitTests/Functions/KernelExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Xunit; | ||
|
||
namespace SemanticKernel.UnitTests.Functions; | ||
|
||
public class KernelExtensionsTests | ||
{ | ||
[Fact] | ||
public void CreatePluginFromFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
KernelPlugin plugin = kernel.CreatePluginFromFunctions("coolplugin", new[] | ||
{ | ||
kernel.CreateFunctionFromMethod(() => { }, "Function1"), | ||
kernel.CreateFunctionFromMethod(() => { }, "Function2"), | ||
}); | ||
|
||
Assert.NotNull(plugin); | ||
Assert.Empty(kernel.Plugins); | ||
|
||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Empty(plugin.Description); | ||
Assert.Equal(2, plugin.FunctionCount); | ||
Assert.True(plugin.Contains("Function1")); | ||
Assert.True(plugin.Contains("Function2")); | ||
} | ||
|
||
[Fact] | ||
public void CreateEmptyPluginFromFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
KernelPlugin plugin = kernel.CreatePluginFromFunctions("coolplugin"); | ||
|
||
Assert.NotNull(plugin); | ||
Assert.Empty(kernel.Plugins); | ||
|
||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Empty(plugin.Description); | ||
Assert.Empty(plugin); | ||
Assert.Equal(0, plugin.FunctionCount); | ||
} | ||
|
||
[Fact] | ||
public void CreatePluginFromDescriptionAndFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
KernelPlugin plugin = kernel.CreatePluginFromFunctions("coolplugin", "the description", new[] | ||
{ | ||
kernel.CreateFunctionFromMethod(() => { }, "Function1"), | ||
kernel.CreateFunctionFromMethod(() => { }, "Function2"), | ||
}); | ||
|
||
Assert.NotNull(plugin); | ||
Assert.Empty(kernel.Plugins); | ||
|
||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Equal("the description", plugin.Description); | ||
Assert.Equal(2, plugin.FunctionCount); | ||
Assert.True(plugin.Contains("Function1")); | ||
Assert.True(plugin.Contains("Function2")); | ||
} | ||
|
||
[Fact] | ||
public void ImportPluginFromFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
kernel.ImportPluginFromFunctions("coolplugin", new[] | ||
{ | ||
kernel.CreateFunctionFromMethod(() => { }, "Function1"), | ||
kernel.CreateFunctionFromMethod(() => { }, "Function2"), | ||
}); | ||
|
||
Assert.Single(kernel.Plugins); | ||
|
||
KernelPlugin plugin = kernel.Plugins["coolplugin"]; | ||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Empty(plugin.Description); | ||
Assert.NotNull(plugin); | ||
|
||
Assert.Equal(2, plugin.FunctionCount); | ||
Assert.True(plugin.Contains("Function1")); | ||
Assert.True(plugin.Contains("Function2")); | ||
} | ||
|
||
[Fact] | ||
public void ImportPluginFromDescriptionAndFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
kernel.ImportPluginFromFunctions("coolplugin", "the description", new[] | ||
{ | ||
kernel.CreateFunctionFromMethod(() => { }, "Function1"), | ||
kernel.CreateFunctionFromMethod(() => { }, "Function2"), | ||
}); | ||
|
||
Assert.Single(kernel.Plugins); | ||
|
||
KernelPlugin plugin = kernel.Plugins["coolplugin"]; | ||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Equal("the description", plugin.Description); | ||
Assert.NotNull(plugin); | ||
|
||
Assert.Equal(2, plugin.FunctionCount); | ||
Assert.True(plugin.Contains("Function1")); | ||
Assert.True(plugin.Contains("Function2")); | ||
} | ||
|
||
[Fact] | ||
public void AddFromFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
kernel.Plugins.AddFromFunctions("coolplugin", new[] | ||
{ | ||
kernel.CreateFunctionFromMethod(() => { }, "Function1"), | ||
kernel.CreateFunctionFromMethod(() => { }, "Function2"), | ||
}); | ||
|
||
Assert.Single(kernel.Plugins); | ||
|
||
KernelPlugin plugin = kernel.Plugins["coolplugin"]; | ||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Empty(plugin.Description); | ||
Assert.NotNull(plugin); | ||
|
||
Assert.Equal(2, plugin.FunctionCount); | ||
Assert.True(plugin.Contains("Function1")); | ||
Assert.True(plugin.Contains("Function2")); | ||
} | ||
|
||
[Fact] | ||
public void AddFromDescriptionAndFunctions() | ||
{ | ||
Kernel kernel = new(); | ||
|
||
kernel.Plugins.AddFromFunctions("coolplugin", "the description", new[] | ||
{ | ||
kernel.CreateFunctionFromMethod(() => { }, "Function1"), | ||
kernel.CreateFunctionFromMethod(() => { }, "Function2"), | ||
}); | ||
|
||
Assert.Single(kernel.Plugins); | ||
|
||
KernelPlugin plugin = kernel.Plugins["coolplugin"]; | ||
Assert.Equal("coolplugin", plugin.Name); | ||
Assert.Equal("the description", plugin.Description); | ||
Assert.NotNull(plugin); | ||
|
||
Assert.Equal(2, plugin.FunctionCount); | ||
Assert.True(plugin.Contains("Function1")); | ||
Assert.True(plugin.Contains("Function2")); | ||
} | ||
} |
Oops, something went wrong.