Ejemplo n.º 1
0
			public void Prepare()
			{
				ISession s = tc.OpenNewSession();
				ITransaction txn = s.BeginTransaction();

				Polliwog = new Animal {BodyWeight = 12, Description = "Polliwog"};

				Catepillar = new Animal {BodyWeight = 10, Description = "Catepillar"};

				Frog = new Animal {BodyWeight = 34, Description = "Frog"};

				Polliwog.Father = Frog;
				Frog.AddOffspring(Polliwog);

				Butterfly = new Animal {BodyWeight = 9, Description = "Butterfly"};

				Catepillar.Mother = Butterfly;
				Butterfly.AddOffspring(Catepillar);

				s.Save(Frog);
				s.Save(Polliwog);
				s.Save(Butterfly);
				s.Save(Catepillar);

				var dog = new Dog {BodyWeight = 200, Description = "dog"};
				s.Save(dog);

				var cat = new Cat {BodyWeight = 100, Description = "cat"};
				s.Save(cat);

				Zoo = new Zoo {Name = "Zoo"};
				var add = new Address {City = "MEL", Country = "AU", Street = "Main st", PostalCode = "3000"};
				Zoo.Address = add;

				PettingZoo = new PettingZoo {Name = "Petting Zoo"};
				var addr = new Address {City = "Sydney", Country = "AU", Street = "High st", PostalCode = "2000"};
				PettingZoo.Address = addr;

				s.Save(Zoo);
				s.Save(PettingZoo);

				var joiner = new Joiner {JoinedName = "joined-name", Name = "name"};
				s.Save(joiner);

				var car = new Car {Vin = "123c", Owner = "Kirsten"};
				s.Save(car);

				var truck = new Truck {Vin = "123t", Owner = "Steve"};
				s.Save(truck);

				var suv = new SUV {Vin = "123s", Owner = "Joe"};
				s.Save(suv);

				var pickup = new Pickup {Vin = "123p", Owner = "Cecelia"};
				s.Save(pickup);

				var b = new BooleanLiteralEntity();
				s.Save(b);

				txn.Commit();
				s.Close();
			}
Ejemplo n.º 2
0
		public void InsertWithGeneratedId()
		{
			// Make sure the env supports bulk inserts with generated ids...
			IEntityPersister persister = sessions.GetEntityPersister(typeof (PettingZoo).FullName);
			IIdentifierGenerator generator = persister.IdentifierGenerator;
			if (!HqlSqlWalker.SupportsIdGenWithBulkInsertion(generator))
			{
				return;
			}

			// create a Zoo
			var zoo = new Zoo {Name = "zoo"};

			ISession s = OpenSession();
			ITransaction t = s.BeginTransaction();
			s.Save(zoo);
			t.Commit();
			s.Close();

			s = OpenSession();
			t = s.BeginTransaction();
			int count = s.CreateQuery("insert into PettingZoo (name) select name from Zoo").ExecuteUpdate();
			t.Commit();
			s.Close();
			Assert.That(count, Is.EqualTo(1), "unexpected insertion count");

			s = OpenSession();
			t = s.BeginTransaction();
			var pz = (PettingZoo) s.CreateQuery("from PettingZoo").UniqueResult();
			t.Commit();
			s.Close();

			Assert.That(zoo.Name, Is.EqualTo(pz.Name));
			Assert.That(zoo.Id != pz.Id);

			s = OpenSession();
			t = s.BeginTransaction();
			s.CreateQuery("delete Zoo").ExecuteUpdate();
			t.Commit();
			s.Close();
		}
