/// <summary> /// Removes temporary client from database. /// </summary> /// <param name="username">Name of client who should be deleted.</param> /// <remarks> Removes client from database to avoid conflicts in other tests.</remarks> protected void DeleteUserFromDatabase(string username) { var database = new DataClassesBettingParlorDataContext(); Player recentlyRegisteredPlayer = database.Players.SingleOrDefault(p => p.UserName == username); database.Players.DeleteOnSubmit(recentlyRegisteredPlayer); database.SubmitChanges(); }
public void RegisterNewPlayer_ThereIsNoUserWithSpecifiedNameInDatabase_NewAccountIsCreatedInDatabase() { var registrationResult = CreateUserinDatabase(); var database = new DataClassesBettingParlorDataContext(); //Search currently added player in database. Player recentlyRegisteredPlayer = database.Players.SingleOrDefault(p => p.UserName == username); //Assert Assert.IsNotNull(recentlyRegisteredPlayer); Assert.IsTrue(registrationResult); //Delete recently added player in database to avoid conflicts with further tests. DeleteUserFromDatabase(username); }
public void LogInToExistingAccount_UserWithSpecifiedNameIsNotRegistered_LoginFails() { //Arrange var login = new Login(); var randomStringGenerator = new RandomStringGenerator(); var formLogin = new FormLogin(); var database = new DataClassesBettingParlorDataContext(); var username = randomStringGenerator.GenerateRandomString(); var password = randomStringGenerator.GenerateRandomString(); //Action formLogin.textBoxUsername.Text = username; formLogin.textBoxPassword.Text = password; //Log in to account which not exists. var loginResult = login.LogInToExistingAccount(username, password, formLogin); //Assert Assert.IsFalse(loginResult); }
/// <summary> /// Creates temporary client in dataBase. /// </summary> /// <remarks> Used whenever client storted in database is needed.</remarks> protected bool CreateUserinDatabase() { //Arrange var login = new Login(); var randomStringGenerator = new RandomStringGenerator(); formLogin = new FormLogin(); var database = new DataClassesBettingParlorDataContext(); username = randomStringGenerator.GenerateRandomString(); password = randomStringGenerator.GenerateRandomString(); connectionId = randomStringGenerator.GenerateRandomString(); //Fill textBoxes on form to pass checkIfTextBoxesAreEmpty verification. formLogin.textBoxUsername.Text = username; formLogin.textBoxPassword.Text = password; //true if client is able to register, false if not. return(login.RegisterNewPlayer(username, password, formLogin)); }
public void AddCashToClientAccount_ClientTransfersCertainAmountOfCash_HisAccountBalanceIsUpdated() { //Arrange CreateUserinDatabase(); var moneyTransfer = 100M; var manageUserData = new ManageUserData(); var loadUserData = new LoadUserData(); var database = new DataClassesBettingParlorDataContext(); //Action //Add client to dictionary because all manageUserData methods relay on it. loadUserData.AddClientToList(connectionId, username); manageUserData.AddCashToClientAccount(connectionId, moneyTransfer); decimal accountBalanceAfterTransfer = database.Players.SingleOrDefault(p => p.UserName == username).CurrentAccountBalance; //Assert //New user is created so after transfer his accountBalance must equal the amount he transfered. Assert.AreEqual(moneyTransfer, accountBalanceAfterTransfer); //Delete recently added player in database to avoid conflicts with further tests. DeleteUserFromDatabase(username); }