Пример #1
0
        public void TennisGame_Ctor_Should_Throw_InvalidOperationException_If_Two_Players_Are_The_Same()
        {
            var player1 = new TennisPlayer("foo");
            var player2 = new TennisPlayer("foo");

            Assert.Throws <InvalidOperationException>(() => new TennisGame(player1, player2));
        }
Пример #2
0
        public TennisGame(TennisPlayer fistPlayer, TennisPlayer secondPlayer)
        {
            if (fistPlayer == default(TennisPlayer))
            {
                throw new ArgumentNullException("fistPlayer");
            }

            if (secondPlayer == default(TennisPlayer))
            {
                throw new ArgumentNullException("secondPlayer");
            }

            if (fistPlayer == secondPlayer)
            {
                throw new InvalidOperationException("A tennis game needs to be played by two different players.");
            }

            _fistPlayer   = fistPlayer;
            _secondPlayer = secondPlayer;
        }