OrleansContrib / OrleansTestKit

Unit Test Toolkit for Microsoft Orleans
http://dotnet.github.io/orleans
MIT License
78 stars 43 forks source link

GrainRuntime + GrainContext Enhancements #139

Closed cmeyertons closed 1 year ago

cmeyertons commented 1 year ago

Overview

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