Exemple #1
0
        public string AddBunny(string bunnyType, string bunnyName)
        {
            IBunny bunny   = null;
            string message = string.Empty;

            switch (bunnyType)
            {
            case "HappyBunny":
                bunny = new HappyBunny(bunnyName);
                bunnyRepository.Add(bunny);
                message = string.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName);
                break;

            case "SleepyBunny":
                bunny = new SleepyBunny(bunnyName);
                bunnyRepository.Add(bunny);
                message = string.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName);
                break;

            default:
                message = ExceptionMessages.InvalidBunnyType;
                break;
            }
            return(message);
        }
Exemple #2
0
        public string AddBunny(string bunnyType, string bunnyName)
        {
            if (bunnyType != nameof(HappyBunny) && bunnyType != nameof(SleepyBunny))
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType);
            }
            IBunny bunny;

            if (bunnyType == nameof(HappyBunny))
            {
                bunny = new HappyBunny(bunnyName);
            }
            else
            {
                bunny = new SleepyBunny(bunnyName);
            }
            bunnies.Add(bunny);
            return(string.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName));
        }
Exemple #3
0
        public string AddBunny(string bunnyType, string bunnyName)
        {
            IBunny bunny = null;

            if (bunnyType == nameof(HappyBunny))
            {
                bunny = new HappyBunny(bunnyName);
            }
            else if (bunnyType == nameof(SleepyBunny))
            {
                bunny = new SleepyBunny(bunnyName);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType);
            }
            bunnies.Add(bunny);
            return($"Successfully added {bunnyType} named {bunnyName}.");
        }
Exemple #4
0
        public string AddBunny(string bunnyType, string bunnyName)
        {
            IBunny currentBunny = null;

            if (bunnyType == "HappyBunny")
            {
                currentBunny = new HappyBunny(bunnyName);
                bunnies.Add(currentBunny);
            }
            else if (bunnyType == "SleepyBunny")
            {
                currentBunny = new SleepyBunny(bunnyName);
                bunnies.Add(currentBunny);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType);
            }
            return($"{String.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName)}");
        }
Exemple #5
0
        public string AddBunny(string bunnyType, string bunnyName)
        {
            IBunny bunny = null;

            if (bunnyType == nameof(HappyBunny))
            {
                bunny = new HappyBunny(bunnyName);
            }
            else if (bunnyType == nameof(SleepyBunny))
            {
                bunny = new SleepyBunny(bunnyName);
            }
            else
            {
                throw new InvalidOperationException(Utilities.Messages.ExceptionMessages.InvalidBunnyType);
            }

            bunnies.Add(bunny);
            return(string.Format(Utilities.Messages.OutputMessages.BunnyAdded, bunnyType, bunnyName));
        }
Exemple #6
0
        public string AddBunny(string bunnyType, string bunnyName)   //ok?
        {
            // Valid types are: "HappyBunny" and "SleepyBunny".

            if (bunnyType != "HappyBunny" && bunnyType != "SleepyBunny")
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.InvalidBunnyType));
            }
            IBunny bunny = null;

            if (bunnyType == "HappyBunny")
            {
                bunny = new HappyBunny(bunnyName);
            }
            else if (bunnyType == "SleepyBunny")
            {
                bunny = new SleepyBunny(bunnyName);
            }
            bunnies.Add(bunny);
            return($"Successfully added {bunnyType} named {bunnyName}.");
        }
Exemple #7
0
        public string AddBunny(string bunnyType, string bunnyName)
        {
            IBunny bunny = null;

            switch (bunnyType)
            {
            case "HappyBunny":
                bunny = new HappyBunny(bunnyName);
                break;

            case "SleepyBunny":
                bunny = new SleepyBunny(bunnyName);
                break;

            default:
                throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType);
            }

            bunnyRepository.Add(bunny);

            return(string.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName));
        }
        public string AddBunny(string bunnyType, string bunnyName)
        {
            IBunny bunny;

            if (bunnyType == nameof(HappyBunny))
            {
                bunny = new HappyBunny(bunnyName);
            }
            else if (bunnyType == nameof(SleepyBunny))
            {
                bunny = new SleepyBunny(bunnyName);
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.InvalidBunnyType);
            }

            this.bunnies.Add(bunny);

            var result = String.Format(OutputMessages.BunnyAdded, bunnyType, bunnyName);

            return(result);
        }