AzureFunctions.TestFramework.CosmosDB 0.11.2

dotnet add package AzureFunctions.TestFramework.CosmosDB --version 0.11.2
                    
NuGet\Install-Package AzureFunctions.TestFramework.CosmosDB -Version 0.11.2
                    
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.CosmosDB" Version="0.11.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureFunctions.TestFramework.CosmosDB" Version="0.11.2" />
                    
Directory.Packages.props
<PackageReference Include="AzureFunctions.TestFramework.CosmosDB" />
                    
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.CosmosDB --version 0.11.2
                    
#r "nuget: AzureFunctions.TestFramework.CosmosDB, 0.11.2"
                    
#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.CosmosDB@0.11.2
                    
#: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.CosmosDB&version=0.11.2
                    
Install as a Cake Addin
#tool nuget:?package=AzureFunctions.TestFramework.CosmosDB&version=0.11.2
                    
Install as a Cake Tool

AzureFunctions.TestFramework.CosmosDB

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

Installation

dotnet add package AzureFunctions.TestFramework.CosmosDB

Supported bindings

Binding Attribute Description
[CosmosDBTrigger] Trigger Receives a batch of changed documents from the CosmosDB change feed
[CosmosDBInput] Input Reads documents from CosmosDB (point-read or query)
[CosmosDBOutput] Output Writes documents to CosmosDB — captured via FunctionInvocationResult

CosmosDB Trigger

Use InvokeCosmosDBAsync to simulate a CosmosDB change-feed trigger with a batch of changed documents.

Strongly-typed documents

var documents = new[]
{
    new TodoItem { Id = "1", Title = "Buy milk", IsComplete = false },
    new TodoItem { Id = "2", Title = "Write tests", IsComplete = true }
};

var result = await host.InvokeCosmosDBAsync("ProcessCosmosDocuments", documents);

Assert.True(result.Success);

Raw JSON

var json = """[{"id":"1","title":"Buy milk"},{"id":"2","title":"Write tests"}]""";

var result = await host.InvokeCosmosDBAsync("ProcessCosmosDocuments", json);

Assert.True(result.Success);

CosmosDB Input Binding

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

var host = await new FunctionsTestHostBuilder()
    .WithFunctionsAssembly(typeof(MyFunction).Assembly)
    .WithHostBuilderFactory(Program.CreateHostBuilder)
    // Single document for [CosmosDBInput(databaseName: "MyDb", containerName: "Items")]
    .WithCosmosDBInputDocuments("MyDb", "Items",
        new TodoItem { Id = "1", Title = "Injected item", IsComplete = false })
    .BuildAndStartAsync();

Use WithCosmosDBInputDocuments<T>(databaseName, containerName, IReadOnlyList<T> documents) to inject a list of documents, and WithCosmosDBInputJson(databaseName, containerName, json) to inject raw JSON.

Function example

[Function("ReadCosmosItem")]
public void Run(
    [QueueTrigger("items-queue")] string queueMessage,
    [CosmosDBInput(databaseName: "MyDb", containerName: "Items", Id = "%itemId%")] TodoItem? item)
{
    if (item is not null)
        _logger.LogInformation("Read item: {Title}", item.Title);
}

CosmosDB Output Binding

Output bindings are captured automatically via FunctionInvocationResult:

var result = await host.InvokeCosmosDBAsync("CreateCosmosDocument", documents);

Assert.True(result.Success);
var written = result.ReadOutputAs<TodoItem>("outputDocument");
Assert.Equal("expected-id", written?.Id);

Function example

[Function("CreateCosmosDocument")]
[CosmosDBOutput(databaseName: "MyDb", containerName: "Items")]
public TodoItem? Run([CosmosDBTrigger(...)] IReadOnlyList<TodoItem> documents)
{
    return documents.FirstOrDefault();
}

Testing across all four flavours

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

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

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.11.2 39 4/14/2026
0.11.1 47 4/13/2026
0.11.0 51 4/13/2026