Ejemplo n.º 3
0
			public void Prepare()
			{
				using (ISession session = tc.OpenNewSession())
				using (ITransaction txn = session.BeginTransaction())
				{
					_stateProvince = new StateProvince {Name = "IL"};

					_zoo1 = new Zoo
					{
						Name = "Zoo",
						Address = new Address
						{
							Street = "1313 Mockingbird Lane",
							City = "Anywhere",
							StateProvince = StateProvince,
							Country = "USA"
						},
						Mammals = new Dictionary<string, Mammal>()
					};

					_zooMammal1 = new Mammal {Description = "zooMammal1", Zoo = Zoo1};
					Zoo1.Mammals.Add("type1", ZooMammal1);

					_zooMammal2 = new Mammal {Description = "zooMammal2", Zoo = Zoo1};
					Zoo1.Mammals.Add("type2", ZooMammal2);

					_zoo2 = new Zoo
					{
						Name = "A Zoo",
						Address = new Address
						{
							Street = "1313 Mockingbird Lane",
							City = "Anywhere",
							StateProvince = StateProvince,
							Country = "USA"
						}
					};

					_zoo3 = new Zoo
					{
						Name = "Zoo",
						Address = new Address
						{
							Street = "1312 Mockingbird Lane",
							City = "Anywhere",
							StateProvince = StateProvince,
							Country = "USA"
						}
					};

					_zoo4 = new Zoo
					{
						Name = "Duh Zoo",
						Address = new Address
						{
							Street = "1312 Mockingbird Lane",
							City = "Nowhere",
							StateProvince = StateProvince,
							Country = "USA"
						}
					};

					session.Save(StateProvince);
					session.Save(ZooMammal1);
					session.Save(ZooMammal2);
					session.Save(Zoo1);
					session.Save(Zoo2);
					session.Save(Zoo3);
					session.Save(Zoo4);

					txn.Commit();
				}

				_zoosWithSameName = new HashSet<Zoo>();
				ZoosWithSameName.Add(Zoo1);
				ZoosWithSameName.Add(Zoo3);

				_zoosWithSameAddress = new HashSet<Zoo>();
				ZoosWithSameAddress.Add(Zoo1);
				ZoosWithSameAddress.Add(Zoo2);
			}
Ejemplo n.º 4
0
            public void Prepare()
            {
                ISession     s   = tc.OpenNewSession();
                ITransaction txn = s.BeginTransaction();

                Polliwog = new Animal {
                    BodyWeight = 12, Description = "Polliwog"
                };

                Catepillar = new Animal {
                    BodyWeight = 10, Description = "Catepillar"
                };

                Frog = new Animal {
                    BodyWeight = 34, Description = "Frog"
                };

                Polliwog.Father = Frog;
                Frog.AddOffspring(Polliwog);

                Butterfly = new Animal {
                    BodyWeight = 9, Description = "Butterfly"
                };

                Catepillar.Mother = Butterfly;
                Butterfly.AddOffspring(Catepillar);

                s.Save(Frog);
                s.Save(Polliwog);
                s.Save(Butterfly);
                s.Save(Catepillar);

                var dog = new Dog {
                    BodyWeight = 200, Description = "dog"
                };

                s.Save(dog);

                var cat = new Cat {
                    BodyWeight = 100, Description = "cat"
                };

                s.Save(cat);

                Zoo = new Zoo {
                    Name = "Zoo"
                };
                var add = new Address {
                    City = "MEL", Country = "AU", Street = "Main st", PostalCode = "3000"
                };

                Zoo.Address = add;

                PettingZoo = new PettingZoo {
                    Name = "Petting Zoo"
                };
                var addr = new Address {
                    City = "Sydney", Country = "AU", Street = "High st", PostalCode = "2000"
                };

                PettingZoo.Address = addr;

                s.Save(Zoo);
                s.Save(PettingZoo);

                var joiner = new Joiner {
                    JoinedName = "joined-name", Name = "name"
                };

                s.Save(joiner);

                var car = new Car {
                    Vin = "123c", Owner = "Kirsten"
                };

                s.Save(car);

                var truck = new Truck {
                    Vin = "123t", Owner = "Steve"
                };

                s.Save(truck);

                var suv = new SUV {
                    Vin = "123s", Owner = "Joe"
                };

                s.Save(suv);

                var pickup = new Pickup {
                    Vin = "123p", Owner = "Cecelia"
                };

                s.Save(pickup);

                var b = new BooleanLiteralEntity();

                s.Save(b);

                txn.Commit();
                s.Close();
            }
Ejemplo n.º 5
0
		private void CheckTestOrderByResult(object result,
											Zoo zooExpected,
											HashSet<Zoo> zoosUnordered)
		{

			Assert.IsInstanceOf<object[]>(result);
			var resultArray = (object[]) result;
			Assert.AreEqual(2, resultArray.Length);

			NHibernateUtil.Initialize(((Address) resultArray[1]).StateProvince);

			if (zooExpected == null)
			{
				Zoo zooResult = new Zoo();
				zooResult.Name = (string) resultArray[0];
				zooResult.Address = (Address) resultArray[1];
				Assert.IsTrue(zoosUnordered.Remove(zooResult));
			}
			else
			{
				Assert.AreEqual(zooExpected.Name, resultArray[0]);
				Assert.AreEqual(zooExpected.Address, resultArray[1]);
			}
		}
