AzureFunctions.TestFramework.Sql 0.12.0

dotnet add package AzureFunctions.TestFramework.Sql --version 0.12.0
                    
NuGet\Install-Package AzureFunctions.TestFramework.Sql -Version 0.12.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AzureFunctions.TestFramework.Sql" Version="0.12.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureFunctions.TestFramework.Sql" Version="0.12.0" />
                    
Directory.Packages.props
<PackageReference Include="AzureFunctions.TestFramework.Sql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AzureFunctions.TestFramework.Sql --version 0.12.0
                    
#r "nuget: AzureFunctions.TestFramework.Sql, 0.12.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AzureFunctions.TestFramework.Sql@0.12.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AzureFunctions.TestFramework.Sql&version=0.12.0
                    
Install as a Cake Addin
#tool nuget:?package=AzureFunctions.TestFramework.Sql&version=0.12.0
                    
Install as a Cake Tool

AzureFunctions.TestFramework.Sql

Azure SQL Trigger, Input, and Output binding support for the Azure Functions Test Framework.

Installation

dotnet add package AzureFunctions.TestFramework.Sql

Supported bindings

Binding Attribute Description
[SqlTrigger] Trigger Receives a batch of row changes from SQL change tracking
[SqlInput] Input Reads rows from a SQL table or view via a query
[SqlOutput] Output Upserts rows into a SQL table — captured via FunctionInvocationResult

SQL Trigger

Use InvokeSqlAsync to simulate a SQL change-tracking trigger with a batch of row changes.

Strongly-typed changes

using Microsoft.Azure.Functions.Worker.Extensions.Sql;

var changes = new[]
{
    new SqlChange<Product>(SqlChangeOperation.Insert, new Product { Id = 1, Name = "Widget" }),
    new SqlChange<Product>(SqlChangeOperation.Update, new Product { Id = 2, Name = "Gadget" })
};

var result = await host.InvokeSqlAsync("ProcessSqlChanges", changes);

Assert.True(result.Success);

Raw JSON

var json = """[{"operation":0,"item":{"id":1,"name":"Widget"}}]""";

var result = await host.InvokeSqlAsync("ProcessSqlChanges", json);

Assert.True(result.Success);

SQL Input Binding

Register fake rows via the builder so they are injected automatically for every invocation:

var host = await new FunctionsTestHostBuilder()
    .WithFunctionsAssembly(typeof(MyFunction).Assembly)
    .WithHostBuilderFactory(Program.CreateHostBuilder)
    // Inject rows for [SqlInput(commandText: "SELECT * FROM Products", commandType: CommandType.Text, ...)]
    .WithSqlInputRows("SELECT * FROM Products",
        new List<Product>
        {
            new Product { Id = 1, Name = "Widget" },
            new Product { Id = 2, Name = "Gadget" }
        })
    .BuildAndStartAsync();

Use WithSqlInputRows<T>(commandText, T row) to inject a single row, WithSqlInputRows<T>(commandText, IReadOnlyList<T> rows) to inject a list, and WithSqlInputJson(commandText, json) to inject raw JSON.

The commandText must exactly match the value declared in the [SqlInput] attribute.

Function example

[Function("ReadSqlProducts")]
public void Run(
    [QueueTrigger("products-queue")] string queueMessage,
    [SqlInput(commandText: "SELECT * FROM Products",
              commandType: System.Data.CommandType.Text,
              connectionStringSetting: "SqlConnection")] IEnumerable<Product> products)
{
    foreach (var product in products)
        _logger.LogInformation("Product: {Name}", product.Name);
}

SQL Output Binding

Output bindings are captured automatically via FunctionInvocationResult:

var changes = new[] { new SqlChange<Product>(SqlChangeOperation.Insert, new Product { Id = 1, Name = "Widget" }) };
var result = await host.InvokeSqlAsync("UpsertSqlProduct", changes);

Assert.True(result.Success);
var written = result.ReadReturnValueAs<Product>();
Assert.Equal(1, written?.Id);

Function example

[Function("UpsertSqlProduct")]
[SqlOutput(tableName: "Products", connectionStringSetting: "SqlConnection")]
public Product? Run(
    [SqlTrigger(tableName: "Changes", connectionStringSetting: "SqlConnection")]
    IReadOnlyList<SqlChange<Product>> changes)
{
    return changes.FirstOrDefault()?.Item;
}

Testing across all four flavours

Add the SQL package reference to your test project and all four function-app test flavours:

<PackageReference Include="AzureFunctions.TestFramework.Sql" />

See the 4-flavour matrix test pattern for the concrete test class structure.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.12.0 40 4/20/2026