Ejemplo n.º 1
0
        private void AcceptButton_Click(object sender, EventArgs e)
        {
            // Pin Code
            PinVAL pinCode = null;

            // Validate Pin Code
            try
            {
                pinCode = new PinVAL(PinCodeTextBox.Text);
            }
            catch (PinVAL_Exception p_e)
            {
                ErrorLabel.Text = p_e.What();
                ErrorLabel.Show();
            }

            if (pinCode != null)
            {
                // Login basic user
                if (pinCode._Value.Length == 4)
                {
                    try
                    {
                        // Connect with basic users database
                        MockBasicUsersRepository mockBasicUsersRepository =
                            new MockBasicUsersRepository(SystemSettings._PlatformType);

                        // Get information about basic user with respectively pin code
                        // from database
                        BasicUserPanelVM basicUserPanelVM = new BasicUserPanelVM
                        {
                            basicUser = mockBasicUsersRepository.GetAll().FirstOrDefault(
                                (singleBasicUser) => singleBasicUser._Pin._Value == pinCode._Value)
                        };

                        // Check basic user's find result
                        if (basicUserPanelVM.basicUser != null)
                        {
                            // Redirect to Basic User Panel
                            basicUserPanelVM.loginPanel = this;

                            BasicUserPanel basicUserPanel = new BasicUserPanel(basicUserPanelVM);

                            this.PinCodeTextBox.Clear();
                            this.ErrorLabel.Hide();
                            basicUserPanel.Show();
                            this.Hide();
                        }
                        else
                        {
                            ErrorLabel.Text = "!!! Użytkownik O Podanym Pinie Nie Istnieje !!!";
                            ErrorLabel.Show();
                        }
                    }
                    catch (MockBasicUsersRepository_Exception mbur_e)
                    {
                        ErrorLabel.Text = mbur_e.What();
                        ErrorLabel.Show();
                    }
                }
                // Login administrator
                else if (pinCode._Value.Length == 6)
                {
                    try
                    {
                        // Connect with administrators database
                        MockAdministratorsRepository mockAdministratorsRepository =
                            new MockAdministratorsRepository(SystemSettings._PlatformType);

                        // Get information about administrator with respectively pin code
                        // from database
                        AdministratorPanelVM administratorPanelVM = new AdministratorPanelVM
                        {
                            administrator = mockAdministratorsRepository.GetAll().
                                            FirstOrDefault((singleAdministrator) =>
                                                           singleAdministrator._Pin._Value == pinCode._Value)
                        };

                        // Check administrator's find result
                        if (administratorPanelVM.administrator != null)
                        {
                            // Redirect to administrator panel
                            administratorPanelVM.loginPanel = this;

                            AdministratorPanel administratorPanel =
                                new AdministratorPanel(administratorPanelVM);

                            this.PinCodeTextBox.Clear();
                            this.ErrorLabel.Hide();
                            administratorPanel.Show();
                            this.Hide();
                        }
                        else
                        {
                            ErrorLabel.Text = "!!! Użytkownik O Podanym Pinie Nie Istnieje !!!";
                            ErrorLabel.Show();
                        }
                    }
                    catch (MockAdministratorsRepository_Exception mar_e)
                    {
                        ErrorLabel.Text = mar_e.What();
                        ErrorLabel.Show();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        MockAdministratorsRepository_When_Find_Administrator_By_Pin(
            string[] administratorsData, string pin, string expected)
        {
            string result = "OK";

            //arrange
            MockAdministratorsRepository mockAdministratorsRepository = null;
            Administrator administrator = null;

            var insertAdministrators = new List <string[]>();


            //Convert administrators data
            foreach (var administratorData in administratorsData)
            {
                insertAdministrators.Add(
                    administratorData.Split(';'));
            }

            //Save administrators data
            using (StreamWriter sw = new StreamWriter(
                       (cashDispenserLibraryTestSettings._SystemSettings
                        == PlatformType.Windows)
                    ? "cashDispenserDatabase\\Administrators.txt"
                    : "cashDispenserDatabase/Administrators.txt", false))
            {
                foreach (var administratorData in administratorsData)
                {
                    sw.WriteLine(administratorData);
                }
            }

            //act

            //Connect with database
            try
            {
                mockAdministratorsRepository =
                    new MockAdministratorsRepository(
                        cashDispenserLibraryTestSettings._SystemSettings);
            }
            catch (MockAdministratorsRepository_Exception mar_e)
            {
                result = mar_e.What();
            }

            //Find administrator by pin number
            if (result.Equals("OK"))
            {
                try
                {
                    administrator =
                        mockAdministratorsRepository.GetAll().FirstOrDefault(
                            (singleAdministrator) =>
                            singleAdministrator._Pin._Value.Equals(pin));

                    if (administrator == null)
                    {
                        result = "!!! Administrator with it pin does not exist !!!";
                    }
                }
                catch (MockAdministratorsRepository_Exception mar_e)
                {
                    result = mar_e.What();
                }

                // Check received administrator information
                if (result.Equals("OK"))
                {
                    var insertAdministratorWithPin =
                        insertAdministrators.FirstOrDefault(
                            (insertAdministrator) =>
                            insertAdministrator[1].Equals(pin));

                    if (((insertAdministratorWithPin[0].Equals(
                              administrator._Id.ToString())) == false) ||
                        ((insertAdministratorWithPin[1].Equals(
                              administrator._Pin._Value)) == false) ||
                        ((insertAdministratorWithPin[2].Equals(
                              administrator._Name._Value)) == false) ||
                        ((insertAdministratorWithPin[3].Equals(
                              administrator._Surname._Value)) == false))
                    {
                        result = "!!! Bad receive administrator's information !!!";
                    }
                }
            }

            //assert
            Assert.AreEqual(expected: expected, actual: result);
        }