public string CalculateClassification(Customer customer) { if (customer == null) { return null; } // we calculate based on customer's A alphabet cout (of course) int aCount = 0; foreach (char c in customer.CompanyName) { if (Char.ToLowerInvariant(c) == 'a') { aCount++; } } if (aCount > 4) { // great customer! return "A"; } if (aCount > 1) { // ok.. return "B"; } // a really lousy customer... return "C"; }
public void CustomerDaoTests() { Assert.AreEqual(91, customerDao.GetAll().Count); Customer c = new Customer(new DefaultCustomerClassificationCalculator()); c.Id = "MPOLL"; c.CompanyName = "Interface21"; customerDao.Save(c); c = customerDao.Get("MPOLL"); Assert.AreEqual(c.Id, "MPOLL"); Assert.AreEqual(c.CompanyName, "Interface21"); //Without flushing, nothing changes in the database: int customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers"); Assert.AreEqual(91, customerCount); //Flush the session to execute sql in the db. SessionFactoryUtils.GetSession(sessionFactory, true).Flush(); //Now changes are visible outside the session but within the same database transaction customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers"); Assert.AreEqual(92, customerCount); Assert.AreEqual(92, customerDao.GetAll().Count); c.CompanyName = "SpringSource"; customerDao.Update(c); c = customerDao.Get("MPOLL"); Assert.AreEqual(c.Id, "MPOLL"); Assert.AreEqual(c.CompanyName, "SpringSource"); customerDao.Delete(c); SessionFactoryUtils.GetSession(sessionFactory, true).Flush(); customerCount = (int)AdoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from Customers"); Assert.AreEqual(92, customerCount); try { c = customerDao.Get("MPOLL"); Assert.Fail("Should have thrown HibernateObjectRetrievalFailureException when finding customer with Id = MPOLL"); } catch (HibernateObjectRetrievalFailureException e) { Assert.AreEqual("Customer", e.PersistentClassName); } }
public Order(DateTime orderDate, DateTime requiredDate, DateTime shippedDate, decimal freight, string shipName, string shipAddress, string shipCity, string shipRegion, string shipPostalCode, string shipCountry, Customer customer, ICustomerClassificationCalculator calculator) { this.orderDate = orderDate; this.requiredDate = requiredDate; this.shippedDate = shippedDate; this.freight = freight; this.shipName = shipName; this.shipAddress = shipAddress; this.shipCity = shipCity; this.shipRegion = shipRegion; this.shipPostalCode = shipPostalCode; this.shipCountry = shipCountry; this.customer = customer; this.calculator = calculator; }
public void Delete(Customer customer) { CurrentSession.Delete(customer); }
public void Update(Customer customer) { CurrentSession.SaveOrUpdate(customer); }
public string Save(Customer customer) { return (string) CurrentSession.Save(customer); }