本文整理汇总了C#中TestData.Prepare方法的典型用法代码示例。如果您正苦于以下问题:C# TestData.Prepare方法的具体用法?C# TestData.Prepare怎么用?C# TestData.Prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestData
的用法示例。
在下文中一共展示了TestData.Prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WithClause
public void WithClause()
{
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
// one-to-many
IList list =
s.CreateQuery("from Human h inner join h.offspring as o with o.bodyWeight < :someLimit").SetDouble("someLimit", 1).
List();
Assert.That(list, Is.Empty, "ad-hoc on did not take effect");
// many-to-one
list =
s.CreateQuery("from Animal a inner join a.mother as m with m.bodyWeight < :someLimit").SetDouble("someLimit", 1).
List();
Assert.That(list, Is.Empty, "ad-hoc on did not take effect");
// many-to-many
list = s.CreateQuery("from Human h inner join h.friends as f with f.nickName like 'bubba'").List();
Assert.That(list, Is.Empty, "ad-hoc on did not take effect");
txn.Commit();
s.Close();
data.Cleanup();
}
示例2: CombinedClassAndCollectionFiltersEnabled
public void CombinedClassAndCollectionFiltersEnabled()
{
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
session.EnableFilter("regionlist").SetParameterList("regions", new string[] {"LA", "APAC"});
session.EnableFilter("fulfilledOrders").SetParameter("asOfDate", testData.lastMonth);
// test retreival through hql with the collection as non-eager
IList salespersons = session.CreateQuery("select s from Salesperson as s").List();
Assert.AreEqual(1, salespersons.Count, "Incorrect salesperson count");
Salesperson sp = (Salesperson) salespersons[0];
Assert.AreEqual(1, sp.Orders.Count, "Incorrect order count");
session.Clear();
// test retreival through hql with the collection join fetched
salespersons = session.CreateQuery("select s from Salesperson as s left join fetch s.Orders").List();
Assert.AreEqual(1, salespersons.Count, "Incorrect salesperson count");
sp = (Salesperson) salespersons[0];
Assert.AreEqual(sp.Orders.Count, 1, "Incorrect order count");
session.Close();
testData.Release();
}
示例3: SecondLevelCachedCollectionsFiltering
public void SecondLevelCachedCollectionsFiltering()
{
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
// Force a collection into the second level cache, with its non-filtered elements
Salesperson sp = (Salesperson) session.Load(typeof(Salesperson), testData.steveId);
NHibernateUtil.Initialize(sp.Orders);
ICollectionPersister persister = ((ISessionFactoryImplementor) sessions)
.GetCollectionPersister(typeof(Salesperson).FullName + ".Orders");
Assert.IsTrue(persister.HasCache, "No cache for collection");
CacheKey cacheKey =
new CacheKey(testData.steveId, persister.KeyType, persister.Role, EntityMode.Poco, (ISessionFactoryImplementor) sessions);
CollectionCacheEntry cachedData = (CollectionCacheEntry)persister.Cache.Cache.Get(cacheKey);
Assert.IsNotNull(cachedData, "collection was not in cache");
session.Close();
session = OpenSession();
session.EnableFilter("fulfilledOrders").SetParameter("asOfDate", testData.lastMonth);
sp = (Salesperson) session.CreateQuery("from Salesperson as s where s.id = :id")
.SetInt64("id", testData.steveId)
.UniqueResult();
Assert.AreEqual(1, sp.Orders.Count, "Filtered-collection not bypassing 2L-cache");
CollectionCacheEntry cachedData2 = (CollectionCacheEntry)persister.Cache.Cache.Get(cacheKey);
Assert.IsNotNull(cachedData2, "collection no longer in cache!");
Assert.AreSame(cachedData, cachedData2, "Different cache values!");
session.Close();
session = OpenSession();
session.EnableFilter("fulfilledOrders").SetParameter("asOfDate", testData.lastMonth);
sp = (Salesperson) session.Load(typeof(Salesperson), testData.steveId);
Assert.AreEqual(1, sp.Orders.Count, "Filtered-collection not bypassing 2L-cache");
session.Close();
// Finally, make sure that the original cached version did not get over-written
session = OpenSession();
sp = (Salesperson) session.Load(typeof(Salesperson), testData.steveId);
Assert.AreEqual(2, sp.Orders.Count, "Actual cached version got over-written");
session.Close();
testData.Release();
}
示例4: WithClauseFailsWithFetch
public void WithClauseFailsWithFetch()
{
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction txn = s.BeginTransaction();
Assert.Throws<SemanticException>(
() =>
s.CreateQuery("from Animal a inner join fetch a.offspring as o with o.bodyWeight = :someLimit").SetDouble(
"someLimit", 1).List(), "ad-hoc on clause allowed with fetched association");
txn.Commit();
s.Close();
data.Cleanup();
}
示例5: InsertWithManyToOne
public void InsertWithManyToOne()
{
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
s.CreateQuery(
"insert into Animal (description, bodyWeight, mother) select description, bodyWeight, mother from Human").
ExecuteUpdate();
t.Commit();
t = s.BeginTransaction();
t.Commit();
s.Close();
data.Cleanup();
}
示例6: SimpleInsert
public void SimpleInsert()
{
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
s.CreateQuery("insert into Pickup (id, Vin, Owner) select id, Vin, Owner from Car").ExecuteUpdate();
t.Commit();
t = s.BeginTransaction();
s.CreateQuery("delete Vehicle").ExecuteUpdate();
t.Commit();
s.Close();
data.Cleanup();
}
示例7: OneToManyFilters
public void OneToManyFilters()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// one-to-many loading tests
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
log.Info("Starting one-to-many collection loader filter tests.");
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
session.EnableFilter("seniorSalespersons")
.SetParameter("asOfDate", testData.lastMonth);
log.Info("Performing Load of Department...");
Department department = (Department) session.Load(typeof(Department), testData.deptId);
ISet<Salesperson> salespersons = department.Salespersons;
Assert.AreEqual(1, salespersons.Count, "Incorrect salesperson count");
session.Close();
testData.Release();
}
示例8: GetFilters
public void GetFilters()
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Get() test
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
log.Info("Starting get() filter tests (eager assoc. fetching).");
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
session.EnableFilter("region").SetParameter("region", "APAC");
log.Info("Performing get()...");
Salesperson salesperson = (Salesperson) session.Get(typeof(Salesperson), testData.steveId);
Assert.IsNotNull(salesperson);
Assert.AreEqual(1, salesperson.Orders.Count, "Incorrect order count");
session.Close();
testData.Release();
}
示例9: UpdateMultiplePropertyOnAnimal
public void UpdateMultiplePropertyOnAnimal()
{
var data = new TestData(this);
data.Prepare();
using (ISession s = OpenSession())
using (ITransaction t = s.BeginTransaction())
{
int count =
s.CreateQuery("update Animal set description = :newDesc, bodyWeight = :w1 where description = :desc")
.SetString("desc", data.Polliwog.Description)
.SetString("newDesc", "Tadpole")
.SetSingle("w1", 3)
.ExecuteUpdate();
Assert.That(count, Is.EqualTo(1));
t.Commit();
}
using (ISession s = OpenSession())
using (s.BeginTransaction())
{
var tadpole = s.Get<Animal>(data.Polliwog.Id);
Assert.That(tadpole.Description, Is.EqualTo("Tadpole"));
Assert.That(tadpole.BodyWeight, Is.EqualTo(3));
}
data.Cleanup();
}
示例10: UpdateOnAnimal
public void UpdateOnAnimal()
{
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
int count =
s.CreateQuery("update Animal set description = description where description = :desc")
.SetString("desc", data.Frog.Description)
.ExecuteUpdate();
Assert.That(count, Is.EqualTo(1), "Incorrect entity-updated count");
count =
s.CreateQuery("update Animal set description = :newDesc where description = :desc")
.SetString("desc",data.Polliwog.Description)
.SetString("newDesc", "Tadpole")
.ExecuteUpdate();
Assert.That(count, Is.EqualTo(1), "Incorrect entity-updated count");
var tadpole = s.Load<Animal>(data.Polliwog.Id);
Assert.That(tadpole.Description, Is.EqualTo("Tadpole"), "Update did not take effect");
count =
s.CreateQuery("update Animal set bodyWeight = bodyWeight + :w1 + :w2")
.SetSingle("w1", 1)
.SetSingle("w2", 2)
.ExecuteUpdate();
Assert.That(count, Is.EqualTo(6), "incorrect count on 'complex' update assignment");
if (! (Dialect is MySQLDialect))
{
// MySQL does not support (even un-correlated) subqueries against the update-mutating table
s.CreateQuery("update Animal set bodyWeight = ( select max(bodyWeight) from Animal )").ExecuteUpdate();
}
t.Commit();
s.Close();
data.Cleanup();
}
示例11: SimpleDeleteOnAnimal
public void SimpleDeleteOnAnimal()
{
if (Dialect.HasSelfReferentialForeignKeyBug)
{
Assert.Ignore("self referential FK bug", "HQL delete testing");
return;
}
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
int count =
s.CreateQuery("delete from Animal as a where a.id = :id").SetInt64("id", data.Polliwog.Id).ExecuteUpdate();
Assert.That(count, Is.EqualTo(1), "Incorrect delete count");
count = s.CreateQuery("delete Animal where id = :id").SetInt64("id", data.Catepillar.Id).ExecuteUpdate();
Assert.That(count, Is.EqualTo(1), "Incorrect delete count");
// HHH-873...
if (Dialect.SupportsSubqueryOnMutatingTable)
{
count = s.CreateQuery("delete from User u where u not in (select u from User u)").ExecuteUpdate();
Assert.That(count, Is.EqualTo(0));
}
count = s.CreateQuery("delete Animal a").ExecuteUpdate();
Assert.That(count, Is.EqualTo(4), "Incorrect delete count");
IList list = s.CreateQuery("select a from Animal as a").List();
Assert.That(list, Is.Empty, "table not empty");
t.Commit();
s.Close();
data.Cleanup();
}
示例12: ManyToManyFilterOnLoad
public void ManyToManyFilterOnLoad()
{
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
session.EnableFilter("effectiveDate").SetParameter("asOfDate", DateTime.Today);
Product prod = (Product) session.Get(typeof(Product), testData.prod1Id);
//long initLoadCount = sessions.Statistics.CollectionLoadCount;
//long initFetchCount = sessions.Statistics.CollectionFetchCount;
// should already have been initialized...
Assert.IsTrue(NHibernateUtil.IsInitialized(prod.Categories));
int size = prod.Categories.Count;
Assert.AreEqual(1, size, "Incorrect filtered collection count");
//long currLoadCount = sessions.Statistics.CollectionLoadCount;
//long currFetchCount = sessions.Statistics.CollectionFetchCount;
//Assert.IsTrue(
// (initLoadCount == currLoadCount) && (initFetchCount == currFetchCount),
// "Load with join fetch of many-to-many did not trigger join fetch"
// );
// make sure we did not get back a collection of proxies
//long initEntityLoadCount = sessions.Statistics.EntityLoadCount;
foreach (Category cat in prod.Categories)
{
Assert.IsTrue(NHibernateUtil.IsInitialized(cat),
"Load with join fetch of many-to-many did not trigger *complete* join fetch");
//Console.WriteLine(" ===> " + cat.Name);
}
//long currEntityLoadCount = sessions.Statistics.EntityLoadCount;
//Assert.IsTrue(
// (initEntityLoadCount == currEntityLoadCount),
// "Load with join fetch of many-to-many did not trigger *complete* join fetch"
// );
session.Close();
testData.Release();
}
示例13: ManyToManyFilterOnQuery
public void ManyToManyFilterOnQuery()
{
TestData testData = new TestData(this);
testData.Prepare();
ISession session = OpenSession();
session.EnableFilter("effectiveDate").SetParameter("asOfDate", DateTime.Today);
IList result = session.CreateQuery("from Product p inner join fetch p.Categories").List();
Assert.IsTrue(result.Count > 0, "No products returned from HQL many-to-many filter case");
Product prod = (Product) result[0];
Assert.IsNotNull(prod);
Assert.AreEqual(1, prod.Categories.Count, "Incorrect Product.categories count for filter with HQL");
session.Close();
testData.Release();
}
示例14: DeleteUnionSubclassLeafSubclass
public void DeleteUnionSubclassLeafSubclass()
{
var data = new TestData(this);
data.Prepare();
// These should only affect the given table
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
int count = s.CreateQuery("delete Car where Owner = :owner").SetString("owner", "Kirsten").ExecuteUpdate();
Assert.That(count, Is.EqualTo(1), "incorrect restricted update count");
count = s.CreateQuery("delete Car").ExecuteUpdate();
Assert.That(count, Is.EqualTo(0), "incorrect update count");
t.Commit();
s.Close();
data.Cleanup();
}
示例15: DeleteRestrictedOnManyToOne
public void DeleteRestrictedOnManyToOne()
{
var data = new TestData(this);
data.Prepare();
ISession s = OpenSession();
ITransaction t = s.BeginTransaction();
int count = s.CreateQuery("delete Animal where mother = :mother").SetEntity("mother", data.Butterfly).ExecuteUpdate();
Assert.That(count, Is.EqualTo(1));
t.Commit();
s.Close();
data.Cleanup();
}