public void MockBasicUsersRepository_When_Add( string[] basicUsersData, int basicUserId, string basicUserPin, string basicUserName, string basicUserSurname, decimal basicUserBankAccountValue, Currency basicUserBankAccountCurrency, string expected) { string result = "OK"; //Set id counter if (basicUsersData.Length > 0) { User._Id_counter = ((basicUsersData.Last()[0] - 48) + 1); } else { User._Id_counter = 0; } //arrange using (StreamWriter sw = new StreamWriter( (cashDispenserLibraryTestSettings._SystemSettings == PlatformType.Windows) ? "cashDispenserDatabase\\BasicUsers.txt" : "cashDispenserDatabase/BasicUsers.txt", false)) { foreach (var basicUserData in basicUsersData) { sw.WriteLine(basicUserData); } } //act //Connect with database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository( cashDispenserLibraryTestSettings._SystemSettings); try { mockBasicUsersRepository.Add(basicUser: new BasicUser( id: basicUserId, pin: new PinVAL(value: basicUserPin), name: new NameVAL(value: basicUserName), surname: new SurnameVAL(value: basicUserSurname), bankAccount: new BankAccount( state: new MoneyVAL( value: basicUserBankAccountValue, currency: basicUserBankAccountCurrency)))); } catch (MockBasicUsersRepository_Exception mbur_e) { result = mbur_e.What(); } if (result.Equals("OK")) { //Check add result BasicUser added_basicUser = null; try { if (basicUserId >= 0) { added_basicUser = mockBasicUsersRepository.Get( basicUserId: basicUserId); } else { added_basicUser = mockBasicUsersRepository.Get( basicUserId: (User._Id_counter - 1)); } } catch (MockBasicUsersRepository_Exception mbur_e) { result = mbur_e.What(); } if (result.Equals("OK")) { if ((((basicUserId >= 0) && (added_basicUser._Id != basicUserId)) || ((basicUserId < 0) && (added_basicUser._Id != (User._Id_counter - 1)))) || (!(added_basicUser._Pin._Value.Equals(basicUserPin))) || (!(added_basicUser._Name._Value.Equals(basicUserName))) || (!(added_basicUser._Surname._Value.Equals(basicUserSurname))) || (added_basicUser._BankAccount.state._Value != basicUserBankAccountValue) || (added_basicUser._BankAccount.state._Currency != basicUserBankAccountCurrency)) { result = "!!! Issue with get basic user !!!"; } } } //assert Assert.AreEqual(expected: expected, actual: result); }
private void AddBasicUserButton_Click(object sender, EventArgs e) { // Add new basic user try { // Get new basic user's informations string basicUserName = this.NameValueTextBox.Text; string basicUserSurname = this.SurnameValueTextBox.Text; string basicUserPin = this.PinValueTextBox.Text; // Connect with database MockBasicUsersRepository mockBasicUsersRepository = new MockBasicUsersRepository(SystemSettings._PlatformType); // Check pin in database if (mockBasicUsersRepository.GetAll().Any((singleBasicUser) => singleBasicUser._Pin._Value == basicUserPin) == true) { this.ErrorLabel.Show(); this.ErrorLabel.Text = "Użytkownik O Podanym Pinie Istnieje W Bazie"; throw new Exception(); } decimal basicUserAccountState = ((this.AccountStateValueTextBox.Text.Length > 0) ? decimal.Parse( this.AccountStateValueTextBox.Text.Replace(',', '.'), CultureInfo.InvariantCulture) : 0.0M); BasicUser basicUser = new BasicUser( id: -1, name: new NameVAL(value: basicUserName), pin: new PinVAL(value: basicUserPin), surname: new SurnameVAL(value: basicUserSurname), bankAccount: new BankAccount( state: new MoneyVAL(value: basicUserAccountState, currency: Currency.PLN))); // Add new basic user's record mockBasicUsersRepository.Add(basicUser: basicUser); // Show add new basic user result AdministratorAddBasicUserResultPanel administratorAddBasicUserResultPanel = new AdministratorAddBasicUserResultPanel(); administratorAddBasicUserResultPanel.ShowDialog(); this.Dispose(); } catch (NameVAL_Exception n_e) { this.ErrorLabel.Text = n_e.What(); this.ErrorLabel.Show(); } catch (SurnameVAL_Exception s_e) { this.ErrorLabel.Text = s_e.What(); this.ErrorLabel.Show(); } catch (PinVAL_Exception p_e) { this.ErrorLabel.Text = p_e.What(); this.ErrorLabel.Show(); } catch (BankAccount_Exception b_e) { this.ErrorLabel.Text = b_e.What(); this.ErrorLabel.Show(); } catch (MoneyVAL_Exception m_e) { this.ErrorLabel.Text = m_e.What(); this.ErrorLabel.Show(); } catch (Exception ex) { } }