private void buttonAdd_Click(object sender, EventArgs e) { if (!CheckData()) { return; } CustomerBean c = new CustomerBean(); c.Name = customer; c.Phone = phone; c.Sex = sex; c.IdCard = idCard; c.Email = email; c.Address = address; c.Remark = remark; c.Age = age; MD5 md5 = MD5.Create(); byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(passwd)); c.Password = Convert.ToBase64String(s); c.Baby = student; c.BabyAge = age; c.Relation = relation; CustomerDAO dao = new CustomerDAO(); if (dao.FindCustomer(c) == false) { dao.AddCustomer(c); } }
public void RemoveOrder_ShouldDeleteOrderWithoutDeletingProductsOrCustomers() { // Arrange ProductDAO productDAO = new ProductDAO(); Product product1 = new Product("Fanta", 2.5m); Product product2 = new Product("Cola", 2.2m); CustomerDAO customerDAO = new CustomerDAO(); customerDAO.AddCustomer(new Customer("Jan Jansenss", "Straat 123")); Customer customer = customerDAO.GetCustomer(1); OrderDAO orderDAO = new OrderDAO(); DateTime dateTime = new DateTime(2020, 12, 05, 05, 05, 05); Order order = new Order(dateTime); order.SetCustomer(customer); order.AddProduct(product1, 1); order.AddProduct(product2, 3); order.IsPayed = true; orderDAO.AddOrder(order); // Act orderDAO.RemoveOrder(1); // Assert orderDAO.GetOrder(1).Should().BeNull(); productDAO.GetProduct(1).Should().NotBeNull(); productDAO.GetProduct(2).Should().NotBeNull(); customerDAO.GetCustomer(1).Should().NotBeNull(); }
public void AddOrder_ShouldAddOrderWithCustomer() { // Arrange CustomerDAO customerDAO = new CustomerDAO(); customerDAO.AddCustomer(new Customer("Jan Jansenss", "Straat 123")); Customer customer = customerDAO.GetCustomer(1); OrderDAO orderDAO = new OrderDAO(); DateTime dateTime = new DateTime(2020, 12, 05, 05, 05, 05); Order order = new Order(dateTime); order.IsPayed = true; order.SetCustomer(customer); // Act orderDAO.AddOrder(order); // Assert Order orderInDb = orderDAO.GetOrder(1); orderInDb.Should().BeOfType <Order>(); orderInDb.DateTime.Should().Be(dateTime); orderInDb.IsPayed.Should().Be(true); orderInDb.PriceAlreadyPayed.Should().Be(0); orderInDb.Id.Should().Be(1); orderInDb.Customer.Should().BeEquivalentTo(customer); }
/*private static P1Context _context; * public static void SetContext(P1Context context) * { * _context = context; * }*/ /// <summary> /// Creates a new entries in the Customers Table and UserAccounts Table for new Users /// </summary> /// <param name="Account"></param> public static void RegisterAccount(UserAccount Account, Customer c, P1Context _context) { var DB = _context; CustomerDAO.AddCustomer(c, DB); Account.Customer = c; UserAccountDAO.AddUserAccount(Account, DB); }
/// <summary> /// Creates a new entries in the Customers Table and UserAccounts Table for new Users /// </summary> /// <param name="Account"></param> public static void RegisterAccount(UserAccount Account, Customer c) { using (var DB = new P0Context()) { CustomerDAO.AddCustomer(c, DB); Account.Customer = c; UserAccountDAO.AddUserAccount(Account, DB); } }
public void GetCustomer_ShouldReturnCorrectCustomer() { // Arrange CustomerDAO customerDAO = new CustomerDAO(); Customer customer1 = new Customer("Jan Janssens", "Vrijdagsmarkt 100 9000 Gent"); customerDAO.AddCustomer(customer1); Customer customer2 = new Customer("Bob Janssens", "Langestraat 56 8000 Kortrijk"); customerDAO.AddCustomer(customer2); // Act Customer customerInDb = customerDAO.GetCustomer(1); // Assert customerInDb.Name.Should().Be("Jan Janssens"); customerInDb.Address.Should().Be("Vrijdagsmarkt 100 9000 Gent"); customerInDb.Id.Should().Be(1); customerInDb.Should().NotBeEquivalentTo(customer2); }
//thêm khách hàng mới void AddCus() { string cusName = (string)Request.Form["name"]; string address = (string)Request.Form["address"]; string note = (string)Request.Form["note"]; string phone = (string)Request.Form["phone"]; cdao = new CustomerDAO(); cdao.AddCustomer(cusName, address, phone, note); Session["listCustomer"] = cdao.GetCustomer(""); }
public void GetAllCustomers_ShouldReturnAllCustomers() { // Arrange CustomerDAO customerDAO = new CustomerDAO(); Customer customer1 = new Customer("Jan Janssens", "Vrijdagsmarkt 100 9000 Gent"); customerDAO.AddCustomer(customer1); Customer customer2 = new Customer("Bob Janssens", "Langestraat 56 8000 Kortrijk"); customerDAO.AddCustomer(customer2); Customer customer3 = new Customer("Daan Janssens", "Zeedijk 5 Blankeberge"); customerDAO.AddCustomer(customer3); // Act IReadOnlyList <Customer> customers = customerDAO.GetAllCustomers(); // Assert customers.Count.Should().Be(3); customers.First().Name.Should().Be("Jan Janssens"); customers.First().Address.Should().Be("Vrijdagsmarkt 100 9000 Gent"); }
public void RemoveCustomer_ShouldDeleteCustomerInDb_IfCustomerExists() { // Arrange CustomerDAO customerDAO = new CustomerDAO(); Customer customer = new Customer("Jan Janssens", "Vrijdagsmarkt 100 9000 Gent"); customerDAO.AddCustomer(customer); // Act customerDAO.RemoveCustomer(1); // Assert customerDAO.GetCustomer(1).Should().BeNull(); }
public void TestUpdateCustomer() { if (customerDAO.GetCustomerById(2) == null) { customerDAO.AddCustomer(c2); } //delete custumer with id 1 customerDAO.UpdateCustomer(2, c5); //check that it doesnt exist Assert.AreEqual(customerDAO.GetCustomerById(11).Id, c5.Id); // update it back to what it was before customerDAO.UpdateCustomer(11, c2); }
//###################### END OF ORDER FUNCTIONS #################### //###################### END OF ORDER FUNCTIONS #################### //##################### CUSTOMER FUNCTIONS ######################### //##################### CUSTOMER FUNCTIONS ######################### #region CUSTOMER_FUNCTIONS public bool AddCustomer(Customer customer) { CustomerDAO dao = daoFactory.GetCustomerDAO(); try { return(dao.AddCustomer(customer)); } catch (DatabaseException ex) { throw ex; } catch (Exception ex) { throw ex; } }
public void AddCustomer_ShouldAddCustomer() { // Arrange CustomerDAO customerDAO = new CustomerDAO(); Customer customer = new Customer("Jan Janssens", "Vrijdagsmarkt 100 9000 Gent"); // Act customerDAO.AddCustomer(customer); // Assert Customer customerInDb = customerDAO.GetCustomer(1); customerInDb.Should().BeOfType <Customer>(); customerInDb.Name.Should().Be("Jan Janssens"); customerInDb.Address.Should().Be("Vrijdagsmarkt 100 9000 Gent"); customerInDb.Id.Should().Be(1); }
public void AddOrder_ShouldAddOrderWithProducts() { // Arrange Product product1 = new Product("Fanta", 2.5m); Product product2 = new Product("Cola", 2.2m); Product product3 = new Product("Hamburger", 8m); CustomerDAO customerDAO = new CustomerDAO(); customerDAO.AddCustomer(new Customer("Jan Jansenss", "Straat 123")); Customer customer = customerDAO.GetCustomer(1); OrderDAO orderDAO = new OrderDAO(); DateTime dateTime = new DateTime(2020, 12, 05, 05, 05, 05); Order order = new Order(dateTime); order.SetCustomer(customer); order.AddProduct(product1, 1); order.AddProduct(product3, 2); order.AddProduct(product2, 3); order.IsPayed = true; // Act orderDAO.AddOrder(order); // Assert Order orderInDb = orderDAO.GetOrder(1); orderInDb.Should().BeOfType <Order>(); orderInDb.DateTime.Should().Be(dateTime); orderInDb.IsPayed.Should().Be(true); orderInDb.PriceAlreadyPayed.Should().Be(25.10M); orderInDb.Id.Should().Be(1); orderInDb.Customer.Should().BeEquivalentTo(customer); orderInDb.GetProducts().Count.Should().Be(3); product1.SetId(1); orderInDb.GetProducts().First().Key.Should().BeEquivalentTo(product1); orderInDb.GetProducts().First().Value.Should().Be(1); }
public void AddNullCustomerException() { CustomerDAO dao = new CustomerDAO(); dao.AddCustomer(null); }