Exemplo n.º 1
0
        public void should_invoke_both_sync_and_async_handlers()
        {
            _messageDispatcher.LoadMessageHandlerInvokers();

            var asyncHandler = new AsyncCommandHandler {
                WaitForSignal = true
            };

            _containerMock.Setup(x => x.GetInstance(typeof(AsyncCommandHandler))).Returns(asyncHandler);

            var syncHandler = new SyncCommandHandler();

            _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(syncHandler);

            var command = new DispatchCommand();

            DispatchFromDefaultDispatchQueue(command);

            syncHandler.Called.ShouldBeTrue();
            asyncHandler.CalledSignal.Wait(50.Milliseconds()).ShouldBeFalse();

            command.Signal.Set();

            asyncHandler.CalledSignal.Wait(1000.Milliseconds()).ShouldBeTrue();
        }
Exemplo n.º 2
0
        public SelectCardsViewModel()
        {
            game = App.GetGame() ?? throw new InvalidOperationException("Game must exist at this point");

            Cards = new (game.DataHolder.Cards.Select(x => new SelectableCardViewModel(x)));
            SelectItemsCommand       = new (SelectItems);
            SendSelectedCardsCommand = new (SendSelectedCards, () => selectedItems?.Count == 5);
        }
Exemplo n.º 3
0
        internal Guid RegisterAsync <T>(Func <IMessageEnvelope <T>, Task> action, RoutingFilter filter)
        {
            var type         = typeof(T);
            var key          = Guid.NewGuid();
            var subscription = new AsyncCommandHandler(type, key, action, filter);

            lock (_allSubscriptions)
            {
                _allSubscriptions.Add(subscription);
                _subscriptionRevision++;
            }

            return(key);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="machine">Konkretna implementacja maszyny</param>
        public GameViewModel(IMachine <T> machine, IDictionary <T, ImageSource> symbolsImageSources, IInformationPresenter informationPresenter)
        {
            m_machine              = machine ?? throw new ArgumentNullException(nameof(machine));
            m_symbolsImageSources  = symbolsImageSources ?? throw new ArgumentNullException(nameof(symbolsImageSources));
            m_informationPresenter = informationPresenter ?? throw new ArgumentNullException(nameof(informationPresenter));

            SpinCommand       = new AsyncCommandHandler(Spin);
            DecreasBidCommand = new CommandHandler(() => ChangeBid(-1));
            IncreasBidCommand = new CommandHandler(() => ChangeBid(1));
            AddCreditsCommand = new CommandHandler(() => AddCredits(10));

            Credits = m_machine.Credits;

            SetCurrentPossitionsOnReels();
        }
Exemplo n.º 5
0
        public PlayingGameViewModel()
        {
            Game = App.GetGame() ?? throw new InvalidOperationException("Game must exist at this point");
            if (Game.Player == null || Game.Opponent == null)
            {
                throw new InvalidOperationException("Both players must exist at this point");
            }

            Player   = new (Game.Player);
            Opponent = new (Game.Opponent);

            AttackCmd      = new (() => InvokeCardAction(CardAction.BasicAttack));
            SpellAttackCmd = new (() => InvokeCardAction(CardAction.SpellUse));
            DefendCmd      = new (() => Game.DefendSelfAsync());

            Game.PacketProcessed += OnPacketProcessed;
        }
Exemplo n.º 6
0
        public void should_filter_invoker()
        {
            _messageDispatcher.LoadMessageHandlerInvokers();

            var asyncHandler = new AsyncCommandHandler();

            _containerMock.Setup(x => x.GetInstance(typeof(AsyncCommandHandler))).Returns(asyncHandler);

            var syncHandler = new SyncCommandHandler();

            _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(syncHandler);

            var context    = MessageContext.CreateTest("u.name");
            var command    = new DispatchCommand();
            var dispatched = new ManualResetEvent(false);
            var dispatch   = new MessageDispatch(context, command, (x, r) => dispatched.Set());

            _messageDispatcher.Dispatch(dispatch, x => x == typeof(AsyncCommandHandler));

            dispatched.WaitOne(500.Milliseconds()).ShouldBeTrue();

            syncHandler.Called.ShouldBeFalse();
            asyncHandler.CalledSignal.IsSet.ShouldBeTrue();
        }
Exemplo n.º 7
0
 public MainMenuViewModel()
 {
     game                = App.GetGame() ?? throw new InvalidOperationException("Game must exist at this point");
     StartGameCommand    = new(async() => await game.SendPacketAsync(new(CMSGPackets.StartGame)));
     AchievementsCommand = new(async() => await game.SendPacketAsync(new(CMSGPackets.GetAchievements)));
 }
Exemplo n.º 8
0
        public void should_filter_invoker()
        {
            _messageDispatcher.LoadMessageHandlerInvokers();

            var asyncHandler = new AsyncCommandHandler();
            _containerMock.Setup(x => x.GetInstance(typeof(AsyncCommandHandler))).Returns(asyncHandler);

            var syncHandler = new SyncCommandHandler();
            _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(syncHandler);

            var context = MessageContext.CreateTest("u.name");
            var command = new DispatchCommand();
            var dispatched = new ManualResetEvent(false);
            var dispatch = new MessageDispatch(context, command, (x, r) => dispatched.Set());
            _messageDispatcher.Dispatch(dispatch, x => x == typeof(AsyncCommandHandler));

            dispatched.WaitOne(500.Milliseconds()).ShouldBeTrue();

            syncHandler.Called.ShouldBeFalse();
            asyncHandler.CalledSignal.IsSet.ShouldBeTrue();
        }
Exemplo n.º 9
0
        public void should_invoke_both_sync_and_async_handlers()
        {
            _messageDispatcher.LoadMessageHandlerInvokers();

            var asyncHandler = new AsyncCommandHandler { WaitForSignal = true };
            _containerMock.Setup(x => x.GetInstance(typeof(AsyncCommandHandler))).Returns(asyncHandler);

            var syncHandler = new SyncCommandHandler();
            _containerMock.Setup(x => x.GetInstance(typeof(SyncCommandHandler))).Returns(syncHandler);

            var command = new DispatchCommand();
            Dispatch(command);

            syncHandler.Called.ShouldBeTrue();
            asyncHandler.CalledSignal.Wait(50.Milliseconds()).ShouldBeFalse();

            command.Signal.Set();

            asyncHandler.CalledSignal.Wait(1000.Milliseconds()).ShouldBeTrue();
        }