private List <object> CreatePersonAndDetails <TPerson, TDetails>() where TPerson : Person, new() where TDetails : Details, new() { List <object> ids = new List <object>(); using (ISession s = Sfi.OpenSession()) using (ITransaction tx = s.BeginTransaction()) { for (int i = 0; i < 6; i++) { Person person = new TPerson(); if (i % 2 == 0) { Details details = new TDetails(); details.Data = String.Format("{0}{1}", typeof(TDetails).Name, i); person.Details = details; } person.Name = String.Format("{0}{1}", typeof(TPerson).Name, i); ids.Add(s.Save(person)); } tx.Commit(); } return(ids); }
private void OneToOneUpdateTest <TPerson, TDetails>() where TPerson : Person, new() where TDetails : Details, new() { List <object> ids = this.CreatePersonAndDetails <TPerson, TDetails>(); IStatistics statistics = Sfi.Statistics; // Clear the second level cache and the statistics Sfi.EvictEntity(typeof(TPerson).FullName); Sfi.EvictEntity(typeof(TDetails).FullName); Sfi.EvictQueries(); statistics.Clear(); // Fill the empty caches with data. this.FetchPeopleById <TPerson>(ids); // Verify that no data was retrieved from the cache. Assert.AreEqual(0, statistics.SecondLevelCacheHitCount, "Second level cache hit count"); statistics.Clear(); int personId = DeleteDetailsFromFirstPerson <TPerson>(); // Verify that the cache was updated Assert.AreEqual(1, statistics.SecondLevelCachePutCount, "Second level cache put count"); statistics.Clear(); // Verify that the Person was updated in the cache using (ISession s = Sfi.OpenSession()) using (ITransaction tx = s.BeginTransaction()) { TPerson person = s.Get <TPerson>(personId); Assert.IsNull(person.Details); } Assert.AreEqual(0, statistics.SecondLevelCacheMissCount, "Second level cache miss count"); statistics.Clear(); // Verify that the Details was removed from the cache and deleted. using (ISession s = Sfi.OpenSession()) using (ITransaction tx = s.BeginTransaction()) { TDetails details = s.Get <TDetails>(personId); Assert.Null(details); } Assert.AreEqual(0, statistics.SecondLevelCacheHitCount, "Second level cache hit count"); }