Exemplo n.º 1
0
        public void Tick_TickCountOfZero_TicksIndefinitely()
        {
            TimerTrigger trigger = this.CreateTimerTrigger(1, 0);
            CountAction  action  = this.MeasureTotalTicks(trigger, 400);

            Assert.AreNotEqual(action.Count, 0, "Timer trigger should fire continuously when TotalTicks <= 0.");
        }
Exemplo n.º 2
0
        public void Tick_TickCountOfFive_TicksFiveTimes()
        {
            TimerTrigger trigger = this.CreateTimerTrigger(1, 5);
            CountAction  action  = this.MeasureTotalTicks(trigger, 400);

            Assert.AreEqual(action.Count, 5, "Timer trigger should fire exactly TotalTicks times when TotalTicks > 0.");
        }
Exemplo n.º 3
0
        public void StoreShouldUseMiddlewareModifiedAction()
        {
            // This is an evil middleware that basically replace all actions
            // to CountAction instead.
            MiddlewareDelegate <int> replaceAllActionToCountMiddleware = _ => {
                return(dispatcher => action => {
                    var newAction = new CountAction();
                    dispatcher.Invoke(newAction);
                    return newAction;
                });
            };

            var store = new SimpleStore(0, replaceAllActionToCountMiddleware);

            Assert.AreEqual(0, store.GetState());

            store.Dispatch(new CountAction());
            Assert.AreEqual(1, store.GetState());

            store.Dispatch(new AddAction()
            {
                amount = 5
            });
            Assert.AreEqual(2, store.GetState());

            // Even on actions that normally not recognized
            store.Dispatch(new UnrecognizedAction());
            Assert.AreEqual(3, store.GetState());
        }
Exemplo n.º 4
0
        public static State Reduce(State state, CountAction action)
        {
            switch (action)
            {
            case CountAction.Increment:
                state.Count++;
                break;

            case CountAction.Decrement:
                state.Count--;
                break;
            }

            return(state);
        }
Exemplo n.º 5
0
        private CountAction MeasureTotalTicks(TimerTrigger trigger, int msToRun)
        {
            CountAction action = new CountAction();

            trigger.Actions.Add(action);
            trigger.StartTimer();

            DateTime currentTime = DateTime.Now;
            DateTime stopTime    = currentTime.AddMilliseconds(msToRun);

            while (DateTime.Now.CompareTo(stopTime) < 0)
            {
                DispatcherHelper.ClearFrames(Dispatcher.CurrentDispatcher);
            }
            return(action);
        }