Beispiel #1
0
		private bool EmployeesAreEqual(Employee x, Employee y)
		{
			if (!PersonsAreEqual(x, y)) return false;
			if (!string.Equals(x.Title, y.Title)) return false;
			if (x.Salary != y.Salary) return false;
			if (x.Meetings.Count != y.Meetings.Count) return false;
			if (x.Manager != null && y.Manager != null)
			{
				return x.Manager.Id == y.Manager.Id;
			}
			else if (x.Manager != null || y.Manager != null)
			{
				return false;
			}
			else // x.Manager and y.Manager are both null
			{
				return true;
			}
		}
Beispiel #2
0
		private Employee[] CreateAndInsertEmployees(ISession s, int count)
		{
			Employee[] result = new Employee[count];

			for (int i = 0; i < count; i++)
			{
				result[i] = CreateEmployee("Employee " + i.ToString(), "Title " + i.ToString());
				s.Save(result[i]);
			}

			s.Flush();
			s.Clear();

			return result;
		}
Beispiel #3
0
		public void TestSequentialSelects()
		{
			using (ISession s = OpenSession())
			using (ITransaction tx = s.BeginTransaction())
			{
				Employee mark = new Employee();
				mark.Name = "Mark";
				mark.Title = "internal sales";
				mark.Sex = 'M';
				mark.Address = "buckhead";
				mark.Zip = "30305";
				mark.Country = "USA";

				Customer joe = new Customer();
				joe.Name = "Joe";
				joe.Address = "San Francisco";
				joe.Zip = "54353";
				joe.Country = "USA";
				joe.Comments = "very demanding";
				joe.Sex = 'M';
				joe.Salesperson = mark;

				Person yomomma = new Person();
				yomomma.Name = "mom";
				yomomma.Sex = 'F';

				s.Save(yomomma);
				s.Save(mark);
				s.Save(joe);

				s.Flush();
				s.Clear();

				Person p = s.Get<Person>(yomomma.Id);
				Assert.AreEqual(yomomma.Name, p.Name);
				Assert.AreEqual(yomomma.Sex, p.Sex);
				s.Clear();

				// Copied from H3.  Don't really know what it is testing
				//Assert.AreEqual(0, s.CreateQuery("from System.Serializable").List().Count);

				Assert.AreEqual(3, s.CreateQuery("from Person").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Person p where p.class is null").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Person p where p.class = Customer").List().Count);
				Assert.AreEqual(1, s.CreateQuery("from Customer c").List().Count);
				s.Clear();

				IList customers = s.CreateQuery("from Customer c left join fetch c.Salesperson").List();
				foreach (Customer c in customers)
				{
					Assert.IsTrue(NHibernateUtil.IsInitialized(c.Salesperson));
					Assert.AreEqual("Mark", c.Salesperson.Name);
				}
				Assert.AreEqual(1, customers.Count);
				s.Clear();

				mark = (Employee) s.Get(typeof (Employee), mark.Id);
				joe = (Customer) s.Get(typeof (Customer), joe.Id);

				mark.Zip = "30306";
				s.Flush();
				s.Clear();
				Assert.AreEqual(1, s.CreateQuery("from Person p where p.Zip = '30306'").List().Count);

				tx.Commit();
			}
		}
Beispiel #4
0
		private Employee CreateEmployee(string name, string title)
		{
			Employee p = new Employee();
			p.Name = name;
			p.Sex = 'M';
			p.Address = "123 Some Street";
			p.Zip = "12345";
			p.Country = "Canada";
			p.HomePhone = "555-1234";
			p.BusinessPhone = "555-4321";

			p.Title = title;
			p.Salary = 100;
			p.Meetings.Add(new Meeting {Employee = p, Description = "salary definition"});
			p.Meetings.Add(new Meeting { Employee = p, Description = "targets definition" });
			return p;
		}