Improve extensibility#47
Open
vfofanov wants to merge 6 commits intoserilog-contrib:mainfrom
Open
Conversation
added 6 commits
November 11, 2025 13:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve extensibility
Summary
This PR refactors the assertions layer so that adding or supporting new assertion frameworks (e.g. FluentAssertions, Shouldly, AwesomeAssertions) is easier and consistent. It also improves the core in-memory sink (naming, nullable, tests) and fills test gaps across the solution.
Changes
Assertion extensibility
Abstractions
Serilog.Sinks.InMemory.Assertions.Abstractionswith:InMemorySinkAssertionsFactory– creates framework-specific assertions from anInMemorySink(snapshot).IInMemorySinkAssertionsExtension– contract for framework-specific assertion behavior (e.g.Assert(condition, FailMessage, because, becauseArgs)).AssertionFrameworkandAssertionFrameworks– identify the active framework and version.FailMessage– structured failure message (message + args) used by extensions.InMemorySinkAssertions,LogEventsAssertions,LogEventAssertion, etc.) remain in the main Assertions assembly and are implemented by each framework-specific package.Factory-based resolution
InMemorySinkAssertionUtilsnow discovers and instantiates the correctInMemorySinkAssertionsFactoryby:Serilog.Sinks.InMemory.FluentAssertions8) and creating its factory implementation.Should()extension calls the factory to create assertions from a snapshot of the sink, so each framework only implements the factory and assertion types.Framework adapters
InMemorySinkAssertionsFactoryImpland use sharedBaseAssertions/AssertionExtensionswhere applicable.IInMemorySinkAssertionsExtensionandFailMessage, reducing duplicated failure-construction logic and making it straightforward to add new frameworks or versions.Test layout and coverage
Shared assertion tests
test/Serilog.Sinks.InMemory.Assertions.Tests.Unit/and are linked into each framework-specific test project (FluentAssertions5–8, Shouldly4, AwesomeAssertions8/9) so the same scenarios run for every framework.TestInMemorySinkAssertionExtensions.AssertionsFactory(backed by the same detection as production), so a single test file runs against the currently compiled framework.New and updated tests
Serilog.Sinks.InMemory.Tests.Unit)GivenNullSinkConfiguration_InMemoryThrowsArgumentNullException– null guard forsinkConfiguration.GivenNullOutputTemplate_InMemoryThrowsArgumentNullException– null guard foroutputTemplate.GivenSnapshotIsTaken_SnapshotDoesNotIncludeEventsLoggedAfterSnapshot– snapshot isolation.GivenDisposeIsCalledTwice_DoesNotThrow– doubleDisposeis safe.GivenNoMessages_NotHaveMessageSucceedsandGivenNoMessages_NotHaveMessageWithTemplateSucceeds–NotHaveMessage()/NotHaveMessage(template)when no events are logged.WhenAssertingWithPredicate–HaveMessage(predicate)andNotHaveMessage(predicate)(success and failure cases).Benefits
InMemorySinkAssertionsFactoryand the assertion interfaces, plus a test project that links the shared tests.