public void UnregisteringTwiceDoesNotThrow() { var observer = new MockObserver(); var store = new MockStore(new MockState(k_MockStateDefault)); store.Register <ChangeFooAction>(MockReducers.ReplaceFoo); store.Register(observer.Observe); store.Unregister(observer.Observe); store.Unregister(observer.Observe); store.Unregister <ChangeFooAction>(); store.Unregister <ChangeFooAction>(); }
public void RegisteredObserverShouldBeCalledForEachActionDispatched() { var observer = new MockObserver(); var store = new MockStore(new MockState(k_MockStateDefault)); store.Register(observer.Observe); store.Register <PassThroughAction>(MockReducers.PassThrough); store.Register <ChangeFooAction>(MockReducers.ReplaceFoo); store.Register <ChangeBarAction>(MockReducers.ReplaceBar); store.Dispatch(new ChangeFooAction(20)); Assert.That(observer.ActionObserved, Is.EqualTo(1)); store.Dispatch(new ChangeBarAction(10)); Assert.That(observer.ActionObserved, Is.EqualTo(2)); store.Dispatch(new PassThroughAction()); Assert.That(observer.ActionObserved, Is.EqualTo(3)); // Unregistered observer should not be notified anymore store.Unregister(observer.Observe); store.Dispatch(new PassThroughAction()); Assert.That(observer.ActionObserved, Is.EqualTo(3)); }
public void RegisteringDoesNotChangeState() { var observer = new MockObserver(); var store = new MockStore(new MockState(k_MockStateDefault)); store.Register(observer.Observe); store.Register <PassThroughAction>(MockReducers.PassThrough); store.Register <ChangeFooAction>(MockReducers.ReplaceFoo); store.Register <ChangeBarAction>(MockReducers.ReplaceBar); Assert.That(store.GetState().Foo, Is.EqualTo(k_MockStateDefault)); store.Unregister(observer.Observe); }
public void MultipleObserverAreSupported() { var observer1 = new MockObserver(); var observer2 = new MockObserver(); var store = new MockStore(new MockState(k_MockStateDefault)); store.Register(observer1.Observe); store.Register(observer2.Observe); store.Register <PassThroughAction>(MockReducers.PassThrough); store.Register <ChangeFooAction>(MockReducers.ReplaceFoo); store.Register <ChangeBarAction>(MockReducers.ReplaceBar); store.Dispatch(new ChangeFooAction(10)); Assert.That(observer1.ActionObserved, Is.EqualTo(1)); Assert.That(observer2.ActionObserved, Is.EqualTo(1)); store.Dispatch(new PassThroughAction()); Assert.That(observer1.ActionObserved, Is.EqualTo(2)); Assert.That(observer2.ActionObserved, Is.EqualTo(2)); store.Unregister(observer1.Observe); store.Unregister(observer2.Observe); }