public void IsValidPhoneNumber() { string[] phones = { "+7(985)531-08-68", "8(3519)454-54-541", "8(800)454-54-54", "8(800)8455412", "8(3519)454-54-54", "" }; for (int i = 0; i < phones.Length; ++i) { var currentValue = phones[i]; if (i % 2 == 0) { Assert.AreEqual(UserInputValidator.IsValidPhoneNumber(currentValue), true); } else { Assert.AreEqual(UserInputValidator.IsValidPhoneNumber(currentValue), false); } } }
public void IsValidNumber() { int minBound = 42; int maxBound = 10000; string[] numbers = { "2134", "21313-213-1", "430", "-21331", "02131", "10001", "939", "" }; for (int i = 0; i < numbers.Length; ++i) { var currentValue = numbers[i]; if (i % 2 == 0) { Assert.AreEqual(UserInputValidator.IsValidNumber(currentValue, minBound, maxBound, out _), true); } else { Assert.AreEqual(UserInputValidator.IsValidNumber(currentValue, minBound, maxBound, out _), false); } } }
public void IsValidDateInFormat() { var format = "dd.MM.yyyy"; string[] dates = { "10.07.1998", "32.01.2020", "28.02.2000", "30.02.2001", "13.12.2015", "13.13.2013" }; for (int i = 0; i < dates.Length; ++i) { var currentValue = dates[i]; if (i % 2 == 0) { Assert.AreEqual(UserInputValidator.IsValidDateInFormat(currentValue, format, out _), true); } else { Assert.AreEqual(UserInputValidator.IsValidDateInFormat(currentValue, format, out _), false); } } }
public void IsValidEmail() { string[] emails = { "*****@*****.**", "_233", "*****@*****.**", "saakjg@", "*****@*****.**", "" }; for (int i = 0; i < emails.Length; ++i) { var currentValue = emails[i]; if (i % 2 == 0) { Assert.AreEqual(UserInputValidator.IsValidEmail(currentValue), true); } else { Assert.AreEqual(UserInputValidator.IsValidEmail(currentValue), false); } } }
public void Setup() { _baseUrl = @"http://api.worldbank.org/v2/country/"; _brasilCountryCode = "BR"; _franceCountryCode = "FR"; _brasilCountrySearcher = new CountrySearcher(_brasilCountryCode, _baseUrl); _franceCountrySearcher = new CountrySearcher(_franceCountryCode, _baseUrl); _validator = new UserInputValidator(); }
public void ValidateDates() { var output = new MockOutputAstext(); var inputValidator = new UserInputValidator(new UserInputMocks(new List <string>()), output, new MockDisplayMessage()); var result = inputValidator.ValidateDate("31 March"); Assert.Equal("31 March", result); var numberOfErrorMessages = output.OutCounter; Assert.Equal(0, numberOfErrorMessages); }
public string ReadPhoneNumberWithHint(string hint) { System.Console.WriteLine(hint); var format = "[+7|7|8]([ddd|dddd])ddd-dd-dd"; var phone = ReadLineWithHint($"Enter the phone number in this format {format}: "); while (!UserInputValidator.IsValidPhoneNumber(phone)) { phone = ReadLineWithHint($"Please enter a valid phone number in this format {format}!"); } System.Console.WriteLine(); return(phone); }
public void AcceptNumbersUntilValid2() { var output = new MockOutputAstext(); var backupUserInputs = new List <string> { "xkfjnlfn", "dgf", "565" }; var inputValidator = new UserInputValidator(new UserInputMocks(backupUserInputs), output, new MockDisplayMessage()); var result = inputValidator.ValidateInteger("sdfbf"); Assert.Equal(565, result); var numberOfErrorMessages = output.OutCounter; Assert.Equal(3, numberOfErrorMessages); }
public void ValidateDatesUntilValid() { var output = new MockOutputAstext(); var backupUserInputs = new List <string> { "dsf", "10 may" }; var inputValidator = new UserInputValidator(new UserInputMocks(backupUserInputs), output, new MockDisplayMessage()); var result = inputValidator.ValidateDate("xdksnf"); Assert.Equal("10 may", result); var numberOfErrorMessages = output.OutCounter; Assert.Equal(2, numberOfErrorMessages); }
private int ValidatePlayersInput(IPlayer player, List <int> gameMap) { bool mapValidated = false; while (!mapValidated) { player.Input = UserInputValidator.ValidateInput(Console.ReadLine()); mapValidated = ValidInputForMap(gameMap, player.Input); if (!mapValidated) { Console.WriteLine($"Please pick a number on the map, {player.Input} couldn't be found"); } } return(player.Input); }
public static Boolean ValidateAgeofAccount(DateTime birthdate) { if (birthdate == null) { throw new NullReferenceException("null date in the age of account validation"); } if (!UserInputValidator.ValidateDateLessThanCurrent(birthdate) || CalculateAge(birthdate) < MIN_AGE) { return(false); } else { return(true); } }
static void Main(string[] args) { IConfiguration config = GetConfiguration(); ISqlDbAccess db = new SqliteDbAccess(config); IPasswordCrypto crypto = new PasswordCrypto(); SqliteUserService userService = new SqliteUserService(db, crypto); SqliteMessageService messageService = new SqliteMessageService(db); UserInputValidator validator = new UserInputValidator(); LoginRoutine loginRoutine = new LoginRoutine(userService, validator); //Console.WriteLine("Logging in"); //Console.Write("username: "******"Your password: "******"Signing up result: { confirmed }"); //Console.ReadLine(); //MessageRoutine messageRoutine = new MessageRoutine(messageService, userService); ////MessageModel message = new MessageModel() ////{ //// Message = "This is the first message.", //// FromUserId = 1 ////}; ////messageRoutine.SendMessage(message, "juusvali"); //List<MessageFullModel> newMessages = messageRoutine.GetNewMessages(2); //foreach (var item in newMessages) //{ // Console.WriteLine($"To: { item.ToUserId }, from: { item.UserName }"); // Console.WriteLine(item.Message); //} }
public int ReadNumberWithHint(string hint, int minBound, int maxBound) { System.Console.WriteLine(hint); var input = System.Console.ReadLine(); int number; while (!UserInputValidator.IsValidNumber(input, minBound, maxBound, out number)) { System.Console.WriteLine($"Please enter a number between {minBound} and {maxBound}!"); System.Console.WriteLine(hint); input = System.Console.ReadLine(); } System.Console.WriteLine(); return(number); }
public decimal ReadPriceWithHint(string hint) { System.Console.WriteLine(hint); string input = System.Console.ReadLine(); decimal price; while (!UserInputValidator.IsValidPrice(input, out price)) { System.Console.WriteLine($"Please enter a non-negative decimal!"); System.Console.WriteLine(hint); input = System.Console.ReadLine(); } System.Console.WriteLine(); return(price); }
public DateTime ReadDateWithHint(string hint) { System.Console.WriteLine(hint); string dateFormat = "dd.MM.yyyy"; string input = System.Console.ReadLine(); DateTime date; while (!UserInputValidator.IsValidDateInFormat(input, dateFormat, out date)) { System.Console.WriteLine($"Please enter the order date in this format {dateFormat}!"); System.Console.WriteLine(hint); input = System.Console.ReadLine(); } System.Console.WriteLine(); return(date); }
private void ValidateUserInput(UserInput userInput) { try { var userInputValidator = new UserInputValidator(userInput); userInputValidator.Validate(); } catch (UserInputException ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Validation error:"); Console.WriteLine(ex.Message); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("Press any key to exit"); Console.ForegroundColor = ConsoleColor.Gray; Console.ReadKey(); Environment.Exit(0x2); } }
public UserInputValidatorTests() { _underTest = new UserInputValidator(); }
private void addButton_Click(object sender, EventArgs e) { var hostnameValidation = UserInputValidator.ValidateNetworkHostname(hostnameTextBox.Text); var portValidation = UserInputValidator.ValidateNetworkPortNumber(portTextBox.Text); var apiKeyValidation = UserInputValidator.ValidateSyncthingApiKey(apiKeyTextBox.Text); var displayNameValidation = UserInputValidator.ValidateSyncthingDisplayName(customNameTextBox.Text); var errorMessages = new List <string>(); // Validate port number if (!portValidation.IsValid) { errorMessages.Add(portValidation.Message); } // Validate hostname if (!hostnameValidation.IsValid) { errorMessages.Add(hostnameValidation.Message); } // Validate API key if (!apiKeyValidation.IsValid) { errorMessages.Add(apiKeyValidation.Message); } if (errorMessages.Count > 0) { MetroMessageBox.Show(this, String.Join(Environment.NewLine, errorMessages), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var instance = new ManagedInstance { UseHttps = useHttpsToggle.Checked, ApiKey = apiKeyValidation.ValidatedValue }; instance.PossibleEndpoints.Add(new RestEndpoint { Hostname = hostnameValidation.ValidatedValue, Port = portValidation.ValidatedValue, Priority = 100, IsPingable = true }); // Assign display name if (displayNameValidation.IsValid) { instance.CustomName = customNameTextBox.Text.Trim(); } Log.Logger.Information("New Syncthing instance created: {@Instance}", instance); Singleton <SyncthingInstanceManager> .Instance.Add(instance); AppSettings.Save(ParentForm); Close(); }
public ValidatorOutput ValidatorUserInput(UserInputValidator input) { return(new ValidatorOutput { Result = 42 }); }
public void RangeValidateGoodScenarioTest(string inputValue) { var validationOutcome = UserInputValidator.RangeValidate(inputValue); Assert.That(validationOutcome, Is.EqualTo(ValidationOutcome.ValidationSuccess)); }
public void ExistingCategoryAsyncTest(string category) { var validationOutcome = UserInputValidator.JokeCategoryValidate(category); Assert.That(validationOutcome, Is.EqualTo(ValidationOutcome.ValidationSuccess)); }
public void NotExistingCategoryAsyncTest(string category) { var validationOutcome = UserInputValidator.JokeCategoryValidate(category); Assert.That(validationOutcome, Is.EqualTo(ValidationOutcome.ValidationInvalidInputGeneric)); }