The PR aims to make the test kit's IGrainRuntime and IGrainContext more accessible.
I tried to do a good job keeping the commits self-contained, should be easier to review commit-by-commit.
Grain Runtime
The TestGrainRuntime has been publicized and set on TestKitSilo as a public Runtime property. This behavior allows easier testing of components outside of the TestKitSilo itself (but still leveraging the TestKit's abstractions but pumping them into another test DI container, such as AutoFixture)
GrainContext
The TestKitSilo now supports a GetOrAddGrainContext method to pre-create the GrainContext prior to grain creation. If the grain is later requested with the same T and ID, the grain context is re-used from the container, otherwise it is recreated to so that we don't accidentally use an empty mock instance.
This is critical for testing lifecycle components that need the GrainContext but don't want to necessarily create the grain itself yet.
Other Changes
The TestServiceProvider has been updated to update a service, instead of adding. I feel strongly about this one as it support last-wins behavior that mirrors real-life DI containers (MS DI, Autofac, etc)
The strongly-typed CreateGrainAsync overloads have been moved to an extensions file to relieve some bloat. The IdSpan core method has been publicized (a nice change that allows for more extensibility)
Added lots of documentation in files that I visited.
Cleaned up the remainder of the warnings in the Tests project -- solution now compiles with no warnings.
Tests have been added for the GetOrAddGrainContext functionality.
Overview
The PR aims to make the test kit's
IGrainRuntime
andIGrainContext
more accessible.I tried to do a good job keeping the commits self-contained, should be easier to review commit-by-commit.
Grain Runtime
The
TestGrainRuntime
has been publicized and set onTestKitSilo
as a publicRuntime
property. This behavior allows easier testing of components outside of theTestKitSilo
itself (but still leveraging the TestKit's abstractions but pumping them into another test DI container, such asAutoFixture
)GrainContext
The
TestKitSilo
now supports aGetOrAddGrainContext
method to pre-create the GrainContext prior to grain creation. If the grain is later requested with the same T and ID, the grain context is re-used from the container, otherwise it is recreated to so that we don't accidentally use an empty mock instance.This is critical for testing lifecycle components that need the
GrainContext
but don't want to necessarily create the grain itself yet.Other Changes
TestServiceProvider
has been updated to update a service, instead of adding. I feel strongly about this one as it support last-wins behavior that mirrors real-life DI containers (MS DI, Autofac, etc)CreateGrainAsync
overloads have been moved to an extensions file to relieve some bloat. TheIdSpan
core method has been publicized (a nice change that allows for more extensibility)GetOrAddGrainContext
functionality.