Ejemplo n.º 6
0
		private void CheckTestOrderByResults(IList results,
											 Zoo zoo1,
											 Zoo zoo2,
											 Zoo zoo3,
											 Zoo zoo4,
											 HashSet<Zoo> zoosUnordered)
		{
			Assert.AreEqual(4, results.Count);
			HashSet<Zoo> zoosUnorderedCopy = (zoosUnordered == null ? null : new HashSet<Zoo>(zoosUnordered));
			CheckTestOrderByResult(results[0], zoo1, zoosUnorderedCopy);
			CheckTestOrderByResult(results[1], zoo2, zoosUnorderedCopy);
			CheckTestOrderByResult(results[2], zoo3, zoosUnorderedCopy);
			CheckTestOrderByResult(results[3], zoo4, zoosUnorderedCopy);
			if (zoosUnorderedCopy != null)
			{
				Assert.IsTrue(!zoosUnorderedCopy.Any());
			}
		}
Ejemplo n.º 7
0
            public async Task PrepareAsync(CancellationToken cancellationToken = default(CancellationToken))
            {
                ISession     s   = tc.OpenNewSession();
                ITransaction txn = s.BeginTransaction();

                Polliwog = new Animal {
                    BodyWeight = 12, Description = "Polliwog"
                };

                Catepillar = new Animal {
                    BodyWeight = 10, Description = "Catepillar"
                };

                Frog = new Animal {
                    BodyWeight = 34, Description = "Frog"
                };

                Polliwog.Father = Frog;
                Frog.AddOffspring(Polliwog);

                Butterfly = new Animal {
                    BodyWeight = 9, Description = "Butterfly"
                };

                Catepillar.Mother = Butterfly;
                Butterfly.AddOffspring(Catepillar);

                await(s.SaveAsync(Frog, cancellationToken));
                await(s.SaveAsync(Polliwog, cancellationToken));
                await(s.SaveAsync(Butterfly, cancellationToken));
                await(s.SaveAsync(Catepillar, cancellationToken));

                var dog = new Dog {
                    BodyWeight = 200, Description = "dog"
                };

                await(s.SaveAsync(dog, cancellationToken));

                var cat = new Cat {
                    BodyWeight = 100, Description = "cat"
                };

                await(s.SaveAsync(cat, cancellationToken));

                Zoo = new Zoo {
                    Name = "Zoo"
                };
                var add = new Address {
                    City = "MEL", Country = "AU", Street = "Main st", PostalCode = "3000"
                };

                Zoo.Address = add;

                PettingZoo = new PettingZoo {
                    Name = "Petting Zoo"
                };
                var addr = new Address {
                    City = "Sydney", Country = "AU", Street = "High st", PostalCode = "2000"
                };

                PettingZoo.Address = addr;

                await(s.SaveAsync(Zoo, cancellationToken));
                await(s.SaveAsync(PettingZoo, cancellationToken));

                var joiner = new Joiner {
                    JoinedName = "joined-name", Name = "name"
                };

                await(s.SaveAsync(joiner, cancellationToken));

                var car = new Car {
                    Vin = "123c", Owner = "Kirsten"
                };

                await(s.SaveAsync(car, cancellationToken));

                var truck = new Truck {
                    Vin = "123t", Owner = "Steve"
                };

                await(s.SaveAsync(truck, cancellationToken));

                var suv = new SUV {
                    Vin = "123s", Owner = "Joe"
                };

                await(s.SaveAsync(suv, cancellationToken));

                var pickup = new Pickup {
                    Vin = "123p", Owner = "Cecelia"
                };

                await(s.SaveAsync(pickup, cancellationToken));

                var b = new BooleanLiteralEntity();

                await(s.SaveAsync(b, cancellationToken));

                await(txn.CommitAsync(cancellationToken));
                s.Close();
            }
