예제 #1
0
        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();
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        public void ValidUsernameSymbols()
        {
            string[] goodUserNames =
            {
                "someUsername.",
                "someUsername_",
            };

            string password = "******";

            foreach (var username in goodUserNames)
            {
                LoginValidator.ValidateLogin(username, password, false);
            }
        }
예제 #4
0
        public void LongUsernameStr()
        {
            string userName = "******";
            string password = "******";

            try
            {
                LoginValidator.ValidateLogin(userName, password, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(_exMessageLongUsername, e.Message);
                return;
            }
            Assert.Fail();
        }
예제 #5
0
        public void EmptyPasswordStr()
        {
            string userName = "******";
            string password = "";

            try
            {
                LoginValidator.ValidateLogin(userName, password, false);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(_exMessageEmptyInput, e.Message);
                return;
            }
            Assert.Fail();
        }
예제 #6
0
        public void ShortPasswordStr()
        {
            string userName = "******";
            string password = "******";

            try
            {
                LoginValidator.ValidateLogin(userName, password, true);
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(_exMessageShortPassword, e.Message);
                return;
            }
            Assert.Fail();
        }