elsa-core/test/integration/Elsa.Http.IntegrationTests/README.md
Sipke Schoorstra ad87ab96fd
Improves HTTP context loss error handling (#7187)
* Remove bookmark-based resumption logic for lost HTTP context scenarios in `WriteHttpResponse` and `WriteFileHttpResponse`.

Simplify error handling by throwing descriptive exceptions for workflows resuming without an available HTTP context.

* Add integration tests for HTTP context loss scenarios in `WriteHttpResponse` and `WriteFileHttpResponse`.

* Add integration tests for handling HTTP context loss in response activities.

* Replace bookmark-based logic with fault exceptions in tests for `WriteHttpResponse` and `WriteFileHttpResponse` when HTTP context is unavailable.

* Update agent-logs/http-context-loss-error-messaging.md

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

* Update test/integration/Elsa.Http.IntegrationTests/Elsa.Http.IntegrationTests.csproj

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

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-12 16:51:30 +01:00

81 lines
2.7 KiB
Markdown

# Elsa.Http Integration Tests
This test project contains integration tests for HTTP-related activities in Elsa Workflows, specifically focusing on HTTP context loss scenarios.
## Status
**Tests are working!** All tests pass successfully and are properly discovered by xUnit.
## Test Coverage
### HttpContextLossTests
Tests that verify the behavior of HTTP response activities when the HTTP context is lost during workflow execution.
#### Test Scenarios
1. **WriteHttpResponse_WithNoHttpContext_ShouldRecordIncident**
- Verifies that `WriteHttpResponse` activity records an incident when HTTP context is null
- Validates that the incident message clearly explains the HTTP context loss scenario
- **Status**: ✅ Passing
2. **WriteFileHttpResponse_WithNoHttpContext_ShouldRecordIncident**
- Verifies that `WriteFileHttpResponse` activity records an incident when HTTP context is null
- Validates the incident message contains expected information
- **Status**: ✅ Passing
## Expected Behavior
When HTTP context is not available:
- **Fault Code**: `NoHttpContext`
- **Fault Category**: `HTTP`
- **Fault Type**: `System`
- **Error Message**: Detailed explanation including:
- What happened: HTTP context was lost during workflow execution
- Why it happened: Workflow suspended and resumed in different execution context
- Common scenarios: Background processing, virtual actor, workflow transition
- Impact: Original HTTP request context no longer available
- **Result**: An `ActivityIncident` is recorded with the fault message
## Project Structure
```
Elsa.Http.IntegrationTests/
├── Activities/
│ ├── HttpContextLossTests.cs # Test class using WorkflowTestFixture
│ └── Workflows/
│ ├── WriteHttpResponseWithoutHttpContextWorkflow.cs
│ └── WriteFileHttpResponseWithoutHttpContextWorkflow.cs
├── Helpers/
│ └── NullHttpContextAccessor.cs # Mock HTTP context accessor
├── Elsa.Http.IntegrationTests.csproj
├── README.md
└── Usings.cs
```
## Running the Tests
```bash
dotnet test Elsa.Http.IntegrationTests.csproj
```
Or run specific tests:
```bash
dotnet test --filter "FullyQualifiedName~HttpContextLossTests"
```
## Test Results
```
Passed! - Failed: 0, Passed: 2, Skipped: 0, Total: 2
```
## Implementation Notes
- Tests use `WorkflowTestFixture` from `Elsa.Testing.Shared` for consistent test setup
- Workflow classes are separated into individual files in the `Workflows` subfolder for better organization
- `NullHttpContextAccessor` is a test helper that simulates HTTP context loss by always returning null
- Tests automatically build the fixture and populate registries before execution