Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            string answer = string.Empty;

            Inquirer.Prompt(Question.Input("1")).Bind(() => answer);
            Inquirer.Prompt(Question.Input("2")).Bind(() => answer).After(() =>
            {
                int x = 1;
            });
            Inquirer.Prompt(() =>
            {
                if (answer.Length > 5)
                {
                    return(Question.Input("3"));
                }

                return(null);
            }).Then(answer2 =>
            {
                Inquirer.Prompt(Question.Input("3.1")).Bind(() => answer);
                Inquirer.Prompt(Question.Input("3.2")).Bind(() => answer).After(() =>
                {
                    answer = "Do this after";
                });
                Inquirer.Prompt(Question.Input("3.3")).Bind(() => answer);
            });
            Inquirer.Go();
        }
Ejemplo n.º 2
0
        public void ShouldInitializeWithQuestions()
        {
            var input1   = Substitute.For <IPrompt>();
            var input2   = Substitute.For <IPrompt>();
            var Inquirer = new Inquirer(input1, input2);

            Inquirer.Questions.Should().HaveCount(2);
        }
Ejemplo n.º 3
0
        public void ShouldReturnOneAnswer()
        {
            var input01 = Substitute.For <IPrompt>();

            input01.Answer().Returns("Answer");

            var Inquirer = new Inquirer(input01);

            Inquirer.Answers().Should().HaveCount(1);
            Inquirer.Answers()[0].Should().Be("Answer");
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            bool              done              = false;
            ConfigRepository  config            = new ConfigRepository();
            HexConverter      hex               = new HexConverter();
            FPSFixRepository  fPSFixRepository  = new FPSFixRepository(config, hex);
            ProcessRepository processRepository = new ProcessRepository(config.Get("FF7ProcessName"));

            List <CommandOption> colors = Enum.GetValues(typeof(CommandOption)).Cast <CommandOption>().ToList();

            for (;;)
            {
                Inquirer.Prompt(Question.List("Choose favourite color", colors)).Then((command) => {
                    switch (command)
                    {
                    case CommandOption.Exit:
                        done = true;
                        return;

                    case CommandOption.GetFPSFixValueFromFile:
                        Console.Clear();
                        Console.WriteLine("Get FPSFix value");
                        Console.WriteLine(fPSFixRepository.GetFPSFIXValue().ToString());
                        Console.ReadLine();
                        break;

                    case CommandOption.SaveFPSFixValueToFile:
                        Console.Clear();
                        Console.WriteLine("Enter a new value: (integer only!)");
                        int newValue = int.Parse(Console.ReadLine());
                        Console.WriteLine($"New value is: {newValue.ToString()}");
                        fPSFixRepository.SaveFPSFixValue(newValue);
                        Console.ReadLine();
                        break;

                    case CommandOption.AttachToGame:
                        Task.Run(() => RunGame());
                        break;

                    case CommandOption.DetatchFromGame:
                        break;
                    }
                });
                Inquirer.Go();

                if (done)
                {
                    return;
                }
            }
        }
Ejemplo n.º 5
0
        public static void Run()
        {
            var emailInput = new Input("name", "What is your email?");

            var passwordInput = new PasswordInput("password", "What is the password?");

            var inquirer = new Inquirer(emailInput, passwordInput);

            inquirer.Ask();

            System.Console.WriteLine($@"Your email is {emailInput.Answer()}!");
            System.Console.WriteLine($@"Secret password: {passwordInput.Answer()}!");
            System.Console.ReadKey();
        }
Ejemplo n.º 6
0
        public static void Run()
        {
            var options   = new string[] { "Option 1", "Option 2" };
            var listInput = new ListInput("option", "Which option?", options);
            var sureInput = new InputConfirmation("confirm", "Are you sure?");

            var inquirer = new Inquirer(listInput, sureInput);

            inquirer.Ask();

            var answer = listInput.Answer();

            Console.WriteLine($@"You have selected option: {answer} - {options[Int32.Parse(answer)-1]}");
            Console.WriteLine(sureInput.Answer() == "y" ? "And you are sure!" : "And you are not sure!");
            Console.ReadKey();
        }
