本文整理汇总了C#中TestClass.Persist方法的典型用法代码示例。如果您正苦于以下问题:C# TestClass.Persist方法的具体用法?C# TestClass.Persist怎么用?C# TestClass.Persist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestClass
的用法示例。
在下文中一共展示了TestClass.Persist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CachedSessionTest
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");
}
示例2: CachedSessionTest
/// <summary>
/// Tests the caching and re using of sessiosn to increase perfomance by avoding
/// creating new sessions for each client request
/// </summary>
// [Test]
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";
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 therad and kill after timeout
ReturnSessionToCache(lSession);
Thread lThread=new Thread(new ThreadStart(()=>
{
lSession = GetCachedSession();
counter = lSession.AllObjects<TestClass>(true, false).Count();
ReturnSessionToCache(lSession);
}));
lThread.Start();
lEvent.WaitOne(5000);
if(lThread.IsAlive)lThread.Abort();
Assert.AreNotEqual(0, counter, "Invalid nr of objects retreived");
}