public void CreatesDefaultState() { // arrange var factory = new WeakActivationStateFactory(); var governor = new FakeResourceGovernor(); var lifecycle = new FakeGrainLifecycle(); var context = new FakeGrainActivationContext() { GrainType = typeof(object), ActivationServices = new ServiceCollection() .AddSingleton(typeof(IKeyedServiceCollection <,>), typeof(KeyedServiceCollection <,>)) .AddSingletonNamedService <IResourceGovernor>(OutkeepProviderNames.OutkeepDefault, (sp, name) => governor) .BuildServiceProvider(), ObservableLifecycle = lifecycle }; var config = new FakeWeakActivationStateConfiguration(); // act var state = factory.Create <FakeWeakActivationFactor>(context, config); // assert Assert.NotNull(state); var(observerName, stage, observer) = Assert.Single(lifecycle.Subscriptions); Assert.Equal(typeof(WeakActivationState <FakeWeakActivationFactor>).FullName, observerName); Assert.Equal(GrainLifecycleStage.SetupState, stage); Assert.Same(state, observer); }
public void ThrowsOnNullContext() { // arrange var factory = new WeakActivationStateFactory(); // act void action() => factory.Create <FakeWeakActivationFactor>(null !, null !); // assert Assert.Throws <ArgumentNullException>("context", action); }
public void ThrowsOnNonRegisteredDefaultResourceGovernor() { // arrange var factory = new WeakActivationStateFactory(); var context = new FakeGrainActivationContext() { GrainType = typeof(object), ActivationServices = new ServiceCollection() .BuildServiceProvider() }; var config = new FakeWeakActivationStateConfiguration(); // act void action() => factory.Create <FakeWeakActivationFactor>(context, config); // assert var result = Assert.Throws <BadWeakActivationConfigException>(action); Assert.Equal(Resources.Exception_NoResourceGovernorNamed_X_FoundForGrainType_X.Format(OutkeepProviderNames.OutkeepDefault, typeof(object).FullName !), result.Message); }