コード例 #1
0
        public void ComponentAttribute()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(),
                                           typeof(Company),
                                           typeof(Client),
                                           typeof(Firm),
                                           typeof(Person),
                                           typeof(Post),
                                           typeof(Blog));
            Recreate();

            Company.DeleteAll();

            Company company = new Company("Castle Corp.");
            company.Address = new PostalAddress(
                "Embau St., 102", "Sao Paulo", "SP", "040390-060");
            company.Save();

            Company[] companies = Company.FindAll();
            Assert.IsNotNull(companies);
            Assert.AreEqual(1, companies.Length);

            Company corp = companies[0];
            Assert.IsNotNull(corp.Address);
            Assert.AreEqual(corp.Address.Address, company.Address.Address);
            Assert.AreEqual(corp.Address.City, company.Address.City);
            Assert.AreEqual(corp.Address.State, company.Address.State);
            Assert.AreEqual(corp.Address.ZipCode, company.Address.ZipCode);
        }
コード例 #2
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 );
		}
コード例 #3
0
        public void InvalidSessionCache()
        {
            ActiveRecordStarter.Initialize( GetConfigSource(),
                typeof(Company), typeof(Client), typeof(Firm), typeof(Person) );
            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();
            }

            using(new SessionScope())
            {
                try
                {
                    Client c = Client.Find( firm.Id );

                    Assert.Fail("Exception was expected");
                }
                catch(Exception)
                {
                    // Phew!!
                }

                Firm firm2 = Firm.Find( firm.Id );

                Assert.IsNotNull(firm2);
            }
        }