<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using Riganti.Utils.Testing.Selenium.Core;
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using Dotvvm.Samples.Tests;

namespace DotVVM.Samples.Tests.Control
{
    [TestClass]
    public class TextBoxTests : SeleniumTest
    {
        [TestMethod]
        public void Control_TextBox()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_TextBox_TextBox);

                browser.First("#TextBox1").CheckTagName("input");
                browser.First("#TextBox2").CheckTagName("input");
                browser.First("#TextArea1").CheckTagName("textarea");
                browser.First("#TextArea2").CheckTagName("textarea");
            });
        }
                
        [TestMethod]
        public void Control_TextBox_StringFormat(string url = null)
        {
            url = url ?? SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format;
            RunInAllBrowsers(browser =>
            {
                void checkForLanguage(string language)
                {
                    var culture = new CultureInfo(language);
                    var dateResult1 = browser.First("#date-result1").GetText();
                    var dateResult2 = browser.First("#date-result2").GetText();
                    var dateResult3 = browser.First("#date-result3").GetText();

                    var dateTextBox = browser.First("#dateTextbox").CheckAttribute("value", dateResult1);
                    var dateText = browser.First("#DateValueText").CheckIfInnerTextEquals(new DateTime(2015, 12, 27).ToString("G", culture));

                    var numberTextbox = browser.First("#numberTextbox").CheckAttribute("value", 123.1235.ToString(culture));
                    var numberValueText = browser.First("#numberValueText").CheckIfInnerTextEquals(123.123456789.ToString(culture));

                    //write new valid values 
                    dateTextBox.Clear().SendKeys(dateResult2);
                    numberTextbox.Clear().SendKeys(2000.ToString("n0", culture));
                    dateTextBox.Click().Wait();

                    //check new values
                    dateText.CheckIfInnerTextEquals(new DateTime(2018, 12, 27).ToString("G", culture));
                    numberValueText.CheckIfInnerTextEquals(2000.ToString(culture));

                    numberTextbox.CheckAttribute("value", 2000.ToString("n4", culture));
                    dateTextBox.CheckAttribute("value", dateResult2);

                    //write invalid values
                    dateTextBox.Clear().SendKeys("dsasdasd");
                    numberTextbox.Clear().SendKeys("000//*a");
                    dateTextBox.Click();

                    //check invalid values
                    dateText.CheckIfInnerTextEquals("");
                    numberValueText.CheckIfInnerTextEquals("");

                    numberTextbox.CheckAttribute("value", "000//*a");
                    dateTextBox.CheckAttribute("value", "dsasdasd");

                    //write new valid values 
                    dateTextBox.Clear().SendKeys(new DateTime(2018, 1, 1).ToString("d", culture));
                    numberTextbox.Clear().SendKeys(1000.550277.ToString(culture));
                    dateTextBox.Click().Wait();

                    //check new values 
                    dateText.CheckIfInnerTextEquals(new DateTime(2018, 1, 1).ToString("G", culture));
                    numberValueText.CheckIfInnerTextEquals(1000.550277.ToString(culture));

                    numberTextbox.CheckAttribute("value", 1000.550277.ToString("n4", culture));
                    dateTextBox.CheckAttribute("value", dateResult3);
                };

                //en-US
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format);
                checkForLanguage("en-US");

                //cs-CZ | reload
                browser.First("#czech").Click();
                checkForLanguage("cs-CZ");
            });
        }

        [TestMethod]
        public void Control_TextBox_StringFormat_Bindings()
        {
            Control_TextBox_StringFormat(SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format_Binding);<commit_msg>Control_TextBox_StringFormat changed signiture for MSTest2<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using Riganti.Utils.Testing.Selenium.Core;
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using Dotvvm.Samples.Tests;

namespace DotVVM.Samples.Tests.Control
{
    [TestClass]
    public class TextBoxTests : SeleniumTest
    {
        [TestMethod]
        public void Control_TextBox()
        {
            RunInAllBrowsers(browser =>
            {
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_TextBox_TextBox);

                browser.First("#TextBox1").CheckTagName("input");
                browser.First("#TextBox2").CheckTagName("input");
                browser.First("#TextArea1").CheckTagName("textarea");
                browser.First("#TextArea2").CheckTagName("textarea");
            });
        }

        [TestMethod]
        public void Control_TextBox_StringFormat()
        {
            Control_TextBox_StringFormat_core(SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format);
        }
        public void Control_TextBox_StringFormat_core(string url)
        {

            RunInAllBrowsers(browser =>
            {
                void checkForLanguage(string language)
                {
                    var culture = new CultureInfo(language);
                    var dateResult1 = browser.First("#date-result1").GetText();
                    var dateResult2 = browser.First("#date-result2").GetText();
                    var dateResult3 = browser.First("#date-result3").GetText();

                    var dateTextBox = browser.First("#dateTextbox").CheckAttribute("value", dateResult1);
                    var dateText = browser.First("#DateValueText").CheckIfInnerTextEquals(new DateTime(2015, 12, 27).ToString("G", culture));

                    var numberTextbox = browser.First("#numberTextbox").CheckAttribute("value", 123.1235.ToString(culture));
                    var numberValueText = browser.First("#numberValueText").CheckIfInnerTextEquals(123.123456789.ToString(culture));

                    //write new valid values 
                    dateTextBox.Clear().SendKeys(dateResult2);
                    numberTextbox.Clear().SendKeys(2000.ToString("n0", culture));
                    dateTextBox.Click().Wait();

                    //check new values
                    dateText.CheckIfInnerTextEquals(new DateTime(2018, 12, 27).ToString("G", culture));
                    numberValueText.CheckIfInnerTextEquals(2000.ToString(culture));

                    numberTextbox.CheckAttribute("value", 2000.ToString("n4", culture));
                    dateTextBox.CheckAttribute("value", dateResult2);

                    //write invalid values
                    dateTextBox.Clear().SendKeys("dsasdasd");
                    numberTextbox.Clear().SendKeys("000//*a");
                    dateTextBox.Click();

                    //check invalid values
                    dateText.CheckIfInnerTextEquals("");
                    numberValueText.CheckIfInnerTextEquals("");

                    numberTextbox.CheckAttribute("value", "000//*a");
                    dateTextBox.CheckAttribute("value", "dsasdasd");

                    //write new valid values 
                    dateTextBox.Clear().SendKeys(new DateTime(2018, 1, 1).ToString("d", culture));
                    numberTextbox.Clear().SendKeys(1000.550277.ToString(culture));
                    dateTextBox.Click().Wait();

                    //check new values 
                    dateText.CheckIfInnerTextEquals(new DateTime(2018, 1, 1).ToString("G", culture));
                    numberValueText.CheckIfInnerTextEquals(1000.550277.ToString(culture));

                    numberTextbox.CheckAttribute("value", 1000.550277.ToString("n4", culture));
                    dateTextBox.CheckAttribute("value", dateResult3);
                };

                //en-US
                browser.NavigateToUrl(SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format);
                checkForLanguage("en-US");

                //cs-CZ | reload
                browser.First("#czech").Click();
                checkForLanguage("cs-CZ");
            });
        }

        [TestMethod]
        public void Control_TextBox_StringFormat_Bindings()
        {
            Control_TextBox_StringFormat_core(SamplesRouteUrls.ControlSamples_TextBox_TextBox_Format_Binding);
{'fraction_non_alphanumeric': 0.11071268489466607, 'fraction_numerical': 0.02521290900941282, 'mean_word_length': 2.049197130167407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1363250', 'n_tokens_mistral': 2412, 'n_tokens_neox': 2085, 'n_words': 309}