forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net Kernel Examples as tests (microsoft#4526)
### Motivation and Context Convert Kernel Examples as Integration Tests.
- Loading branch information
1 parent
f9bef63
commit b99b780
Showing
70 changed files
with
1,565 additions
and
1,204 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using RepoUtils; | ||
using Xunit.Abstractions; | ||
|
||
namespace Examples; | ||
|
||
public abstract class BaseTest | ||
{ | ||
protected ITestOutputHelper Output { get; } | ||
|
||
protected BaseTest(ITestOutputHelper output) | ||
{ | ||
this.Output = output; | ||
LoadUserSecrets(); | ||
} | ||
|
||
private static void LoadUserSecrets() | ||
{ | ||
IConfigurationRoot configRoot = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.Development.json", true) | ||
.AddEnvironmentVariables() | ||
.AddUserSecrets<Env>() | ||
.Build(); | ||
|
||
TestConfiguration.Initialize(configRoot); | ||
} | ||
|
||
/// <summary> | ||
/// This method can be substituted by Console.WriteLine when used in Console apps. | ||
/// </summary> | ||
/// <param name="target">Target object to write</param> | ||
protected void WriteLine(object? target = null) | ||
{ | ||
this.Output.WriteLine(target ?? string.Empty); | ||
} | ||
|
||
/// <summary> | ||
/// Current interface ITestOutputHelper does not have a Write method. This extension method adds it to make it analogous to Console.Write when used in Console apps. | ||
/// </summary> | ||
/// <param name="target">Target object to write</param> | ||
protected void Write(object? target = null) | ||
{ | ||
this.Output.WriteLine(target ?? string.Empty); | ||
} | ||
} |
18 changes: 13 additions & 5 deletions
18
dotnet/samples/KernelSyntaxExamples/Example01_MethodFunctions.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 |
---|---|---|
@@ -1,23 +1,31 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.SemanticKernel.Plugins.Core; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
public static class Example01_MethodFunctions | ||
namespace Examples; | ||
|
||
public class Example01_MethodFunctions : BaseTest | ||
{ | ||
public static Task RunAsync() | ||
[Fact] | ||
public Task RunAsync() | ||
{ | ||
Console.WriteLine("======== Functions ========"); | ||
this.WriteLine("======== Functions ========"); | ||
|
||
// Load native plugin | ||
var text = new TextPlugin(); | ||
|
||
// Use function without kernel | ||
var result = text.Uppercase("ciao!"); | ||
|
||
Console.WriteLine(result); | ||
this.WriteLine(result); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
public Example01_MethodFunctions(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
} |
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
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
Oops, something went wrong.