Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fortedigital/forte.functions.testable
In-memory orchestration for testing Durable Functions
https://github.com/fortedigital/forte.functions.testable
azure-functions azure-functions-v2 durable-functions net-core unit-testing
Last synced: about 2 months ago
JSON representation
In-memory orchestration for testing Durable Functions
- Host: GitHub
- URL: https://github.com/fortedigital/forte.functions.testable
- Owner: fortedigital
- License: mit
- Created: 2019-04-24T10:58:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-25T20:43:11.000Z (over 1 year ago)
- Last Synced: 2024-08-31T03:18:55.288Z (5 months ago)
- Topics: azure-functions, azure-functions-v2, durable-functions, net-core, unit-testing
- Language: C#
- Size: 145 KB
- Stars: 2
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Forte.Functions.Testable
In-memory orchestration for testing Durable Functions[![Build Status](https://fortedigital.visualstudio.com/Forte.OpenSource/_apis/build/status/Forte.Functions.Testable?branchName=master)](https://fortedigital.visualstudio.com/Forte.OpenSource/_build/latest?definitionId=102&branchName=master)
[![Nuget](https://img.shields.io/nuget/v/Forte.Functions.Testable.svg?label=NuGet)](https://www.nuget.org/packages/Forte.Functions.Testable/)
By leveraging `IDurableOrchestrationClient` and the related interfaces, this project implements an `InMemoryOrchestrationClient` which allows durable functions to be executed in-memory and observed with no mocking. For example, you could write a test such as:
```c#
[TestMethod]
public async Task Can_execute_durable_function()
{
var input = new MyFunctionInput();var client = new InMemoryOrchestrationClient(typeof(MyFunction).Assembly);
var instanceId = await client
.StartNewAsync(nameof(MyFunction.DurableFunction), input);await client.WaitForOrchestrationToReachStatus(instanceId, OrchestrationRuntimeStatus.Completed);
var status = await client.GetStatusAsync(instanceId);
Assert.AreEqual(OrchestrationRuntimeStatus.Completed, status.RuntimeStatus);
}
```Tests can use the `WaitForOrchestrationToReachStatus`, `WaitForOrchestrationToExpectEvent`, `RaiseEventAsync` and `Timeshift` methods on the orchestration client to direct the durable function.
Contrast this with the approach suggested in https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-unit-testing which requires a lot of brittle mocking/setup to accomplish this.
The implementation supports most features of durable functions including activities, retries, sub-orchestrations, external events etc. The major difference is of course that this orchestration client does not have the replay-behavior of durable functions, but simply executes the durable function in-memory with async/await-like behavior.
Note: Durable Entities are not yet supported and will throw `NotImplementedException`s.