Пример #1
0
        public static Player RegisterNewPlayer(string name, IPlayerMapper playerMapper = null)

        {
            // If a PlayerMapper was not passed in, use a real one.

            // This allows us to pass in a "mock" PlayerMapper (for testing),

            // but use a real PlayerMapper, when running the program.

            if (playerMapper == null)

            {
                playerMapper = new PlayerMapper();
            }

            if (string.IsNullOrWhiteSpace(name))

            {
                throw new ArgumentException("Player name can’t be empty.");
            }

            // Throw an exception if there is already a player with this name in the database.

            if (playerMapper.IsPlayerNameExistsInDb(name))

            {
                throw new ArgumentException("Player name already exists.");
            }

            // Add the player to the database.

            playerMapper.AddNewPlayerIntoDb(name);

            return(new Player(name, 23, "India", 30));
        }
Пример #2
0
        public static Player RegisterNewPlayer(string name, IPlayerMapper playermapper = null)
        {
            if (playermapper == null)
            {
                playermapper = new PlayerMapper();
            }
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Player name can't be empty.");
            }

            if (playermapper.IsPlayerNameExistsInDb(name))
            {
                throw new ArgumentException("Player name alredy exists.");
            }

            playermapper.AddNewPlayerIntoDb(name);
            return(new Player(name, 23, "India", 30));
        }