Skip to content

Add Shesha.Testing NuGet package for reusable integration test infrastructure and fix SheshaNHibernateInterceptor bugs #4519

@ihouvet

Description

@ihouvet

Problem

1. SheshaNHibernateInterceptor bugs force workarounds in every Shesha application

Two bugs in SheshaNHibernateInterceptor currently require every Shesha application to implement custom interceptor workarounds:

  • Null previousState in OnFlushDirty: When NHibernate calls OnFlushDirty during soft-delete detection, the previousState parameter can be null, causing a NullReferenceException. Every application must guard against this independently.
  • Null EntityChangeEventHelper during early bootstrap: During application startup, the EntityChangeEventHelper property (which relies on property injection) hasn't been set yet, leading to null reference errors when the interceptor fires during early bootstrap operations.

2. No reusable test infrastructure package

Every Shesha application currently needs to copy-paste ~500 lines of test infrastructure from the framework's internal Shesha.Tests project because it is not published as a NuGet package. This causes:

  • Drift: Each application independently patches framework test bugs, leading to divergent implementations
  • Duplicated interceptor workarounds: Every test project must independently work around the two NHibernate interceptor bugs described above
  • Inconsistent test patterns: Without a shared base, each application develops its own conventions for integration test setup, database fixtures, and module configuration
  • High onboarding cost: New Shesha applications require significant boilerplate (~500 lines) just to set up basic integration testing

Requirements

Bug Fixes

  1. Fix OnFlushDirty null previousState: Add a null guard for previousState in SheshaNHibernateInterceptor.OnFlushDirty before accessing it for soft-delete detection
  2. Fix null EntityChangeEventHelper during bootstrap: Add a null check for EntityChangeEventHelper before invoking it, so the interceptor gracefully handles the case where property injection hasn't completed yet

New Shesha.Testing NuGet Package

Create a new Shesha.Testing NuGet package that extracts and publishes the reusable test infrastructure currently locked in the unpublished Shesha.Tests project. The package should include:

  1. ShaIntegratedTestBase<T> - Base class for integrated tests with ABP dependency injection and module lifecycle support
  2. SheshaNhTestBase<T> - Base class for NHibernate-backed integration tests with session management
  3. Database fixtures for multiple providers:
    • SQL Server fixture (Testcontainers-based)
    • PostgreSQL fixture (Testcontainers-based)
    • Local SQL Server fixture (for local development)
  4. ConfigureForTesting() helper - An extension method or helper that encapsulates the ~40 lines of common module boilerplate needed to configure a Shesha module for testing (e.g., disabling background jobs, configuring test-specific settings, setting up in-memory caches)

Validation

  • Update Shesha.Tests to consume Shesha.Testing instead of its own internal infrastructure, validating that the package works correctly
  • The migration should significantly reduce the test module code (e.g., from ~142 lines to ~65 lines)
  • All existing tests must continue to pass after the migration

Acceptance Criteria

  • SheshaNHibernateInterceptor.OnFlushDirty handles null previousState without throwing
  • SheshaNHibernateInterceptor handles null EntityChangeEventHelper during early bootstrap
  • Shesha.Testing NuGet package is created with ShaIntegratedTestBase<T>, SheshaNhTestBase<T>, database fixtures, and ConfigureForTesting() helper
  • Shesha.Tests is updated to consume Shesha.Testing and all existing tests pass
  • Duplicated infrastructure code is removed from Shesha.Tests

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or request

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions