Skip to content

Allow [SharedDb] and [PooledDb] on classes and assemblies, add [NewDb] - #1065

Merged
SimonCropp merged 1 commit into
mainfrom
db-attribute-levels
Sep 15, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
db-attribute-levels

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

[SharedDb] and [PooledDb] could only be applied to test methods. They can now also be applied to a test class or the assembly ([assembly: PooledDb]).

  • The nearest attribute wins: method over class over assembly.
  • New [NewDb] attribute (method or class) opts out of a class or assembly attribute and uses a new database per test. That is still the default when no attribute applies.
  • More than one of [PooledDb], [SharedDb] and [NewDb] on the same method, class, or assembly throws. Every level is checked, even when a nearer level decides. The message is now "[PooledDb], [SharedDb] and [NewDb] are mutually exclusive. Use only one on a test method." (or "a test class" / "an assembly").
  • Attribute resolution moves from the four framework test bases (MSTest, NUnit, TUnit, xunit.v3) into DbAttributeReader in EfLocalDb.

Tests:

  • DbAttributeReaderTests covers each level, the overrides, class attribute inheritance and the conflicts. The assembly cases use an in-memory assembly.
  • Each framework has ClassLevelPooledDbTests (class-level [PooledDb], with method-level [SharedDb] and [NewDb] overrides) and PooledAndSharedDbTests (the throw when both are on a method).

The pooled-db and shared-db docs includes describe class and assembly use and [NewDb], and the four usage pages are regenerated.

[SharedDb] and [PooledDb] could only be applied to test methods. They
can now also be applied to a test class or the assembly. The nearest
attribute wins: method over class over assembly.

[NewDb] opts a method or class out of a class or assembly attribute and
uses a new database per test, which is still the default when no
attribute applies.

Attribute resolution moves from the four framework test bases into
DbAttributeReader in EfLocalDb. More than one of the three attributes
on the same method, class, or assembly throws, and every level is
checked even when a nearer level decides.

DbAttributeReaderTests covers each level, the overrides, inheritance
and the conflicts. Each framework gets tests for class-level [PooledDb]
with method-level [SharedDb] and [NewDb] overrides, and for the throw
when both [PooledDb] and [SharedDb] are on a method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant