Inheritance: ActiveRecordBase
Esempio n. 1
0
		public void ManyToMany()
		{
			ActiveRecordStarter.Initialize( GetConfigSource(), 
				typeof(Company), typeof(Client), typeof(Firm), typeof(Person),
				typeof(Blog), typeof(Post));
			Recreate();

			Company.DeleteAll();
			Client.DeleteAll();
			Firm.DeleteAll();
			Person.DeleteAll();

			Firm firm = new Firm("keldor");
			Client client = new Client("castle", firm);
			Company company = new Company("vs");

			using(new SessionScope())
			{
				firm.Save();
				client.Save();
				company.Save();

				Person person = new Person();
				person.Name = "hammett";

				person.Companies.Add( firm );
				person.Companies.Add( client );
				person.Companies.Add( company );
				person.Save();
			}

			company = Company.Find( company.Id );
			Assert.AreEqual(1, company.People.Count );
		}
Esempio n. 2
0
		public void JoinedTable()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), 
				typeof(Post), 
				typeof(Blog), 
				typeof(Company), 
				typeof(Person));

			Recreate();

			Post.DeleteAll();
			Blog.DeleteAll();
			Company.DeleteAll();
			Person.DeleteAll();

			Blog blog = new Blog();
			blog.Name = "Ronalodo's blog";
			blog.Author = "Christiano Ronalodo";
			blog.Save();

			Person person = new Person();
			person.Name = "Ronaldo";
			person.FullName = new FullName();
			person.FullName.First = "Christiano";
			person.FullName.Last = "Ronaldo";
			person.Address = "123 Nutmeg";
			person.City = "Lisbon";
			person.Blog = blog;
			person.Save();

			Person[] people = Person.FindAll();
			Assert.AreEqual( 1, people.Length );

			Person personLoaded = people[0];

			Assert.AreEqual(person.Name, personLoaded.Name);
			Assert.AreEqual(person.FullName.First, personLoaded.FullName.First);
			Assert.AreEqual(person.FullName.Last, personLoaded.FullName.Last);
			Assert.AreEqual(person.Address, personLoaded.Address);
			Assert.AreEqual(person.City, personLoaded.City);
			Assert.AreEqual(blog.Id, personLoaded.Blog.Id);
			Assert.AreEqual(blog.Name, personLoaded.Blog.Name);

			personLoaded.FullName.Middle = "Goal";
			personLoaded.Address = "200 Hatrick";
			personLoaded.Update();

			people = Person.FindAll();
			Assert.AreEqual(1, people.Length);

			Person personUpdated = people[0];
			Assert.AreEqual(personLoaded.FullName.Middle, personUpdated.FullName.Middle);
			Assert.AreEqual(personLoaded.Address, personUpdated.Address);
		}