コード例 #1
0
        private EditStationForm()
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            positionValidator = new NumberValidator(positionTextBox, false, false, errorMessage: "Bitte eine Zahl als Position eingeben!");
            nameValidator     = new NotEmptyValidator(nameTextBox, errorMessage: "Bitte einen Bahnhofsnamen eingeben!");
            validators        = new ValidatorCollection(positionValidator, nameValidator);

            this.Shown += (s, e) =>
            {
                stationRendererHeight = stationRenderer.Height;
                stationRendererWidth  = stationRenderer.Width;
            };
            stationRenderer.SizeChanged += (s, e) =>
            {
                if (WindowShown && stationRenderer.Height > stationRendererHeight)
                {
                    var diff = stationRenderer.Height - stationRendererHeight;
                    this.Height          += diff;
                    stationRendererHeight = stationRenderer.Height;
                }
                if (WindowShown && stationRenderer.Width > stationRendererWidth)
                {
                    var diff = stationRenderer.Width - stationRendererWidth;
                    this.Width          += diff;
                    stationRendererWidth = stationRenderer.Width;
                }
            };
        }
コード例 #2
0
        public ActionResult Number(Reservation model)
        {
            _log.InfoFormat("New request number: {0} attempting entry.", model.Number);


            if (!NumberValidator.IsPhoneNumber(model.Number))
            {
                return(View());
            }

            if (_twilioRepository.MaxRequestsNotReached(model.Number) &&
                _personRepository.CheckPhoneNumberExists(model.Number))
            {
                TwilioMessage message = new TwilioMessage()
                {
                    To      = model.Number,
                    Message = _codeGenerator.GenerateCode()
                };

                //Send Message to Phone Number
                _twilioMessageProvider.SendMessage(message);

                //Create the database object
                TwilioMessaging messageDB = new TwilioMessaging()
                {
                    Code        = _codeGenerator.HashCode(message.Message),
                    Date        = DateTime.Now,
                    PhoneNumber = model.Number
                };

                //Log code
                _twilioRepository.AddRequest(messageDB);
            }
            return(View());
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: alfredq6/GuessNumberGame
        protected void GuessingPlayerActions()
        {
            Console.Clear();
            Console.WriteLine("Guessing player, press any key to start...");
            Console.ReadKey();
            Console.WriteLine("Try guess a number!");

            MaxAttempt = GetMaxAttempt(Min, Max);
            do
            {
                validator = new MinMaxValidator(Min, Max);
                Console.WriteLine($"Min value is {Min} and max is {Max}");
                GuessingPlayerNumber = NumberValidator.ConvertStringToNumber(validator);

                if (GuessingPlayerNumber > GuessingNumber)
                {
                    validator.maxValue = validator.IsValid(GuessingPlayerNumber) ? GuessingPlayerNumber : validator.maxValue;
                    Max = (int)validator.maxValue;
                }

                if (GuessingPlayerNumber < GuessingNumber)
                {
                    validator.minValue = validator.IsValid(GuessingPlayerNumber) ? GuessingPlayerNumber : validator.minValue;
                    Min = (int)validator.minValue;
                }

                if (GuessingPlayerNumber == GuessingNumber)
                {
                    IsWin = true;
                }

                Console.WriteLine($"It was your {++Attempt}/{MaxAttempt} attempt");
            } while (!IsWin && Attempt != MaxAttempt);
        }
コード例 #4
0
        public void Sut_IsValid_WhenReceiveAMinusZeroNumber_ShouldReturnFalse(
            NumberValidator sut)
        {
            var result = sut.isValid(-1);

            result.Should().BeFalse();
        }
コード例 #5
0
 /// <summary>
 /// Constructor, initializes different objects needed
 /// </summary>
 /// <param name="linesOfInvoice">lines of invoice being mapped</param>
 public InvoiceMapper(string[] linesOfInvoice)
 {
     linesOfInvoiceToProcess = linesOfInvoice;
     dateValidator           = new DateValidator();
     numberValidator         = new NumberValidator();
     InvoiceErrors           = new List <string>();
 }
コード例 #6
0
 /// <summary>
 /// Constructor for MainWindow, adds dependencies
 /// </summary>
 public MainWindow()
 {
     InitializeComponent();
     invoiceCalculator = new InvoiceCalculator();
     numberValidator   = new NumberValidator();
     dateValidator     = new DateValidator();
 }
コード例 #7
0
        public void Sut_IsValid_WhenReceiveANumberBetween0And100_ShouldReturnTrue(
            int number, NumberValidator sut)
        {
            var result = sut.isValid(number);

            result.Should().BeTrue();
        }
コード例 #8
0
        public void ShouldReturnTrueForIntAndHasToBeEqualToInputDate()
        {
            NumberValidator numberValidator = new NumberValidator(testValueInt, separator1);

            Assert.IsTrue(numberValidator.Validate());
            Assert.AreEqual(testValueInt, numberValidator.Number);
        }
コード例 #9
0
        public void Sut_IsValid_WhenReceiveANumberGreaterThan100_ShouldReturnFalse(
            NumberValidator sut)
        {
            var result = sut.isValid(101);

            result.Should().BeFalse();
        }
コード例 #10
0
        public void ShouldReturnTrueForCorrectStringAndHasToBeEqualToInputDate()
        {
            NumberValidator numberValidator = new NumberValidator(correctTestString, separator1);

            Assert.IsTrue(numberValidator.Validate());
            Assert.AreEqual(testValueDouble, numberValidator.Number);
        }
コード例 #11
0
        private static void GetInputForAffineCipher(IEnumerable <string> messages, Storage storage)
        {
            Printer.Print(messages.ElementAt(0));

            var oddNumberSequence = _oddNumberGenerator.GetNumbersBetween(0, 25);
            var builder           = new StringBuilder();

            foreach (var number in oddNumberSequence)
            {
                builder.Append($"{number} ");
            }

            Printer.Print(builder.ToString());

            var oddKey = Reader.Read <int>();

            if (NumberValidator.IsOdd(oddKey))
            {
                if (oddNumberSequence.Contains(oddKey))
                {
                    storage.AffineKeys.KeyOne = oddKey;
                }

                Printer.Print(messages.ElementAt(1));

                var randKey = Reader.Read <int>();
                if (randKey >= 0 && randKey <= 25)
                {
                    storage.AffineKeys.KeyTwo = randKey;
                }
            }
        }
コード例 #12
0
        public void ShouldReturnTrueForDecimalAndHasToBeEqualToInputDate()
        {
            NumberValidator numberValidator = new NumberValidator(testValueDecimal, separator2);

            Assert.IsTrue(numberValidator.Validate());
            Assert.AreEqual(testValueDecimal, (decimal)numberValidator.Number);
        }
コード例 #13
0
        public void ShouldReturnTrueForIncorrectStringAndHasToBeEqualZero()
        {
            NumberValidator numberValidator = new NumberValidator(incorrectTestString, separator1);

            Assert.IsFalse(numberValidator.Validate());
            Assert.AreEqual(0, numberValidator.Number);
        }
コード例 #14
0
        public static void StartMainMenu(ref Game game, ref bool exit)
        {
            Console.Clear();
            Console.WriteLine("Menu:");
            Console.WriteLine($"{(int)UserGameTypeChoice.PlayWithAnotherPlayer} - Play with another player");
            Console.WriteLine($"{(int)UserGameTypeChoice.PlayWithComputer} - Play with computer");
            Console.WriteLine($"{(int)UserGameTypeChoice.Exit} - Exit");

            UserGameTypeChoice choice = (UserGameTypeChoice)NumberValidator.ConvertStringToNumber();

            switch (choice)
            {
            case UserGameTypeChoice.PlayWithAnotherPlayer:
            {
                Console.Clear();
                game = new GameVersusPlayer();
                break;
            }

            case UserGameTypeChoice.PlayWithComputer:
            {
                StartLevelMenu(ref game);
                break;
            }

            case UserGameTypeChoice.Exit:
            {
                exit = true;
                break;
            }

            default: break;
            }
        }
コード例 #15
0
        public static void StartLevelMenu(ref Game game)
        {
            Console.Clear();
            Console.WriteLine($"{(int)UserLevelChoice.Easy} - Easy level");
            Console.WriteLine($"{(int)UserLevelChoice.Medium} - Medium level");
            Console.WriteLine($"{(int)UserLevelChoice.Hard} - Hard level");
            UserLevelChoice choiceLevel = (UserLevelChoice)NumberValidator.ConvertStringToNumber();

            switch (choiceLevel)
            {
            case UserLevelChoice.Easy:
            {
                game = new EasyLevelGame();
                break;
            }

            case UserLevelChoice.Medium:
            {
                game = new MediumLevelGame();
                break;
            }

            case UserLevelChoice.Hard:
            {
                game = new HardLevelGame();
                break;
            }

            default: break;
            }
        }
コード例 #16
0
        public TrainCopyDialog(Train t, Timetable tt)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            diffValidator   = new NumberValidator(diffTextBox, false, true, errorMessage: T._("Bitte die Verschiebung als Zahl in Minuten angeben!"));
            countValidator  = new NumberValidator(countTextBox, false, true, allowNegative: false, errorMessage: T._("Bitte eine gültige Anzahl >0 neuer Züge eingeben!"));
            changeValidator = new NumberValidator(changeTextBox, false, true, errorMessage: T._("Bitte eine gültige Veränderung der Zugnummer eingeben!"));

            train              = t;
            this.tt            = tt;
            nameTextBox.Text   = t.TName;
            diffTextBox.Text   = "+20";
            countTextBox.Text  = "1";
            changeTextBox.Text = "2";

            modeSelect = new SelectionUI <CopySelectionMode>(mode => UpdateVisibility(), selectStack);
            linkSelect = new SelectionUI <LinkTypeMode>(linkType => UpdateVisibility(), linkTypeStack);

            if (tt.Type == TimetableType.Network && tt.Version.CompareTo(TimetableVersion.Extended_FPL2) < 0)
            {
                modeSelect.DisableOption(CopySelectionMode.Link);
            }

            specialNameGridView.AddColumn((SpecialNameEntry spn) => spn.RowNumber.ToString(), "");
            specialNameGridView.AddColumn((SpecialNameEntry spn) => spn.Name, T._("Zugname"), true);
            specialNameGridView.DataStore = new[] { new SpecialNameEntry(1, "") };
        }