Ejemplo n.º 8
0
            public void Prepare()
            {
                using (ISession session = tc.OpenNewSession())
                    using (ITransaction txn = session.BeginTransaction())
                    {
                        _stateProvince = new StateProvince {
                            Name = "IL"
                        };

                        _zoo1 = new Zoo
                        {
                            Name    = "Zoo",
                            Address = new Address
                            {
                                Street        = "1313 Mockingbird Lane",
                                City          = "Anywhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            },
                            Mammals = new Dictionary <string, Mammal>()
                        };

                        _zooMammal1 = new Mammal {
                            Description = "zooMammal1", Zoo = Zoo1
                        };
                        Zoo1.Mammals.Add("type1", ZooMammal1);

                        _zooMammal2 = new Mammal {
                            Description = "zooMammal2", Zoo = Zoo1
                        };
                        Zoo1.Mammals.Add("type2", ZooMammal2);

                        _zoo2 = new Zoo
                        {
                            Name    = "A Zoo",
                            Address = new Address
                            {
                                Street        = "1313 Mockingbird Lane",
                                City          = "Anywhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            }
                        };

                        _zoo3 = new Zoo
                        {
                            Name    = "Zoo",
                            Address = new Address
                            {
                                Street        = "1312 Mockingbird Lane",
                                City          = "Anywhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            }
                        };

                        _zoo4 = new Zoo
                        {
                            Name    = "Duh Zoo",
                            Address = new Address
                            {
                                Street        = "1312 Mockingbird Lane",
                                City          = "Nowhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            }
                        };

                        session.Save(StateProvince);
                        session.Save(ZooMammal1);
                        session.Save(ZooMammal2);
                        session.Save(Zoo1);
                        session.Save(Zoo2);
                        session.Save(Zoo3);
                        session.Save(Zoo4);

                        txn.Commit();
                    }

                _zoosWithSameName = new HashSet <Zoo>();
                ZoosWithSameName.Add(Zoo1);
                ZoosWithSameName.Add(Zoo3);

                _zoosWithSameAddress = new HashSet <Zoo>();
                ZoosWithSameAddress.Add(Zoo1);
                ZoosWithSameAddress.Add(Zoo2);
            }
Ejemplo n.º 9
0
            public async Task PrepareAsync(CancellationToken cancellationToken = default(CancellationToken))
            {
                using (ISession session = tc.OpenNewSession())
                    using (ITransaction txn = session.BeginTransaction())
                    {
                        _stateProvince = new StateProvince {
                            Name = "IL"
                        };

                        _zoo1 = new Zoo
                        {
                            Name    = "Zoo",
                            Address = new Address
                            {
                                Street        = "1313 Mockingbird Lane",
                                City          = "Anywhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            },
                            Mammals = new Dictionary <string, Mammal>()
                        };

                        _zooMammal1 = new Mammal {
                            Description = "zooMammal1", Zoo = Zoo1
                        };
                        Zoo1.Mammals.Add("type1", ZooMammal1);

                        _zooMammal2 = new Mammal {
                            Description = "zooMammal2", Zoo = Zoo1
                        };
                        Zoo1.Mammals.Add("type2", ZooMammal2);

                        _zoo2 = new Zoo
                        {
                            Name    = "A Zoo",
                            Address = new Address
                            {
                                Street        = "1313 Mockingbird Lane",
                                City          = "Anywhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            }
                        };

                        _zoo3 = new Zoo
                        {
                            Name    = "Zoo",
                            Address = new Address
                            {
                                Street        = "1312 Mockingbird Lane",
                                City          = "Anywhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            }
                        };

                        _zoo4 = new Zoo
                        {
                            Name    = "Duh Zoo",
                            Address = new Address
                            {
                                Street        = "1312 Mockingbird Lane",
                                City          = "Nowhere",
                                StateProvince = StateProvince,
                                Country       = "USA"
                            }
                        };

                        await(session.SaveAsync(StateProvince, cancellationToken));
                        await(session.SaveAsync(ZooMammal1, cancellationToken));
                        await(session.SaveAsync(ZooMammal2, cancellationToken));
                        await(session.SaveAsync(Zoo1, cancellationToken));
                        await(session.SaveAsync(Zoo2, cancellationToken));
                        await(session.SaveAsync(Zoo3, cancellationToken));
                        await(session.SaveAsync(Zoo4, cancellationToken));

                        await(txn.CommitAsync(cancellationToken));
                    }

                _zoosWithSameName = new HashSet <Zoo>();
                ZoosWithSameName.Add(Zoo1);
                ZoosWithSameName.Add(Zoo3);

                _zoosWithSameAddress = new HashSet <Zoo>();
                ZoosWithSameAddress.Add(Zoo1);
                ZoosWithSameAddress.Add(Zoo2);
            }