microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Tests/Microsoft.Teams.AI.Tests/FunctionTests.cs
76lines · modecode
| 1 | using Microsoft.Teams.AI.Annotations; |
| 2 | |
| 3 | namespace Microsoft.Teams.AI.Tests; |
| 4 | |
| 5 | public class FunctionTests |
| 6 | { |
| 7 | [Fact] |
| 8 | public void Test_Function_GeneratesParametersSchema_FromDelegate() |
| 9 | { |
| 10 | // Arrange & Act |
| 11 | var function = new Function( |
| 12 | "test_function", |
| 13 | "A test function", |
| 14 | ([Param("name")] string name, int age) => $"Hello {name}, age {age}" |
| 15 | ); |
| 16 | |
| 17 | // Assert |
| 18 | Assert.NotNull(function.Parameters); |
| 19 | } |
| 20 | |
| 21 | [Fact] |
| 22 | public void Test_Function_GeneratesParametersSchema_WithParamAttribute() |
| 23 | { |
| 24 | // Arrange & Act |
| 25 | var function = new Function( |
| 26 | "pokemon_search", |
| 27 | "Search for pokemon", |
| 28 | ([Param("pokemon_name")] string pokemonName) => $"Searching for {pokemonName}" |
| 29 | ); |
| 30 | |
| 31 | // Assert |
| 32 | Assert.NotNull(function.Parameters); |
| 33 | } |
| 34 | |
| 35 | [Fact] |
| 36 | public void Test_Function_NoParameters_ReturnsNullSchema() |
| 37 | { |
| 38 | // Arrange & Act |
| 39 | var function = new Function( |
| 40 | "no_params_function", |
| 41 | "A function with no parameters", |
| 42 | () => "No params" |
| 43 | ); |
| 44 | |
| 45 | // Assert |
| 46 | Assert.Null(function.Parameters); |
| 47 | } |
| 48 | |
| 49 | [Fact] |
| 50 | public void Test_Function_OptionalParameters_MarkedCorrectly() |
| 51 | { |
| 52 | // Arrange & Act |
| 53 | var function = new Function( |
| 54 | "optional_params_function", |
| 55 | "A function with optional parameters", |
| 56 | (string required, string optional = "default") => $"{required} {optional}" |
| 57 | ); |
| 58 | |
| 59 | // Assert |
| 60 | Assert.NotNull(function.Parameters); |
| 61 | } |
| 62 | |
| 63 | [Fact] |
| 64 | public void Test_Function_MultipleParameters_GeneratesSchema() |
| 65 | { |
| 66 | // Arrange & Act |
| 67 | var function = new Function( |
| 68 | "multi_param_function", |
| 69 | "A function with multiple parameters", |
| 70 | (string name, int age, bool active) => $"{name} {age} {active}" |
| 71 | ); |
| 72 | |
| 73 | // Assert |
| 74 | Assert.NotNull(function.Parameters); |
| 75 | } |
| 76 | } |