コード例 #17
0
        public ConfigForm(Timetable tt, IPluginInterface pluginInterface)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            backupHandle = pluginInterface.BackupTimetable();

            this.tt = tt;
            this.pluginInterface = pluginInterface;

            heightPerHourValidator = new NumberValidator(heightPerHourTextBox, false, false, errorMessage: "Bitte eine Zahl als Höhe pro Stunde angeben!");
            startTimeValidator     = new TimeValidator(startTimeTextBox, false, errorMessage: "Bitte eine gültige Uhrzeit im Format hh:mm angeben!");
            endTimeValidator       = new TimeValidator(endTimeTextBox, false, errorMessage: "Bitte eine gültige Uhrzeit im Format hh:mm angeben!", maximum: new TimeEntry(48, 0));
            validators             = new ValidatorCollection(heightPerHourValidator, startTimeValidator, endTimeValidator);

            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, bgColorComboBox, "BgColor");
            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, stationColorComboBox, "StationColor");
            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, timeColorComboBox, "TimeColor");
            DropDownBind.Color <TimetableStyle>(pluginInterface.Settings, trainColorComboBox, "TrainColor");

            DropDownBind.Font <TimetableStyle>(stationFontComboBox, stationFontSizeComboBox, "StationFont");
            DropDownBind.Font <TimetableStyle>(timeFontComboBox, timeFontSizeComboBox, "TimeFont");
            DropDownBind.Font <TimetableStyle>(trainFontComboBox, trainFontSizeComboBox, "TrainFont");

            DropDownBind.Width <TimetableStyle>(hourTimeWidthComboBox, "HourTimeWidth");
            DropDownBind.Width <TimetableStyle>(minuteTimeWidthComboBox, "MinuteTimeWidth");
            DropDownBind.Width <TimetableStyle>(stationWidthComboBox, "StationWidth");
            DropDownBind.Width <TimetableStyle>(trainWidthComboBox, "TrainWidth");

            var styles = new Dictionary <StationLineStyle, string>()
            {
                [StationLineStyle.None]   = "Keine",
                [StationLineStyle.Normal] = "Gerade Linien",
                [StationLineStyle.Cubic]  = "Kubische Linien",
            };

            if (tt.Version == TimetableVersion.JTG2_x)
            {
                styles.Remove(StationLineStyle.Cubic);
            }
            DropDownBind.Enum <TimetableStyle, StationLineStyle>(stationLinesDropDown, "StationLines", styles);

            heightPerHourTextBox.TextBinding.AddFloatConvBinding <TimetableStyle, TextControl>(s => s.HeightPerHour);

            startTimeTextBox.TextBinding.AddTimeEntryConvBinding <TimetableStyle, TextControl>(s => s.StartTime);
            endTimeTextBox.TextBinding.AddTimeEntryConvBinding <TimetableStyle, TextControl>(s => s.EndTime);

            includeKilometreCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.DisplayKilometre);
            drawStationNamesCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.DrawHeader);
            stationVerticalCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.StationVertical);
            multitrackCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.MultiTrack);
            networkTrainsCheckBox.CheckedBinding.BindDataContext <TimetableStyle>(s => s.DrawNetworkTrains);

            networkTrainsCheckBox.Enabled = tt.Type == TimetableType.Network;

            attrs       = new TimetableStyle(tt);
            DataContext = attrs;

            this.AddCloseHandler();
        }
