public void CachedSessionTest() { ServerClientSession lSession = GetCachedSession(); //lets simulate that we did some prior work, return the session and get it again ReturnSessionToCache(lSession); lSession = GetCachedSession(); TestClass lTestClass = new TestClass(); lTestClass.SomeIntVar = 123; lTestClass.SomeStringVar = "test"; UInt64 id = lTestClass.Persist(lSession, lTestClass); var c = new Class_A(); UInt64 id2 = lSession.Persist(c); Class_B class_b = new Class_B(); class_b.IntField = 11; class_b.StringField = "sss"; Class_A class_a = new Class_A(); class_a.string_field = "xxx"; class_a.b_field = class_b; UInt64 id3 = lSession.Persist(class_a); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); lSession.Abort(); lSession.BeginUpdate(); Class_A cA = lSession.Open<Class_A>(id2); cA = lSession.Open<Class_A>(id3); lTestClass = lSession.Open<TestClass>(id); Assert.NotNull(lTestClass.GeoCord); Assert.NotNull(lTestClass.StoredStructInObjectField); lTestClass.SomeIntVar = 1234; lTestClass.SomeStringVar = "test2"; lTestClass.Persist(lSession, lTestClass); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); counter = (int) lSession.AllObjects<TestClass>(true, false).Count(); ReturnSessionToCache(lSession); Thread lThread = new Thread(new ThreadStart(() => { lSession = GetCachedSession(); counter = (int) lSession.AllObjects<TestClass>(true, false).Count(); ReturnSessionToCache(lSession); })); lThread.Start(); lEvent.WaitOne(5000); if (lThread.IsAlive) lThread.Abort(); Assert.AreNotEqual(0, counter, "Invalid number of objects retrieved"); }
/* オブジェクト指向 */ /* ①継承 : Inheritance */ /*クラスを継承して使うことができる*/ static void Main() { Class_A A = new Class_A(); System.Console.WriteLine(""); Class_B B = new Class_B(); System.Console.WriteLine(""); Class_C C = new Class_C(); System.Console.WriteLine(""); Class_D D = new Class_D(); }
static void Main(string[] args) { Class_B b = new Class_B(); Class_A a = null; // Приведение типов при помощи оператора is //if (b is Class_A) // a = (Class_A)b; //else a = null; Console.WriteLine(b is Class_A); //Console.WriteLine(a.GetType()); // Приведение типов при помощи оператора as. Означает, что переменной а присваивается значение переменной b приведенной к типу а (Class_A) a = b as Class_A; Console.WriteLine(a.GetType()); Console.ReadKey(); }
public void CachedSessionTest() { ServerClientSession lSession = GetCachedSession(); //lets simulate that we did some prior work, return the session and get it again ReturnSessionToCache(lSession); lSession = GetCachedSession(); TestClass lTestClass = new TestClass(); lTestClass.SomeIntVar = 123; lTestClass.SomeStringVar = "test"; UInt64 id = lTestClass.Persist(lSession, lTestClass); var c = new Class_A(); UInt64 id2 = lSession.Persist(c); Class_B class_b = new Class_B(); class_b.IntField = 11; class_b.StringField = "sss"; Class_A class_a = new Class_A(); class_a.string_field = "xxx"; class_a.b_field = class_b; UInt64 id3 = lSession.Persist(class_a); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); lSession.Abort(); lSession.BeginUpdate(); Class_A cA = lSession.Open <Class_A>(id2); cA = lSession.Open <Class_A>(id3); lTestClass = lSession.Open <TestClass>(id); Assert.NotNull(lTestClass.GeoCord); Assert.NotNull(lTestClass.StoredStructInObjectField); lTestClass.SomeIntVar = 1234; lTestClass.SomeStringVar = "test2"; lTestClass.Persist(lSession, lTestClass); lSession.Commit(); //return to cache, get it again and query the object //as this test is to verify it does not hang we do it in separate thread and kill after timeout ReturnSessionToCache(lSession); lSession = GetCachedSession(); counter = (int)lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); Thread lThread = new Thread(new ThreadStart(() => { lSession = GetCachedSession(); counter = (int)lSession.AllObjects <TestClass>(true, false).Count(); ReturnSessionToCache(lSession); })); lThread.Start(); lEvent.WaitOne(5000); if (lThread.IsAlive) { lThread.Abort(); } Assert.AreNotEqual(0, counter, "Invalid number of objects retrieved"); }