public void CustomerSaveTest() { Customer customer = new Customer("Ali"); customer.Email = "*****@*****.**"; Address address = new Address(); address.Street = "2534 Lorong 2 Taman India"; address.Postal = "12345"; address.State = "Melaka"; Stock stock = new Stock(3); Nisan nisan = new Nisan(stock); nisan.Name = "Ramli" + new System.Random().Next(100) + " bin Taib"; nisan.Death = RandomDate(); Order target = new Order(); target.Status = TransactionStage.Submit; //target.Agent = new Agent("W002"); target.Amount = stock.Price; target.Quantity = 1; target.Stock = nisan; target.ShipTo = address; target.Parent.CreatedBy = customer;//can be an agent Assert.IsTrue(target.Save()); }
public void LoadAllTest() { Stock target = new Stock(); int expected = 0; int actual = target.LoadAll().Count; Assert.AreNotEqual(expected, actual); }
/// <summary> /// Recommended constructor. Clone from stock object. /// </summary> /// <param name="stock"></param> public Nisan(Stock stock) : base(stock.Id) { Initialize(); Clone(stock); this.stockId = stock.Id; System.Diagnostics.Debug.WriteLine("-- Nisan --"); }
public void LoadTest() { Stock target = new Stock(1); target.Load(); Assert.IsTrue(target.Type.Length > 0); string expected = "2' Batu Batik(L)"; target = new Stock(expected); target.Load(); Assert.AreNotEqual(0, target.Id); Assert.AreEqual(expected, target.Type); }
public void SaveTest() { string name = "4½' Batu Marble(L)"; Stock target = new Stock(); target.Type = name; target.Price = 300; //target.Uri = new Uri("file://kiwi.jpg"); target.Uri = "kiwi.jpg"; target.Save(); Stock actual = new Stock(name); Assert.AreEqual(name, actual.Type); }
public void AgentSaveTest() { Address address = new Address(); address.Street = "1234 Lorong 2 Taman Bangla"; address.Postal = "12345"; address.State = "Pahang"; Stock stock = new Stock(3); Nisan nisan = new Nisan(stock); nisan.Name = "Che Som" + new System.Random().Next(100) + " bin Said"; nisan.Death = RandomDate(); Agent agent = new Agent("W002"); Order target = new Order(); target.Status = TransactionStage.Submit; target.Agent = agent; target.Amount = stock.Price; target.Quantity = 1; target.Stock = nisan; target.ShipTo = address; Assert.IsTrue(target.Save()); }
public List<Stock> LoadAll() { List<Stock> result = new List<Stock>(); using (DbConnection connection = factory.CreateConnection()) { connection.ConnectionString = this.connectionString; connection.Open(); using (DbCommand command = connection.CreateCommand()) { command.CommandType = System.Data.CommandType.Text; command.CommandText = "SELECT * FROM " + base.tableName; using (DbDataAdapter adapter = factory.CreateDataAdapter()) { DataSet dataSet = new DataSet(); adapter.SelectCommand = command; adapter.SelectCommand.Connection = connection; adapter.Fill(dataSet); if (dataSet.Tables.Count > 0) { foreach (DataRow row in dataSet.Tables[0].Rows) { Stock stock = new Stock(); stock.Id = (int)row["Id"]; stock.Type = row["Type"].ToString(); stock.Price = (decimal)row["Price"]; stock.Remarks = row["Remarks"].ToString(); stock.Uri = row["Uri"].ToString(); result.Add(stock); } } dataSet.Clear(); dataSet.Dispose(); } } connection.Close(); }//end return result; }
/// <summary> /// TODO: Why need this additional step? /// </summary> /// <param name="stock"></param> private void Clone(Stock stock) { base.Type = stock.Type; //base.remarksField = stock.Remarks; //base.uriField = stock.Uri; }
public void UpdateTest() { Stock expected = new Stock(3); expected.Price = 333; expected.Uri = "banana.jpg"; expected.Save(); Stock actual = new Stock(3); Assert.AreEqual(expected.Uri, actual.Uri); }
private void Submit() { stockId = Convert.ToInt32(ddlStock.SelectedValue); HLGranite.Nisan.Stock stock = new HLGranite.Nisan.Stock(stockId); Nisan nisan = new Nisan(stock); nisan.Name = txtName.Text.Trim(); nisan.Jawi = txtJawi.Text.Trim(); nisan.Death = ToDate(txtDeath.Text); nisan.Deathm = new DateTime(Convert.ToInt32(txtYear.Text), ddlMonth.SelectedIndex + 1, Convert.ToInt32(ddlDay.Text)); Order target = new Order(); target.Status = TransactionStage.Submit; if (user == null) { Customer customer = new Customer(); customer.Name = txtCustomer.Text; customer.Email = txtEmail.Text; customer.Phone = txtPhone.Text; target.Customer = customer; target.Parent.CreatedBy = customer; } else { if (txtCustomer.Text.Trim() != user.Name) { Customer customer = new Customer(); customer.Name = txtCustomer.Text; customer.Email = txtEmail.Text; customer.Phone = txtPhone.Text; target.Customer = customer; target.Parent.CreatedBy = customer; } else if (user is Agent) { target.Agent = (user as Agent); target.Parent.CreatedBy = (user as Agent); } } target.Amount = stock.Price; target.Quantity = 1; target.Stock = nisan; Address address = new Address(); address.Street = txtAddress.Text; address.Postal = txtPostal.Text; address.State = ddlState.Text; target.ShipTo = address; bool success = target.Save(); if (success) { lblMessage.Text = "Your order has been sent to us and we will contact you shortly."; EnableForm(false); } }