コード例 #18
0
        public void IsNumber_WithIntegerWorks()
        {
            var numVal = new NumberValidator();

            var result = numVal.IsValid("123", "Temp");

            Assert.IsTrue(result);
        }
コード例 #19
0
        public void IsNumber_WithDecimalWorks()
        {
            var numVal = new NumberValidator();

            var result = numVal.IsValid("1234.12", "Temp");

            Assert.IsTrue(result);
        }
コード例 #20
0
        public void Valid_Number_Should_Return_IsValid_True()
        {
            var validator = new NumberValidator();

            var result = validator.IsValid("345882865");

            Assert.True(result);
        }
コード例 #21
0
        public void IsNumber_WithLettersFails()
        {
            var numVal = new NumberValidator();

            var result = numVal.IsValid("1a234.12", "Temp");

            Assert.IsFalse(result);
        }
コード例 #22
0
        public NumberVerifierMain(INumberVerifierSettings numberVerifierSettings)
        {
            _verificationSettings = numberVerifierSettings;

            _textFormatter ??= new TextFormatter();

            _numberValidator = new NumberValidator();
        }
コード例 #23
0
        public void ShouldReturnFalseForEmptyObjectAndHasToBeEqualZero()
        {
            object          emptyObject     = new object();
            NumberValidator numberValidator = new NumberValidator(emptyObject, separator1);

            Assert.IsFalse(numberValidator.Validate());
            Assert.AreEqual(0, numberValidator.Number);
        }
