示例#1
0
    def start_game(command: StartGame):
        """ Creates Game and will try to apply GameStarted """
        game = Game()
        game.apply(
            GameStarted(aggregate_root_id=command.get_aggregate_root_id(),
                        tries=command.get_tries(),
                        word=command.get_word()))

        return game
示例#2
0
    def test_it_cant_guess_words_when_game_over(self):
        aggregate_id = '297F2CE9-CB4F-4BE2-8C86-21B911FC2663'
        aggregate = Game.start_game(StartGame(aggregate_id, 'birthday', 1))
        aggregate.guess_word(GuessWord(aggregate_id, 'dog'))

        self.withAggregate(aggregate).expects_exception(
            DomainException, "You are game over!", "guess_word",
            GuessWord(aggregate_id, 'cat'))
示例#3
0
    def test_it_cant_guess_letters_when_no_tries_are_left(self):
        aggregate_id = '297F2CE9-CB4F-4BE2-8C86-21B911FC2663'
        aggregate = Game.start_game(StartGame(aggregate_id, 'birthday', 1))
        aggregate.guess_letter(GuessLetter(aggregate_id, 'x'))

        self.withAggregate(aggregate).expects_exception(
            DomainException, "Game doesn't have any tries left.",
            "guess_letter", GuessLetter(aggregate_id, 'x'))
示例#4
0
    def test_it_can_start_a_game(self):
        game_start_command = StartGame('297F2CE9-CB4F-4BE2-8C86-21B911FC2663',
                                       'birthday', 9)

        aggregate = Game.start_game(game_start_command)
        self.withAggregate(aggregate)\
            .assert_aggregate_property_state_equal_to('__tries', 9)
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__word', 'birthday')
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__active_game', True)
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__letters_guessed', [])
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__letters_not_guessed', [])
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__word_guessed', "")
示例#5
0
    def test_it_can_guess_word(self):
        aggregate_id = '297F2CE9-CB4F-4BE2-8C86-21B911FC2663'

        aggregate = Game.start_game(StartGame(aggregate_id, 'birthday', 9))
        aggregate.guess_word(GuessWord(aggregate_id, 'birthday'))

        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__tries', 9)
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__word', 'birthday')
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__active_game', False)
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__letters_guessed', [])
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__letters_not_guessed', [])
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__word_guessed', "birthday")
示例#6
0
    def test_it_can_win_by_guessing_all_letters(self):
        aggregate_id = '297F2CE9-CB4F-4BE2-8C86-21B911FC2663'
        aggregate = Game.start_game(StartGame(aggregate_id, 'bird', 9))

        aggregate.guess_letter(GuessLetter(aggregate_id, 'x'))
        aggregate.guess_letter(GuessLetter(aggregate_id, 'r'))
        aggregate.guess_letter(GuessLetter(aggregate_id, 'd'))
        aggregate.guess_letter(GuessLetter(aggregate_id, 'b'))
        aggregate.guess_letter(GuessLetter(aggregate_id, 'i'))

        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__tries', 8)
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__word', 'bird')
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__active_game', False)
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__letters_guessed', ['r','d','b','i'])
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__letters_not_guessed', ['x'])
        self.withAggregate(aggregate) \
            .assert_aggregate_property_state_equal_to('__word_guessed', "")