public async Task CreateContextAsync_Test() { // Arrange // Create EF database context using var context = db.NewDbContext <TestUserModule>(); // User 1001 var user1001 = new TestUserModule { Id = 1001, Name = "Admin 1" }; var user1002 = new TestUserModule { Id = 1002, Name = "Admin 2" }; // Act // Try to add two records if (await context.Entities !.FindAsync(user1001.Id) == null) { await context.Entities.AddAsync(user1001); } if (await context.Entities.FindAsync(user1002.Id) == null) { await context.Entities.AddAsync(user1002); } }
public async Task ExecuteReader_Test() { // Arrange using var connection = db.NewConnection(); var sql = "SELECT 1001 AS id, 'Admin 1' AS name, '1\n2\n3' AS friends"; // Act using var reader = await connection.ExecuteReaderAsync(sql); var users = await(TestUserModule.CreateAsync(reader)).ToListAsync(); // Assert Assert.IsTrue(users.Count == 1); Assert.IsTrue(users[0].Id == 1001); Assert.IsTrue(users[0].Friends?.Length == 3); }
public async Task CreateAsync_Test() { // Arrange var user = new TestUserModule { Id = 1021, Name = "Admin 1" }; // Act var result = await repo.CreateAsync(user); // Assert if (result.Ok) { Assert.AreEqual(1021, result.Data["Id"]); } }
protected void EncryptPassword(object sender, EventArgs e) { TestUserModule test = new TestUserModule(); string rawPassword = password.Text; string hash = test.encodePassword(rawPassword); encryptedPassword.Text = hash; //tells user if the pass matches the hash encryptedPassword.Text += "<br/>"; if (test.checkEncryptedPassword(rawPassword, hash)) { encryptedPassword.Text += "The password "+rawPassword+" and hash "+hash+" matches."; } else { encryptedPassword.Text += "The password " + rawPassword + " and hash " + hash + " doesn't match."; } }
protected void Test_Insert_UserAccount(object sender, EventArgs e) { TestUserModule test = new TestUserModule(); Session["userList"] = test.insertUserAccount(Convert.ToInt32(TestInsertUserAccount_NumberOfUsers_Textbox.Text)); InsertedUserTable.DataSource = Session["userList"]; InsertedUserTable.DataBind(); }
protected void TestLogin(object sender, EventArgs e) { TestUserModule test = new TestUserModule(); try { test.login(input_userid.Text, input_password.Text); login_message.Controls.Add(new LiteralControl( "<div class='alert alert-success col-sm-10 col-sm-offset-1'>" + "Login successful!" + "</div>")); } catch (LoginException lex) { login_message.Controls.Add(new LiteralControl( "<div class='alert alert-danger col-sm-10 col-sm-offset-1'>" + lex.Message + "</div>")); } catch (Exception ex) { login_message.Controls.Add(new LiteralControl( "<div class='alert alert-danger col-sm-10 col-sm-offset-1'>" + ex.Message + "</div>")); } }