コード例 #24
0
        private NumberController CreateController()
        {
            var validator  = new NumberValidator();
            var formatter  = new NumberFormatter(validator);
            var controller = new NumberController(formatter, validator);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            return(controller);
        }
コード例 #25
0
        public TrainFillDialog(Train train)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            offsetValidator = new NumberValidator(offsetTextBox, false, true, errorMessage: T._("Bitte die Verschiebung als Zahl in Minuten angeben!"));

            offsetTextBox.Text = "+20";

            trainsComboBox.ItemTextBinding = Binding.Delegate <Train, string>(t => t.TName);
            trainsComboBox.DataStore       = new TrainEditHelper().FillCandidates(train).ToArray();
            trainsComboBox.SelectedIndex   = 0;
        }
コード例 #26
0
        public void Validate_ValidNumber_ReturnTrue()
        {
            // Arrange
            var validator = new NumberValidator();
            var number    = "+46712312123";

            // Act
            var validationResult = validator.Validate(number);

            // Assert
            validationResult.Should().BeTrue();
        }
コード例 #27
0
        public void Validate_InvalidCharacters_ReturnFalse()
        {
            // Arrange
            var validator = new NumberValidator();
            var number    = "T00467562341424";

            // Act
            var validationResult = validator.Validate(number);

            // Assert
            validationResult.Should().BeFalse();
        }
コード例 #28
0
        public void Validate_TooManyDigits_ReturnFalse()
        {
            // Arrange
            var validator = new NumberValidator();
            var number    = "00467562341424";

            // Act
            var validationResult = validator.Validate(number);

            // Assert
            validationResult.Should().BeFalse();
        }
コード例 #29
0
        public void ErrorMessage_CustomFormat_AreEqual()
        {
            string column = "測試欄位";

            NumberValidator validator = new NumberValidator(column, "error", "{0}Number");

            validator.Validate();

            Assert.AreEqual(
                string.Format(validator.CustomErrorMessageFormat, column),
                validator.ErrorMessage
                );
        }
コード例 #30
0
        public void ErrorMessage_MinFormat_AreEqual()
        {
            string column = "測試欄位";

            NumberValidator validator = NumberValidator.CreateMinValue(column, "0.1", 1.1m);

            validator.Validate();

            Assert.AreEqual(
                string.Format(validator.MinValueErrorMessageFormat, column, 1.1m),
                validator.ErrorMessage
                );
        }