public async Task WhenCalled_ThenTriggersOnlyEffectsThatHandleTheDispatchedAction() { var mockIncompatibleEffect = new Mock <IEffect>(); mockIncompatibleEffect .Setup(x => x.ShouldReactToAction(It.IsAny <object>())) .Returns(false); var mockCompatibleEffect = new Mock <IEffect>(); mockCompatibleEffect .Setup(x => x.ShouldReactToAction(It.IsAny <object>())) .Returns(true); var subject = new TestStore(); await subject.InitializeAsync(); subject.AddEffect(mockIncompatibleEffect.Object); subject.AddEffect(mockCompatibleEffect.Object); var action = new TestAction(); subject.Dispatch(action); mockIncompatibleEffect.Verify(x => x.HandleAsync(action, It.IsAny <IDispatcher>()), Times.Never); mockCompatibleEffect.Verify(x => x.HandleAsync(action, It.IsAny <IDispatcher>()), Times.Once); }
public async Task WhenSynchronousEffectThrowsException_ThenStillExecutesSubsequentEffects() { var subject = new TestStore(); var action = new object(); var mockSynchronousEffectThatThrows = new Mock <IEffect>(); mockSynchronousEffectThatThrows .Setup(x => x.ShouldReactToAction(action)) .Returns(true); mockSynchronousEffectThatThrows .Setup(x => x.HandleAsync(action, subject)) .ThrowsAsync(new NotImplementedException()); var mockEffectThatFollows = new Mock <IEffect>(); mockEffectThatFollows .Setup(x => x.ShouldReactToAction(action)) .Returns(true); await subject.InitializeAsync(); subject.AddEffect(mockSynchronousEffectThatThrows.Object); subject.AddEffect(mockEffectThatFollows.Object); subject.Dispatch(action); mockSynchronousEffectThatThrows.Verify(x => x.HandleAsync(action, subject)); mockEffectThatFollows.Verify(x => x.HandleAsync(action, subject)); }
public UnhandledExceptionTests() { Subject = new TestStore(); Subject.AddEffect(new EffectThatThrowsSimpleException()); Subject.AddEffect(new EffectThatThrowsAggregateException()); Subject.InitializeAsync().Wait(); }
public async Task WhenFinished_ThenDispatchesTasksFromRegisteredEffects() { var mockFeature = MockFeatureFactory.Create(); var actionToEmit1 = new TestActionFromEffect1(); var actionToEmit2 = new TestActionFromEffect2(); var actionsToEmit = new object[] { actionToEmit1, actionToEmit2 }; var subject = new TestStore(); await subject.InitializeAsync(); subject.AddFeature(mockFeature.Object); subject.AddEffect(new EffectThatEmitsActions <TestAction>(actionsToEmit)); subject.Dispatch(new TestAction()); mockFeature .Verify(x => x.ReceiveDispatchNotificationFromStore(actionToEmit1), Times.Once); mockFeature .Verify(x => x.ReceiveDispatchNotificationFromStore(actionToEmit2), Times.Once); }