VOOZH about

URL: https://www.nuget.org/packages/AzureFunctions.TestFramework.CosmosDB/

⇱ NuGet Gallery | AzureFunctions.TestFramework.CosmosDB 0.14.0




AzureFunctions.TestFramework.CosmosDB 0.14.0

dotnet add package AzureFunctions.TestFramework.CosmosDB --version 0.14.0
 
 
NuGet\Install-Package AzureFunctions.TestFramework.CosmosDB -Version 0.14.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.CosmosDB" Version="0.14.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureFunctions.TestFramework.CosmosDB" Version="0.14.0" />
 
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.14.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AzureFunctions.TestFramework.CosmosDB, 0.14.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.CosmosDB@0.14.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.CosmosDB&version=0.14.0
 
Install as a Cake Addin
#tool nuget:?package=AzureFunctions.TestFramework.CosmosDB&version=0.14.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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 Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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.14.0 98 5/25/2026
0.13.2 114 4/30/2026
0.12.0 109 4/20/2026
0.11.2 112 4/14/2026
0.11.1 107 4/13/2026
0.11.0 113 4/13/2026