示例#1
0
        public void DiscoverGameAlreadyFinishedBeforeGettingActionStatus()
        {
            _messageProvider.Setup(x => x.Receive <ActionValidPayload>()).Throws(new GameAlreadyFinishedException());

            var actionExecutor = new ActionExecutor(_messageProvider.Object, _playerState);

            Assert.Throws <GameAlreadyFinishedException>(() => actionExecutor.Discover());
        }
示例#2
0
        public void DiscoverActionInvalid()
        {
            _messageProvider.Setup(x => x.Receive <ActionValidPayload>()).Throws(new ActionInvalidException());

            var actionExecutor = new ActionExecutor(_messageProvider.Object, _playerState);
            var result         = actionExecutor.Discover();

            Assert.That(result, Is.False);
        }
示例#3
0
        public void DiscoverWrongPayload()
        {
            _messageProvider.Setup(x => x.Receive <ActionValidPayload>()).Returns(new Message <ActionValidPayload>());
            _messageProvider.Setup(x => x.Receive <DiscoveryResponsePayload>()).Throws(new WrongPayloadException());

            var actionExecutor = new ActionExecutor(_messageProvider.Object, _playerState);

            Assert.Throws <WrongPayloadException>(() => actionExecutor.Discover());
        }
示例#4
0
        public void DiscoverNoPayload()
        {
            var msg = new Message <DiscoveryResponsePayload>
            {
                Type        = Common.Consts.DiscoveryResponse,
                SenderId    = Common.Consts.GameMasterId,
                RecipientId = _assignedPlayerId,
                Payload     = null
            };

            _messageProvider.Setup(x => x.Receive <ActionValidPayload>()).Returns(new Message <ActionValidPayload>());
            _messageProvider.Setup(x => x.Receive <DiscoveryResponsePayload>()).Returns(msg);

            var actionExecutor = new ActionExecutor(_messageProvider.Object, _playerState);

            Assert.Throws <NoPayloadException>(() => actionExecutor.Discover());
        }
示例#5
0
        public void DiscoverSuccess()
        {
            var assignedX = 0;
            var assignedY = 0;
            var tile1     = new TileDiscoveryDTO
            {
                X = 0,
                Y = 0,
                DistanceToClosestPiece = 11,
                Piece = false,
            };

            var tile2 = new TileDiscoveryDTO
            {
                X = 1,
                Y = 0,
                DistanceToClosestPiece = 10,
                Piece = false,
            };

            var tile3 = new TileDiscoveryDTO
            {
                X = 2,
                Y = 0,
                DistanceToClosestPiece = 0,
                Piece = true,
            };

            var tiles = new List <TileDiscoveryDTO>
            {
                tile1, tile2, tile3
            };

            var msg = new Message <DiscoveryResponsePayload>
            {
                Type        = Common.Consts.DiscoveryResponse,
                SenderId    = Common.Consts.GameMasterId,
                RecipientId = _assignedPlayerId,
                Payload     = new DiscoveryResponsePayload
                {
                    Timestamp = 69,
                    Tiles     = tiles
                }
            };

            _messageProvider.Setup(x => x.Receive <ActionValidPayload>()).Returns(new Message <ActionValidPayload>());
            _messageProvider.Setup(x => x.Receive <DiscoveryResponsePayload>()).Returns(msg);
            _playerState.X = assignedX;
            _playerState.Y = assignedY;

            var actionExecutor = new ActionExecutor(_messageProvider.Object, _playerState);
            var result         = actionExecutor.Discover();

            Assert.That(result, Is.True);
            foreach (var t in tiles)
            {
                Assert.That(_playerState.Board.At(t.X, t.Y).DistanceToClosestPiece, Is.EqualTo(t.DistanceToClosestPiece));
                Assert.That(_playerState.Board.At(t.X, t.Y).Timestamp, Is.EqualTo(msg.Payload.Timestamp));
                if (t.Piece)
                {
                    Assert.That(_playerState.Board.At(t.X, t.Y), Is.Not.Null);
                    Assert.That(_playerState.Board.At(t.X, t.Y).Piece.WasTested, Is.False);
                }
                else
                {
                    Assert.That(_playerState.Board.At(t.X, t.Y).Piece, Is.Null);
                }
            }
        }