Spotflow.InMemory.Azure 0.1.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Spotflow.InMemory.Azure --version 0.1.0
                    
NuGet\Install-Package Spotflow.InMemory.Azure -Version 0.1.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="Spotflow.InMemory.Azure" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Spotflow.InMemory.Azure" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Spotflow.InMemory.Azure" />
                    
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 Spotflow.InMemory.Azure --version 0.1.0
                    
#r "nuget: Spotflow.InMemory.Azure, 0.1.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 Spotflow.InMemory.Azure@0.1.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=Spotflow.InMemory.Azure&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Spotflow.InMemory.Azure&version=0.1.0
                    
Install as a Cake Tool

alternate text is missing from this package README image

<h1 align="center">Azure In-Memory SDKs for Testing</h1> <p align="center">Drop-in fakes of Azure .NET SDKs to make your test blazing-fast and reliable.</p>

<p align="center"> <a href="#supported-sdks">Supported SDKs</a> | <a href="#example">Example</a> | <a href="#key-features">Key features</a> | <a href="#why-should-i-use-it">Why Should I Use It?</a> | <a href="#how-it-works">How It Works</a> | <a href="#license">License</a> </p>

CI status

Supported SDKs

Package Relevant Azure SDK NuGet
Spotflow.InMemory.Azure.Storage Azure.Storage.Blobs, Azure.Data.Tables NuGet
Spotflow.InMemory.Azure.Storage.FluentAssertions NuGet
Spotflow.InMemory.Azure.EventHubs Azure.Messaging.EventHubs NuGet
Spotflow.InMemory.Azure.ServiceBus Azure.Messaging.ServiceBus NuGet
Spotflow.InMemory.Azure.ServiceBus.FluentAssertions NuGet
Spotflow.InMemory.Azure.KeyVault Azure.Security.KeyVault.Secrets NuGet

Example

See how the in-memory Azure SDKs can be used in your code, for example with Azure Storage:

Design

var storageAccount = new InMemoryStorageProvider().AddAccount();

// The InMemoryBlobContainerClient inherits from BlobContainerClient (from the official SDK)
// So it can be used as a drop-in replacement for the real BlobContainerClient in your tests
var containerClient = InMemoryBlobContainerClient.FromAccount(storageAccount, "test-container");

// From now on, you can use the BlobContainerClient methods as you're used to:
containerClient.Create();

await containerClient.UploadBlobAsync("my-blob", BinaryData.FromString("Hello World!"));

// The `containerClient` can now be used in your code as if it was a real BlobContainerClient:

await PrintBlobAsync(containerClient);

async Task PrintBlobAsync(BlobContainerClient container)
{
    var blob = container.GetBlobClient("my-blob");

    var response = await blob.DownloadContentAsync();

    Console.WriteLine(response.Value.Content.ToString());
    // Output: Hello World!
}

This design allows you to create a factory for SDK clients with two implementations: one that provides the official Azure SDK clients and another that provides in-memory clients. By selecting the appropriate factory, you can use the real implementation in your production code and the in-memory implementation in your tests.

You can learn how we recommend to use this library in the documentations for each SDK.

Key Features

  • Drop-in Replacement of the official Azure SDKs.
  • Blazing-fast thanks to the in-memory implementation.
  • No external dependencies, not even Docker.
  • Fault Injection: build resilient code thanks to simulated Azure outages in your tests.
  • Delay Injection: Examine behavior of your system under pressure of slowed-down operations.
  • TimeProvider Support: avoid flaky tests thanks to the time abstraction.
  • Fluent Assertions to conveniently test common scenarios.
  • Customizable: you can easily extend the functionality of the in-memory providers via before and after hooks.

Why Should I Use It?

There's been a lot written on why to prefer fakes over mocks in tests. Mocks are test-doubles that return pre-programmed responses to method calls. This can tightly couple your tests to implementation details, making them brittle and hard to maintain. Fakes, on the other hand, are lightweight implementations of real services that can seamlessly integrate into your tests. Using real services in tests is another approach, which is reasonable in many cases but can result in tests that are slow and harder to manage.

One major drawback of fakes is the initial effort required to create them. We have solved this problem by implementing them for you. This way, you can use the same interfaces and methods as in the real SDKs, but with the benefits of in-memory implementation.

How It Works

The Azure SDKs are designed for inheritance-based testability:

  • Important methods are virtual.
  • There are parameterless protected constructor available for all clients.
  • There are static factories for creating most models.

The in-memory clients (e.g. InMemoryBlobContainerClient or InMemoryEventHubConsumerClient) provided by this library are inheriting the Azure SDK clients so that they can be injected to any code that expected the actual Azure SDK clients (the BlobContainerClient or EventHubConsumerClient the previous example). The tested code can therefore depend directly on Azure SDK clients and only abstract away creation of these clients. This removes the need to design and implement custom client interfaces.

The in-memory clients have similar constructors as real clients but they all also require a so-called in-memory provider (e.g. InMemoryStorageProvider or InMemoryEventHubProvider). The in-memory providers emulate the functionality of the actual services for which the SDK clients are created for (e.g. Azure Storage or Azure Event Hubs). The providers allows to read, change and assert the internal state during testing. For most Azure SDK clients, the in-memory providers are exposing corresponding types representing actual state. For example for InMemoryBlobContainerClient: BlobContainerClient, there is InMemoryBlobContainer type exposed by the provider. The important difference is that the InMemoryBlobContainer is representing the actual state (in this case an existing Azure Storage Blob Container) while InMemoryBlobContainerClient might be representing container that does not yet exist.

Maintainers

Contributing

Please read our Contributing Guidelines to learn how you can contribute to this project.

License

This project is licensed under the MIT license.

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 was computed.  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 (4)

Showing the top 4 NuGet packages that depend on Spotflow.InMemory.Azure:

Package Downloads
Spotflow.InMemory.Azure.ServiceBus

In-memory implementation of the Azure Service Bus clients for convenient testing.

Spotflow.InMemory.Azure.Storage

In-memory implementation of the Azure Storage Blobs and Tables clients for convenient testing.

Spotflow.InMemory.Azure.KeyVault

In-memory implementation of the Azure Key Vault clients for convenient testing.

Spotflow.InMemory.Azure.EventHubs

In-memory implementation of the Azure Event Hubs clients for convenient testing.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.12.0 274 7/10/2025
0.11.0 761 5/17/2025
0.10.0 714 5/1/2025
0.9.4 2,977 3/14/2025
0.9.3 186 3/13/2025
0.9.2 349 2/26/2025
0.9.1 162 2/26/2025
0.9.0 140 2/26/2025
0.8.0 1,205 2/20/2025
0.7.0 479 2/4/2025
0.6.0 337 2/4/2025
0.5.0 634 12/2/2024
0.4.2 1,321 10/21/2024
0.4.1 12,264 10/16/2024
0.4.0 176 10/11/2024
0.3.1 3,536 9/30/2024
0.3.0 203 9/24/2024
0.2.0 677 8/17/2024
0.1.0 218 8/9/2024