private void BtnLogin_Click(object sender, RoutedEventArgs e) { var userName = TbUserName.Text; var password = PbPassword.Password; var registrationRequired = CheckBoxRegistration.IsChecked == true; //Validate correctness of login credentials try { LoginValidator.ValidateLogin(userName, password, registrationRequired); } catch (ArgumentException exception) { MessageBox.Show(exception.Message); return; } //Connects user if everything is OK _clientService = new ClientService(); _clientService.FaultExceptionThrown += FaultExceptionOccured; _clientService.ConnectUser(userName, password, registrationRequired); _clientService.FaultExceptionThrown -= FaultExceptionOccured; if (_clientService.CurrentUser == null) { return; } //Creates main window instance and shows it MainWindow mainWindow = new MainWindow(_clientService, this); mainWindow.Title += $" - {userName}"; mainWindow.Show(); Hide(); }
public void RestrictedUsernameStr() { string[] badUserNames = { "someUsername`", "someUsername~", "someUsername!", "someUsername@", "someUsername#", "someUsername$", "someUsername%", "someUsername^", "someUsername|", "someUsername&", "someUsername*", "someUsername)", "someUsername-", "someUsername+", "someUsername[", "someUsername]", "someUsername\"", "someUsername/", "someUsername№", "someUsername;", "someUsername:"******"someUsername?", "someUsername="******"someUsername<", "someUsername>", "someUsername,", "someUsername'", "someUsername{", "someUsername}", "someUsername ", }; string password = "******"; foreach (var username in badUserNames) { string actualExMessage = null; try { LoginValidator.ValidateLogin(username, password, false); } catch (ArgumentException e) { actualExMessage = e.Message; } if (actualExMessage == null) { Assert.Fail(); } Assert.AreEqual(_exMessageRestrictedSymbol, actualExMessage); } }
public void ValidUsernameSymbols() { string[] goodUserNames = { "someUsername.", "someUsername_", }; string password = "******"; foreach (var username in goodUserNames) { LoginValidator.ValidateLogin(username, password, false); } }
public void LongUsernameStr() { string userName = "******"; string password = "******"; try { LoginValidator.ValidateLogin(userName, password, false); } catch (ArgumentException e) { Assert.AreEqual(_exMessageLongUsername, e.Message); return; } Assert.Fail(); }
public void EmptyPasswordStr() { string userName = "******"; string password = ""; try { LoginValidator.ValidateLogin(userName, password, false); } catch (ArgumentException e) { Assert.AreEqual(_exMessageEmptyInput, e.Message); return; } Assert.Fail(); }
public void ShortPasswordStr() { string userName = "******"; string password = "******"; try { LoginValidator.ValidateLogin(userName, password, true); } catch (ArgumentException e) { Assert.AreEqual(_exMessageShortPassword, e.Message); return; } Assert.Fail(); }