public void CompanyFirmAndClient() { ActiveRecordStarter.Initialize( GetConfigSource(), typeof(Company), typeof(Client), typeof(Firm), typeof(Person), typeof(Blog), typeof(Post)); Recreate(); Client.DeleteAll(); Firm.DeleteAll(); Company.DeleteAll(); Person.DeleteAll(); Firm firm = new Firm("keldor"); firm.Save(); Client client = new Client("castle", firm); client.Save(); Client[] clients = Client.FindAll(); Assert.AreEqual( 1, clients.Length ); Firm[] firms = Firm.FindAll(); Assert.AreEqual( 1, firms.Length ); Assert.AreEqual( firm.Id, firms[0].Id ); Assert.AreEqual( client.Id, clients[0].Id ); Assert.IsNotNull( clients[0].Firm ); Assert.AreEqual( firm.Id, clients[0].Firm.Id ); }
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 ); }
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); } }