public void GetValue_CallingGetValueWithinValueInitializer_DoesNotCallValueInitializerAgain() { PropertyStub <object> property = null; Func <IBehaviorContext, object> provideValueFunction = ctx => { return(new Object()); }; var behavior = new TestBehavior(provideValueFunction); var valueInitializerWasAlreadyInvoked = false; Action <IBehaviorContext> initializeValueAction = ctx => { Assert.IsFalse(valueInitializerWasAlreadyInvoked); valueInitializerWasAlreadyInvoked = true; property.Behaviors.GetValueNext <object>(ctx); }; property = PropertyStub .WithBehaviors(behavior, new TestValueInitializerBehavior(initializeValueAction)) .Build(); var context = ViewModelStub .WithProperties(property) .BuildContext(); behavior.GetValue(context); Assert.IsTrue(valueInitializerWasAlreadyInvoked); }
public void GetValue_CallingGetValueWithinProvideValue_ThrowsException() { PropertyStub <object> property = null; var provideValueWasAlreadyCalled = false; Func <IBehaviorContext, object> provideValueFunction = ctx => { Assert.IsFalse(provideValueWasAlreadyCalled); provideValueWasAlreadyCalled = true; property.Behaviors.GetValueNext <object>(ctx); return(new Object()); }; var behavior = new TestBehavior(provideValueFunction); property = PropertyStub .WithBehaviors(behavior) .Build(); var context = ViewModelStub .WithProperties(property) .BuildContext(); AssertHelper.Throws <InvalidOperationException>(() => behavior.GetValue(context) ).WithMessage(EViewModels.ValueAccessedWithinProvideValue); Assert.IsTrue(provideValueWasAlreadyCalled); }