Esempio n. 1
0
        public void Should_update_tiles_after_processing_rules()
        {
            var gameData = CreateData();

            var gameResultService = new Mock <IGameResultService>();

            var tiles = Enumerable.Range(0, 9)
                        .Select(x => new Tile
            {
                TileId  = x,
                Element = Element.Fire
            });

            var ruleStrategy = new Mock <IRuleStrategy>();

            ruleStrategy
            .Setup(x => x.Apply(
                       It.IsAny <IEnumerable <Tile> >(),
                       It.IsAny <int>()))
            .Returns(tiles);

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(ruleStrategy.Object);

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data = subject.Run(CreateStep(gameData));

            data.Tiles.Should().BeEquivalentTo(tiles);
        }
Esempio n. 2
0
        public void Should_switch_turn(bool isHost)
        {
            var gameData = CreateData(isHost);

            var gameResultService = new Mock <IGameResultService>();

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(CreateRuleStrategy());

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data = subject.Run(CreateStep(gameData, isHost: isHost));

            data.HostTurn.Should().Be(!isHost);
        }
Esempio n. 3
0
        public void Should_have_correct_move_log_entry(bool isHost, int tileId, string message)
        {
            var gameData = CreateData(isHost);

            var gameResultService = new Mock <IGameResultService>();

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(CreateRuleStrategy());

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data = subject.Run(CreateStep(gameData, isHost: isHost, tileId: tileId));

            data.Log.Should().Contain(message);
        }
Esempio n. 4
0
        public void Should_have_player_assigned_to_card(bool isHost)
        {
            var gameData = CreateData(isHost);

            var gameResultService = new Mock <IGameResultService>();

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(CreateRuleStrategy());

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data = subject.Run(CreateStep(gameData, isHost: isHost));
            var tile = data.Tiles.Single(x => x.TileId == 0);

            tile.Card.IsHost.Should().Be(isHost);
        }
Esempio n. 5
0
        public void Should_assign_card_to_tile(int tileId)
        {
            var gameData = CreateData();

            var gameResultService = new Mock <IGameResultService>();

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(CreateRuleStrategy());

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data = subject.Run(CreateStep(gameData, tileId: tileId));
            var tile = data.Tiles.Single(x => x.TileId == tileId);

            tile.Card.Should().BeEquivalentTo(Card, options => options.ExcludingMissingMembers());
        }
Esempio n. 6
0
        public void Should_have_remove_card_from_hand(bool isHost)
        {
            var gameData = CreateData(isHost);

            var gameResultService = new Mock <IGameResultService>();

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(CreateRuleStrategy());

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data          = subject.Run(CreateStep(gameData, isHost: isHost));
            var cards         = isHost ? data.HostCards : data.ChallengerCards;
            var expectedCards = (isHost ? HostCards : ChallengerCards)
                                .Where(x => x.Name != Card.Name);

            cards.Should().BeEquivalentTo(expectedCards);
        }
Esempio n. 7
0
        public void Should_have_correct_result(Result?result)
        {
            var gameData = CreateData();

            var gameResultService = new Mock <IGameResultService>();

            gameResultService
            .Setup(x => x.GetResult(It.IsAny <GameData>()))
            .Returns(result);

            var ruleStrategyFactory = new Mock <IRuleStrategyFactory>();

            ruleStrategyFactory
            .Setup(x => x.Create(It.IsAny <IEnumerable <Rule> >()))
            .Returns(CreateRuleStrategy());

            var subject = new PlayCardHandler(
                gameResultService.Object,
                ruleStrategyFactory.Object);

            var data = subject.Run(CreateStep(gameData));

            data.Result.Should().Be(result);
        }