Ejemplo n.º 7
0
        public void SaveInquirer(InquirerViewModel viewModel)
        {
            Inquirer inquirerForSave = new Inquirer();

            inquirerForSave.Name = viewModel.Name;
            if (viewModel.HasText)
            {
                inquirerForSave.Text = viewModel.TextInput;
            }
            if (viewModel.HasRadio)
            {
                inquirerForSave.Radio = viewModel.RadioInput;
            }
            pc.Inquirers.Add(inquirerForSave);
            pc.SaveChanges();
        }
Ejemplo n.º 8
0
        public static void Run()
        {
            var numbersOnly = new RegexValidator("^[0-9]*$");
            var nameInput   = new Input("name", "What is your name?");
            var ageInput    = new Input("age", "What is your age?");

            ageInput.SetValid(numbersOnly);

            var passwordInput = new PasswordInput("password", "What is the password?");

            var inquirer = new Inquirer(nameInput, ageInput, passwordInput);

            inquirer.Ask();

            System.Console.WriteLine($@"Hello {nameInput.Answer()}! Your age is {ageInput.Answer()}");
            System.Console.WriteLine($@"Secret password: {passwordInput.Answer()}!");
            System.Console.ReadKey();
        }
Ejemplo n.º 9
0
        public void ShouldAskQuestionsInOrder()
        {
            var calledInput1 = false;
            var calledInput2 = false;
            var input01      = Substitute.For <IPrompt>();
            var input02      = Substitute.For <IPrompt>();

            input01.When(x => x.Ask())
            .Do(x => calledInput1 = true);
            input02.When(x => x.Ask())
            .Do(x => { if (calledInput1)
                       {
                           calledInput2 = true;
                       }
                });


            var Inquirer = new Inquirer(input01, input02);

            Inquirer.Ask();

            calledInput2.Should().BeTrue();
        }
Ejemplo n.º 10
0
        public static MvcHtmlString GenerateInquirerResults(this HtmlHelper html, IEnumerable <Inquirer> inquirers)
        {
            TagBuilder ul = new TagBuilder("ul");

            ul.AddCssClass("list-group");
            TagBuilder h1       = new TagBuilder("h1");
            Inquirer   inquirer = inquirers.First();

            h1.InnerHtml += inquirer.Name;
            ul.InnerHtml += h1.ToString();
            Dictionary <string, int> textDictionary = new Dictionary <string, int>();

            if (inquirer.Text != null)
            {
                foreach (Inquirer singleResult in inquirers)
                {
                    if (!textDictionary.ContainsKey(singleResult.Text))
                    {
                        textDictionary.Add(singleResult.Text, 1);
                    }
                    else
                    {
                        textDictionary[singleResult.Text]++;
                    }
                }
                var textDictionaryOrdered = textDictionary.OrderByDescending(x => x.Value);
                foreach (var pair in textDictionaryOrdered)
                {
                    TagBuilder li = new TagBuilder("li");
                    li.AddCssClass("list-group-item");
                    li.SetInnerText(string.Format("{0} - {1}", pair.Key, pair.Value));
                    ul.InnerHtml += li.ToString();
                }
                TagBuilder hr = new TagBuilder("hr");
                ul.InnerHtml += hr.ToString();
            }
            Dictionary <string, int> radioDictionary = new Dictionary <string, int>();

            if (inquirer.Radio != null)
            {
                foreach (Inquirer singleResult in inquirers)
                {
                    if (!radioDictionary.ContainsKey(singleResult.Radio))
                    {
                        radioDictionary.Add(singleResult.Radio, 1);
                    }
                    else
                    {
                        radioDictionary[singleResult.Radio]++;
                    }
                }
                var radioDictionaryOrdered = radioDictionary.OrderByDescending(x => x.Value);
                foreach (var pair in radioDictionaryOrdered)
                {
                    TagBuilder li = new TagBuilder("li");
                    li.AddCssClass("list-group-item");
                    li.SetInnerText(string.Format("{0} - {1}", pair.Key, pair.Value));
                    ul.InnerHtml += li.ToString();
                }
                TagBuilder hr = new TagBuilder("hr");
                ul.InnerHtml += hr.ToString();
            }
            return(new MvcHtmlString(ul.ToString()));
        }