elsa-core/test/unit/Elsa.Activities.UnitTests/Http/Helpers/TestHttpMessageHandler.cs
Sipke Schoorstra 84c04341f9
Add unit tests for FlowSendHttpRequest activity and refactor helper utilities (#6997)
* Add unit tests for `FlowFork` activity and enhance test utilities

- Introduce `FlowForkTests` to validate activity behavior with various branch configurations.
- Extend `ActivityExecutionContextExtensions` with methods to retrieve and check outcomes.
- Modify `ActivityTestFixture` to ensure activities transition to `Running` status before execution.

* Add unit tests for `FlowSwitch` activity and extend test utilities

- Implement `FlowSwitchTests` to verify behavior based on switch cases, modes, and literal expressions.
- Enhance `ActivityExecutionContextExtensions` with methods to retrieve and check outcomes in execution context.

* Update test guidelines to include examples for checking activity outcomes

- Add unit test examples for validating multiple and default outcomes.
- Extend documentation to describe new `ActivityExecutionContextExtensions` methods: `GetOutcomes` and `HasOutcome`.

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Simplify `GetOutcomes` method in `ActivityExecutionContextExtensions`.

* Add unit tests for `FlowSendHttpRequest` activity and refactor helper utilities

- Introduce `FlowSendHttpRequestTests` to validate activity behavior across various scenarios.
- Add utility methods in `SendHttpRequestTestHelpers` for creating mock responses and exceptions.
- Refactor `Helpers` namespace to `Http.Helpers` for better organization.
- Update project file to reflect namespace adjustments.

* Update test/unit/Elsa.Activities.UnitTests/Elsa.Activities.UnitTests.csproj

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-21 15:36:54 +02:00

18 lines
818 B
C#

namespace Elsa.Activities.UnitTests.Http.Helpers;
/// <summary>
/// Custom test HTTP message handler that allows full control over HTTP responses for testing.
/// Use this class to simulate different HTTP scenarios without making actual network calls.
/// </summary>
/// <param name="sendAsyncFunc">Function that defines how to handle HTTP requests and generate responses</param>
public class TestHttpMessageHandler(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> sendAsyncFunc) : HttpMessageHandler
{
/// <summary>
/// Handles HTTP requests using the provided function.
/// </summary>
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return sendAsyncFunc(request, cancellationToken);
}
}