Inheritance: IEntity, IDeletable, IHaveEmail
        public void CanReadAndSavePersonWithCats()
        {
            int personid;
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    // create a couple of Cats each with connected to Person
                    var person = new Person { Name = new Name { First = "Olo", Last = "Bolus" } };
                    session.Save(person);
                    personid = person.Id;
                    Console.WriteLine(person.Id);
                    person.AddCat(new Cat { Name = "Filip" });
                    person.AddCat(new Cat { Name = "Nick" });
                   
                    session.Save(person);
                    transaction.Commit();
                }
			}
			using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
					 var dbPerson = session.Get<Person>(personid);
					Assert.AreEqual(2, dbPerson.Cats.Count);
				}
            }
        }
        public void CanReadAndSavePerson()
        {
            factory = new SessionProvider().Factory;
            int personId;
			using (var session = factory.OpenSession())
			{
				using (var transaction = session.BeginTransaction())
				{
					var person = new Person { Name = new Name { First = "Olo", Last = "Bolus" } };
					var cat = new Cat { Name = "Filip" };
					session.Save(cat);
					session.Save(person);
					transaction.Commit();
					personId = person.Id;
				}
			}
            using (var session = factory.OpenSession())
            {
                using (session.BeginTransaction())
                {
                    var person = (from p in ((IOrderedQueryable<Person>)session.Linq<Person>()) where p.Id == personId select  p).First()  ;
                    Assert.That(person.Name.First,Is.EqualTo("Olo"));
                }
            }
        }
        public void CanReadAndSavePerson()
        {
            int personId;
            using (var session = GetSession())
            {
                
                
                using (var transaction = session.BeginTransaction())
                {
                    
                    // create a couple of Stores each with some Products and Employees
                    var person = new Person { Name = new Name { First = "Olo", Last = "Bolus" } };
                    session.SaveOrUpdate(person);
                    transaction.Commit();
                    personId = person.Id;
                    session.Evict(person);
                    //session.Linq<Person>().Where(p=>p.Id==1);
                }

                using (session.BeginTransaction())
                {
                    var query=(from user in session.Linq<Person>() select user );

                    var person = query.First<Person>();
                    //Assert.AreEqual("Olo", person.FirstName);
                    //Assert.AreEqual("Bolus", person.LastName);


                }
               
            }
            using (var session = GetSession())
            {
                

                using (var transaction = session.BeginTransaction())
                {
                    // create a couple of Stores each with some Products and Employees
                    var person = new Person { Name = new Name { First = "Olo", Last = "Bolus" } };
                    session.SaveOrUpdate(person);
                    transaction.Commit();
                    personId = person.Id;
                    session.Evict(person);
                    //session.Linq<Person>().Where(p=>p.Id==1);
                }

                using (session.BeginTransaction())
                {
                    var query = (from user in session.Linq<Person>() where user.Name.First == "Bolus1" select user);

                    var person = query.First<Person>();
                  
                    Assert.AreEqual("Olo1", person.Name.First);
                    Assert.AreEqual("Bolus1", person.Name.Last);
                }

            }

        }
        public void FuturesTest()
        {
            int personid;
			using (var session = factory.OpenSession())
			{
				using (var transaction = session.BeginTransaction())
				{
					var person = new Person { Name = new Name { First = "Olo", Last = "Bolus" } };
					Console.WriteLine(person.Id);
					person.AddCat(new Cat { Name = "Filip" });
					person.AddCat(new Cat { Name = "Nick" });
					session.Save(person);
					personid = person.Id;
					transaction.Commit();
				}
			}
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var dbPerson = session.CreateCriteria<Person>().
						Add(Expression.Eq("Id", personid)).
						SetFetchMode("Cats", FetchMode.Join).
						Future<Person>();
                    var catscount = session.CreateCriteria<Cat>()
						.SetProjection(Projections.Count(Projections.Id()))
						.FutureValue<int>();
                    transaction.Commit();
					Assert.AreEqual(2, dbPerson.First<Person>().Cats.Count);
					Assert.AreEqual(2, catscount.Value);
                }
            }
        }
 public void CanReadAndSavePersonWithTwoSessions()
 {
     int personid;
     Person dbPerson;
     using (var session = factory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             var person = new Person { Name = new Name { First = "Olo", Last = "Bolus" } };
             personid = person.Id;
             Console.WriteLine(person.Id);
             person.AddCat(new Cat { Name = "Filip" });
             person.AddCat(new Cat { Name = "Nick" });
             person.AddCat(new Cat { Name = "Cage" });
             session.Save(person);
             transaction.Commit();
             personid = person.Id;
         }
         
         dbPerson = session.Get<Person>(personid);
         Assert.AreEqual(3, dbPerson.Cats.Count);
     }
     dbPerson.Name.Last = "New Name";
     using (var session = factory.OpenSession())
     {
         using (var transaction = session.BeginTransaction())
         {
             session.Update(dbPerson);
             transaction.Commit();
         }
         var dbPerson2 = session.Get<Person>(personid);
         Assert.AreEqual(3, dbPerson2.Cats.Count);
         Assert.That(dbPerson2.Name.Last,Is.EqualTo("New Name"));
     }
 }
Exemplo n.º 6
0
 public void Save(Person person)
 {
     throw new NotImplementedException();
 }