Exemplo n.º 1
0
        public void CanNotRetrieveDetachedCriteriaResultWithUnknownKey()
        {
            CreateItems();

            using (ISession session = OpenSession())
            {
                IMultiCriteria multiCriteria = session.CreateMultiCriteria();

                DetachedCriteria firstCriteria = DetachedCriteria.For(typeof(Item))
                                                 .Add(Expression.Lt("id", 50));

                multiCriteria.Add("firstCriteria", firstCriteria);

                try
                {
                    IList firstResult = (IList)multiCriteria.GetResult("unknownKey");
                    Assert.Fail("This should've thrown an InvalidOperationException");
                }
                catch (InvalidOperationException)
                {
                }
                catch (Exception)
                {
                    Assert.Fail("This should've thrown an InvalidOperationException");
                }
            }

            RemoveAllItems();
        }
Exemplo n.º 2
0
        public void CanAddDetachedCriteriaWithKeyAndRetrieveResultsWithKey()
        {
            CreateItems();

            using (ISession session = OpenSession())
            {
                IMultiCriteria multiCriteria = session.CreateMultiCriteria();

                DetachedCriteria firstCriteria = DetachedCriteria.For(typeof(Item))
                                                 .Add(Expression.Lt("id", 50));

                DetachedCriteria secondCriteria = DetachedCriteria.For(typeof(Item));

                multiCriteria.Add("firstCriteria", firstCriteria);
                multiCriteria.Add("secondCriteria", secondCriteria);

                IList secondResult = (IList)multiCriteria.GetResult("secondCriteria");
                IList firstResult  = (IList)multiCriteria.GetResult("firstCriteria");

                Assert.Greater(secondResult.Count, firstResult.Count);
            }

            RemoveAllItems();
        }