public void When_KingCrowned_Expect_True()
        {
            // Arrange
            // Setting all kingdoms except water to compete
            var testGameEngine = new GameEngine(consoleMethods);

            testGameEngine.AllKingdoms[Kingdoms.Air].IsCompeting   = true;
            testGameEngine.AllKingdoms[Kingdoms.Fire].IsCompeting  = true;
            testGameEngine.AllKingdoms[Kingdoms.Ice].IsCompeting   = true;
            testGameEngine.AllKingdoms[Kingdoms.Land].IsCompeting  = true;
            testGameEngine.AllKingdoms[Kingdoms.Space].IsCompeting = true;
            // Updating message list to only contain valid message for water
            // So that we are sure to have a winner in the very first round
            Utility.listOfMessages.Clear();
            Utility.listOfMessages.Add("octopus");
            var highPriest = new HighPriest(6, 100, consoleMethods);

            // Act
            highPriest.HoldBallot(testGameEngine);

            // Explicitly call Utility class' static constructor so as to revert changes to listOfMessages
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Utility).TypeHandle);

            // Assert
            Assert.NotNull(testGameEngine.RulingKingdom);
        }
        /// <summary>
        /// Custom Input Action for the 'Breaker of Chains' problem
        /// </summary>
        /// <param name="input">The user input which triggered the custom action</param>
        /// <param name="southeros"></param>
        /// <returns></returns>
        /// <remarks>We don't particularly require the input data in this function but we keep it anyway to match the function signature</remarks>
        public string CustomInputAction(string input, ISoutheros southeros)
        {
            // Once a ruler has been found, we no longer need to hold a ballot
            if (southeros.RulingKingdom != null)
            {
                return(string.Format(Utility.RulerCrownedMessage, southeros.RulingKingdom.Name));
            }

            // Declare local variables
            var output           = string.Empty;
            var noOfCompetitors  = 0;
            var maxBallotRounds  = 1000;
            var messagesToChoose = 6;

            // Read the list of competitors from the user
            var possibleCandidates = console.ReadLine().Trim().Replace(',', ' ').Split(" ", StringSplitOptions.RemoveEmptyEntries);

            // Try parsing the user input into valid kingdoms
            foreach (var candidate in possibleCandidates)
            {
                if (!string.IsNullOrWhiteSpace(candidate) &&
                    Enum.TryParse(candidate, true, out Kingdoms competingKingdom))
                {
                    southeros.AllKingdoms[competingKingdom].IsCompeting = true;
                    noOfCompetitors++;
                }
                else
                {
                    output += string.Format(Utility.InvalidKingdomMessage, candidate);
                }
            }

            // We need atleast two kingdoms competing for the crown
            if (noOfCompetitors < 2)
            {
                output += Utility.NoCompetingKingdomsMessage;
            }
            // and atmost one less than all of them
            else if (noOfCompetitors < Enum.GetValues(typeof(Kingdoms)).Length)
            {
                // Summon high priest
                var highPriest = new HighPriest(messagesToChoose, maxBallotRounds, console);
                // FindRulerByBallot return false if we don't have a ruler after maxBallotRounds

                if (!highPriest.HoldBallot(southeros))
                {
                    output += Utility.BallotTookTooLongMessage;
                }
            }
            // If all the kingdoms compete, we can't proceed
            else
            {
                output += Utility.TooManyKingdomsMessage;
            }

            return(output);
        }
        public void Test_SendMesgFromKingdomsToBallotBoxNOCompitetors()
        {
            string     output   = "Not able to conduct election because of no compitetors";
            Universe   Sotheros = new Universe();
            HighPriest priest   = Universe.Priest;

            priest.Compitetors = new List <string>();
            string result = priest.ConductElection();

            Assert.AreEqual(output, result);
        }
        public void Test_AddSixMessages()
        {
            //Test to add the messages less than 6
            string         output             = "Ballot box count should be atleast 6";
            Universe       Sotheros           = new Universe();
            HighPriest     priest             = Universe.Priest;
            List <Kingdom> CompitetorsKingdom = new List <Kingdom>();

            AddMessagetoBallotBox(priest);
            string op = priest.AddSixMessages();

            Assert.AreEqual(op, output);
        }
        public void Test_AddSixMessagesGreaterthen5()
        {
            //Test to add the messages less than 6
            string         output             = "Sucess";
            Universe       Sotheros           = new Universe();
            HighPriest     priest             = Universe.Priest;
            List <Kingdom> CompitetorsKingdom = new List <Kingdom>();

            for (int i = 0; i < 7; i++)
            {
                priest.AddMessagetoBallotbox(Get5messages());
            }

            string op = priest.AddSixMessages();

            Assert.AreEqual(op, output);
        }
        public void Test_SendMesgFromKingdomsToBallotBoxCompitetors()
        {
            string     output   = "Sucess";
            Universe   Sotheros = new Universe();
            HighPriest priest   = Universe.Priest;

            priest.Compitetors = new List <string>();
            List <string> kingdoms = new List <string>()
            {
                "AIR", "LAND", "WATER", "SPACE", "FIRE", "ICE"
            };
            Random kingEmblem = new Random();

            for (int i = 0; i < 2; i++)
            {
                int ind = kingEmblem.Next(6);
                priest.Compitetors.Add(kingdoms[ind]);
                kingdoms.RemoveAt(ind);
            }
            string result = priest.ConductElection();

            Assert.AreEqual(output, result);
        }
 private void AddMessagetoBallotBox(HighPriest priest)
 {
     priest.AddMessagetoBallotbox(GetDummyMessages());
 }