public void QueryWithSingleAndPredicate()
        {
            var query = (from o in QueryFactory.CreateLinqQuery <Order>()
                         select o).Single(i => i.OrderNumber == 5);

            Assert.That(query, Is.EqualTo(DomainObjectIDs.Order5.GetObject <TestDomainBase> ()));
        }
        public void EagerFetching_FetchAfterMultipleFromsWithoutSelectClauseInCallChain()
        {
            var query = (from o1 in QueryFactory.CreateLinqQuery <Order> ()
                         from o2 in QueryFactory.CreateLinqQuery <Order> ()
                         where o1.OrderNumber < 6
                         select o1).Distinct().FetchMany(x => x.OrderItems);

            CheckQueryResult(query, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.Order4, DomainObjectIDs.Order5,
                             DomainObjectIDs.Order2);

            CheckDataContainersRegistered(DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.Order4, DomainObjectIDs.Order5,
                                          DomainObjectIDs.Order2);
            CheckDataContainersRegistered(
                DomainObjectIDs.OrderItem1,
                DomainObjectIDs.OrderItem2,
                DomainObjectIDs.OrderItem3,
                DomainObjectIDs.OrderItem4,
                DomainObjectIDs.OrderItem5,
                DomainObjectIDs.OrderItem6);

            CheckCollectionRelationRegistered(DomainObjectIDs.Order1, "OrderItems", false, DomainObjectIDs.OrderItem1, DomainObjectIDs.OrderItem2);
            CheckCollectionRelationRegistered(DomainObjectIDs.Order3, "OrderItems", false, DomainObjectIDs.OrderItem3);
            CheckCollectionRelationRegistered(DomainObjectIDs.Order4, "OrderItems", false, DomainObjectIDs.OrderItem4);
            CheckCollectionRelationRegistered(DomainObjectIDs.Order5, "OrderItems", false, DomainObjectIDs.OrderItem5);
            CheckCollectionRelationRegistered(DomainObjectIDs.Order2, "OrderItems", false, DomainObjectIDs.OrderItem6);
        }
Пример #3
0
        public List <AccessControlList> FindAccessControlLists()
        {
            var findAllAclsQuery = from acl in QueryFactory.CreateLinqQuery <AccessControlList> ()
                                   select acl;

            return(findAllAclsQuery.ToList());
        }
        public void EagerFetching_MultipleFetches_OnSameLevel()
        {
            var query = (from o in QueryFactory.CreateLinqQuery <Order> ()
                         where o.OrderNumber == 1
                         select o)
                        .Distinct()
                        .FetchMany(o => o.OrderItems)
                        .FetchOne(o => o.Customer).ThenFetchMany(c => c.Orders).ThenFetchOne(c => c.OrderTicket)
                        .FetchOne(o => o.Customer).ThenFetchMany(c => c.Orders).ThenFetchMany(c => c.OrderItems)
                        .FetchMany(o => o.OrderItems);

            CheckQueryResult(query, DomainObjectIDs.Order1);

            CheckDataContainersRegistered(
                DomainObjectIDs.Order1,                                                            // the original order
                DomainObjectIDs.Customer1,                                                         // the customer
                DomainObjectIDs.Order1, DomainObjectIDs.Order2,                                    // the customer's orders
                DomainObjectIDs.OrderTicket1, DomainObjectIDs.OrderTicket2,                        // the customer's orders' tickets
                DomainObjectIDs.OrderItem1, DomainObjectIDs.OrderItem2, DomainObjectIDs.OrderItem6 // the customer's orders' items
                );

            CheckObjectRelationRegistered(DomainObjectIDs.Order1, "Customer", DomainObjectIDs.Customer1);
            CheckCollectionRelationRegistered(DomainObjectIDs.Customer1, "Orders", true, DomainObjectIDs.Order1, DomainObjectIDs.Order2);

            CheckObjectRelationRegistered(DomainObjectIDs.Order1, "OrderTicket", DomainObjectIDs.OrderTicket1);
            CheckObjectRelationRegistered(DomainObjectIDs.OrderTicket1, "Order", DomainObjectIDs.Order1);
            CheckObjectRelationRegistered(DomainObjectIDs.Order2, "OrderTicket", DomainObjectIDs.OrderTicket2);
            CheckObjectRelationRegistered(DomainObjectIDs.OrderTicket2, "Order", DomainObjectIDs.Order2);

            CheckCollectionRelationRegistered(DomainObjectIDs.Order1, "OrderItems", false, DomainObjectIDs.OrderItem1, DomainObjectIDs.OrderItem2);
            CheckObjectRelationRegistered(DomainObjectIDs.OrderItem1, "Order", DomainObjectIDs.Order1);
            CheckObjectRelationRegistered(DomainObjectIDs.OrderItem2, "Order", DomainObjectIDs.Order1);
            CheckCollectionRelationRegistered(DomainObjectIDs.Order2, "OrderItems", false, DomainObjectIDs.OrderItem6);
        }
Пример #5
0
        public void GroupBy_WithSubqueryKey()
        {
            var query = (from o in QueryFactory.CreateLinqQuery <Order> ()
                         group o by QueryFactory.CreateLinqQuery <OrderItem> ().Where(oi => oi.Order == o).Select(oi => oi.Product).Count()).Select(g => g.Key);

            Assert.That(query.Count(), Is.EqualTo(3));
        }
Пример #6
0
        public void Search_WithResultSizeConstraint()
        {
            var searchService = new TestableSecurityManagerSearchServiceBase(QueryFactory.CreateLinqQuery <User>());
            var actual        = searchService.Search(null, _property, CreateSecurityManagerSearchArguments(3));

            Assert.That(actual.Length, Is.EqualTo(3));
        }
Пример #7
0
        private ILookup <ObjectID, StatefulAccessControlListData> LoadStatefulAccessControlLists()
        {
            var result = GetOrCreateQuery(
                MethodInfo.GetCurrentMethod(),
                () => from acl in QueryFactory.CreateLinqQuery <StatefulAccessControlList>()
                from sc in acl.GetStateCombinationsForQuery()
                from usage in sc.GetStateUsagesForQuery().DefaultIfEmpty()
                from propertyReference in acl.GetClassForQuery().GetStatePropertyReferencesForQuery().DefaultIfEmpty()
                select new
            {
                Class            = acl.GetClassForQuery().ID,
                StateCombination = sc.ID.GetHandle <StateCombination>(),
                Acl               = acl.ID.GetHandle <StatefulAccessControlList>(),
                StatePropertyID   = propertyReference.StateProperty.ID,
                StatePropertyName = propertyReference.StateProperty.Name,
                StateValue        = usage.StateDefinition.Name
            });

            using (CreateStopwatchScopeForQueryExecution("stateful ACLs"))
            {
                return(result.GroupBy(
                           row => new { row.Class, row.Acl, row.StateCombination },
                           row => row.StatePropertyID != null
                       ? new State(
                               row.StatePropertyID.GetHandle <StatePropertyDefinition>(),
                               row.StatePropertyName,
                               row.StateValue)
                       : null)
                       .ToLookup(g => g.Key.Class, g => new StatefulAccessControlListData(g.Key.Acl, g.Where(s => s != null))));
            }
        }
Пример #8
0
        public void GroupBy_EntityKey()
        {
            var query1 = from o in QueryFactory.CreateLinqQuery <Order> ()
                         where o.ID != DomainObjectIDs.InvalidOrder
                         group o by o.Customer into ordersByCustomer
                         select ordersByCustomer.Key;

            CheckQueryResult(query1, DomainObjectIDs.Customer1, DomainObjectIDs.Customer3, DomainObjectIDs.Customer4, DomainObjectIDs.Customer5);

            var query2 =
                from o in QueryFactory.CreateLinqQuery <Order> ()
                group o by o.OrderTicket into ordersByOrderTicket
                where ordersByOrderTicket.Key != null
                select ordersByOrderTicket.Key.FileName;

            Assert.That(query2.Count(), Is.EqualTo(6));

            var query3 = from r in QueryFactory.CreateLinqQuery <Order> ()
                         from c in r.OrderItems
                         group c.ID by r
                         into cooksByRestaurant
                         from cook in cooksByRestaurant
                         select new { cooksByRestaurant.Key.DeliveryDate, CookID = cook };

            Assert.That(query3.Count(), Is.GreaterThan(0));
        }
Пример #9
0
 private static void TestSimpleLinqQueryWithCustomProjection_MappingInitialization()
 {
     using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
     {
         QueryFactory.CreateLinqQuery <Tenant>().Select(p => new { Value = p.ID, Key = p.UniqueIdentifier }).ToList();
     }
 }
Пример #10
0
        private static void TestComplexLinqQuery()
        {
            using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope())
            {
                using (StopwatchScope.CreateScope("Complex query took {elapsed:ms} ms"))
                {
                    var result = from acl in QueryFactory.CreateLinqQuery <StatefulAccessControlList>()
                                 from sc in acl.GetStateCombinationsForQuery()
                                 from usage in sc.GetStateUsagesForQuery().DefaultIfEmpty()
                                 from propertyReference in acl.GetClassForQuery().GetStatePropertyReferencesForQuery().DefaultIfEmpty()
                                 select new
                    {
                        Class                = acl.GetClassForQuery().ID,
                        Acl                  = acl.ID.GetHandle <StatefulAccessControlList>(),
                        HasState             = propertyReference != null,
                        StatePropertyID      = propertyReference.StateProperty.ID.Value,
                        StatePropertyClassID = propertyReference.StateProperty.ID.ClassID,
                        StatePropertyName    = propertyReference.StateProperty.Name,
                        StateValue           = usage.StateDefinition.Name
                    };

                    result.Count();
                }
            }
        }
Пример #11
0
        public void LinqCustomQuery_CallsFilterCustomQueryResult()
        {
            var listenerMock = MockRepository.GenerateMock <IClientTransactionListener>();

            listenerMock
            .Expect(
                mock => mock.FilterCustomQueryResult(
                    Arg.Is(TestableClientTransaction),
                    Arg <IQuery> .Is.Anything,
                    Arg <IEnumerable <int> > .List.Equal(new[] { 1, 2, 3, 4, 5 })))
            .Return(new[] { 1, 2, 3 });

            TestableClientTransaction.AddListener(listenerMock);
            try
            {
                var query  = from o in QueryFactory.CreateLinqQuery <Order>() where o.OrderNumber <= 5 orderby o.OrderNumber select o.OrderNumber;
                var result = query.ToArray();

                listenerMock.VerifyAllExpectations();
                Assert.That(result, Is.EqualTo(new[] { 1, 2, 3 }));
            }
            finally
            {
                TestableClientTransaction.RemoveListener(listenerMock);
            }
        }
Пример #12
0
 private void Step1()
 {
     QueryFactory.CreateLinqQuery <SecurableClassDefinition>()
     .Where(cd => cd == CurrentObject).Select(cd => cd)
     .FetchDetails()
     .ToArray();
 }
        public void SequenceOfObjectIDs_ConstructedInMemory()
        {
            var result =
                (from o in QueryFactory.CreateLinqQuery <Order>() where o.OrderNumber < 3 select new ObjectID(o.ID.ClassID, o.ID.Value)).ToArray();

            Assert.That(result, Is.EquivalentTo(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order2 }));
        }
Пример #14
0
        public void FilterQueryResult_RaisedInAllHierarchyLevels()
        {
            using (ExtensionStrictMock.GetMockRepository().Ordered())
            {
                ExtensionStrictMock
                .Expect(
                    mock => mock.FilterQueryResult(
                        Arg.Is(ReadOnlyRootTransaction),
                        Arg <QueryResult <DomainObject> > .Matches(qr => qr.ToArray().SequenceEqual(new[] { _order1 }))))
                .Return(new QueryResult <DomainObject> (_queryStub, new[] { _order3 }))
                .WhenCalled(mi => Assert.That(ReadOnlyRootTransaction.IsWriteable, Is.False));

                ExtensionStrictMock
                .Expect(
                    mock => mock.FilterQueryResult(
                        Arg.Is(ReadOnlyMiddleTransaction),
                        Arg <QueryResult <DomainObject> > .Matches(qr => qr.ToArray().SequenceEqual(new[] { _order3 }))))
                .Return(new QueryResult <DomainObject> (_queryStub, new[] { _order4 }))
                .WhenCalled(mi => Assert.That(ReadOnlyMiddleTransaction.IsWriteable, Is.False));

                ExtensionStrictMock
                .Expect(
                    mock => mock.FilterQueryResult(
                        Arg.Is(WriteableSubTransaction),
                        Arg <QueryResult <DomainObject> > .Matches(qr => qr.ToArray().SequenceEqual(new[] { _order4 }))))
                .Return(new QueryResult <DomainObject> (_queryStub, new[] { _order5 }))
                .WhenCalled(mi => Assert.That(WriteableSubTransaction.IsWriteable, Is.True));
            }

            var result = ExecuteInWriteableSubTransaction(() => QueryFactory.CreateLinqQuery <Order>().Where(obj => obj.ID == _order1.ID).ToList());

            ExtensionStrictMock.VerifyAllExpectations();
            Assert.That(result, Is.EqualTo(new[] { _order5 }));
        }
Пример #15
0
        public void QueryWithSubQuery_InMainFrom()
        {
            var orders = from c in (from ci in QueryFactory.CreateLinqQuery <Computer> () select ci) select c;

            CheckQueryResult(orders, DomainObjectIDs.Computer1, DomainObjectIDs.Computer2, DomainObjectIDs.Computer3, DomainObjectIDs.Computer4,
                             DomainObjectIDs.Computer5);
        }
Пример #16
0
        public void QueryWithAll_InSubquery()
        {
            var query1 = from o in QueryFactory.CreateLinqQuery <Order>()
                         where o.OrderItems.All(oi => oi.Position == 1)
                         select o;

            CheckQueryResult(
                query1,
                DomainObjectIDs.Order3,
                DomainObjectIDs.Order4,
                DomainObjectIDs.Order5,
                DomainObjectIDs.Order2,
                DomainObjectIDs.InvalidOrder,
                DomainObjectIDs.OrderWithoutOrderItems);

            // ReSharper disable UseMethodAny.0
            var query2 = from c in QueryFactory.CreateLinqQuery <Customer>()
                         where c.Orders.All(o => o.OrderItems.Count() > 0)
                         select c;

            // ReSharper restore UseMethodAny.0

            CheckQueryResult(
                query2,
                DomainObjectIDs.Customer1,
                DomainObjectIDs.Customer2,
                DomainObjectIDs.Customer3,
                DomainObjectIDs.Customer4);
        }
Пример #17
0
        public void Compare_NotEqual()
        {
            IQueryable <TestDomainObject> expected = from d in QueryFactory.CreateLinqQuery <TestDomainObject>() where d.Value == 1 select d;
            IQueryable <TestDomainObject> actual   = from d in QueryFactory.CreateLinqQuery <TestDomainObject>() where d.Value == 0 select d;

            _queryableComparer.Compare(expected, actual);
        }
Пример #18
0
        public void GroupBy_UseGroupInFromExpression()
        {
            var query = from o in QueryFactory.CreateLinqQuery <Order> ()
                        group o.ID by o.OrderNumber into orderByOrderNo
                        from id in orderByOrderNo
                        select new { orderByOrderNo.Key, OrderID = id };

            Assert.That(query.Count(), Is.EqualTo(7));

            var query2 =
                from o in QueryFactory.CreateLinqQuery <Order>()
                group o by o.OrderNumber
                into orderByOrderNo
                from o in orderByOrderNo
                where o != null
                select new { orderByOrderNo.Key, Order = o };

            Assert.That(query2.Count(), Is.EqualTo(7));

            var query3 =
                from o in QueryFactory.CreateLinqQuery <Order>()
                group o.OrderNumber by o.OrderNumber into orderByOrderNo
                from o in
                (
                    from so in orderByOrderNo
                    select so).Distinct()
                select new { orderByOrderNo.Key, Order = o };

            Assert.That(query3.Count(), Is.EqualTo(7));
        }
Пример #19
0
        public void QueryWithCount()
        {
            var number = (from o in QueryFactory.CreateLinqQuery <Order>()
                          select o).Count();

            Assert.That(7, Is.EqualTo(number));
        }
Пример #20
0
        public void ExtensibleEnums_InWhereClause()
        {
            var query1 = from cwadt in QueryFactory.CreateLinqQuery <ClassWithAllDataTypes> ()
                         where cwadt.ExtensibleEnumProperty == Color.Values.Red()
                         select cwadt;

            var result1 = query1.ToArray();

            Assert.That(result1, Is.EqualTo(new[] { DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> () }));

            var query2 = from cwadt in QueryFactory.CreateLinqQuery <ClassWithAllDataTypes> ()
                         where cwadt.ExtensibleEnumProperty.Equals(Color.Values.Red())
                         select cwadt;

            var result2 = query2.ToArray();

            Assert.That(result2, Is.EqualTo(new[] { DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> () }));

            var query3 = from cwadt in QueryFactory.CreateLinqQuery <ClassWithAllDataTypes> ()
                         where new[] { Color.Values.Red(), Color.Values.Blue() }.Contains(cwadt.ExtensibleEnumProperty)
            select cwadt;

            var result3 = query3.ToArray();

            Assert.That(
                result3,
                Is.EquivalentTo(
                    new[]
            {
                DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (),
                DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> ()
            }));
        }
Пример #21
0
        public void CreateLinqQuery_WithoutParserAndExecutor()
        {
            var factoryMock    = MockRepository.GenerateStrictMock <ILinqProviderComponentFactory> ();
            var serviceLocator = DefaultServiceLocator.Create();

            serviceLocator.RegisterSingle <ILinqProviderComponentFactory> (() => factoryMock);
            using (new ServiceLocatorScope(serviceLocator))
            {
                var fakeExecutor    = MockRepository.GenerateStub <IQueryExecutor> ();
                var fakeQueryParser = MockRepository.GenerateStub <IQueryParser> ();
                var fakeResult      = MockRepository.GenerateStub <IQueryable <Order> > ();

                factoryMock
                .Expect(mock => mock.CreateQueryExecutor(TestDomainStorageProviderDefinition))
                .Return(fakeExecutor);
                factoryMock
                .Expect(mock => mock.CreateQueryParser())
                .Return(fakeQueryParser);
                factoryMock
                .Expect(mock => mock.CreateQueryable <Order> (fakeQueryParser, fakeExecutor))
                .Return(fakeResult);

                var result = QueryFactory.CreateLinqQuery <Order> ();

                factoryMock.VerifyAllExpectations();
                Assert.That(result, Is.SameAs(fakeResult));
            }
        }
        public void BaseObjects_MemberAccessInSameClass_SingleTableInheritance()
        {
            var company = (from c in QueryFactory.CreateLinqQuery <Company> ()
                           where c.IndustrialSector.ID == DomainObjectIDs.IndustrialSector2 && c.Name == "Firma 2"
                           select c);

            CheckQueryResult(company, DomainObjectIDs.Company2);
        }
        public void BaseObjects_PropertyAccessInSameClass_SingleTableInheritance()
        {
            var company = (from c in QueryFactory.CreateLinqQuery <Company> ()
                           where c.Name == "Firma 2"
                           select c);

            CheckQueryResult(company, DomainObjectIDs.Company2);
        }
        public void ConcreteObjects_MemberAccessInBaseClass_SingleTableInheritance()
        {
            var customers = (from c in QueryFactory.CreateLinqQuery <Customer> ()
                             where c.IndustrialSector.ID == DomainObjectIDs.IndustrialSector2
                             select c);

            CheckQueryResult(customers, DomainObjectIDs.Customer3, DomainObjectIDs.Customer2);
        }
        public void ConcreteObjects_PropertyAccessInBaseClass_SingleTableInheritance()
        {
            var customer = (from c in QueryFactory.CreateLinqQuery <Customer>()
                            where c.Name == "Kunde 3"
                            select c);

            CheckQueryResult(customer, DomainObjectIDs.Customer3);
        }
        public void ConcreteObjects_PropertyAccessInBaseClass_ClassAboveInheritanceHierarchy()
        {
            var storageClass = (from f in QueryFactory.CreateLinqQuery <StorageGroupClass> ()
                                where f.AboveInheritanceIdentifier == "AboveInheritanceName1"
                                select f);

            CheckQueryResult(storageClass, DomainObjectIDs.StorageGroupClass1);
        }
        public void BaseObjects_MemberAccessInSameClass_ConcreteTableInheritance()
        {
            var fsi = (from f in QueryFactory.CreateLinqQuery <TIFileSystemItem> ()
                       where f.ParentFolder.ID == _concreteObjectIDs.FolderRoot
                       select f);

            CheckQueryResult(fsi, _concreteObjectIDs.FileRoot, _concreteObjectIDs.Folder1);
        }
        public void BaseObjects_PropertyAccessInSameClass_ConcreteTableInheritance()
        {
            var fsi = (from f in QueryFactory.CreateLinqQuery <TIFileSystemItem> ()
                       where f.Name == "Datei im Root"
                       select f);

            CheckQueryResult(fsi, _concreteObjectIDs.FileRoot);
        }
        public void ConcreteObjects_PropertyAccessInSameClass_ConcreteTableInheritance()
        {
            var fsi = (from f in QueryFactory.CreateLinqQuery <TIFile> ()
                       where f.Size == 512
                       select f);

            CheckQueryResult(fsi, _concreteObjectIDs.File1);
        }
Пример #30
0
        public void QueryWithFirst_AndInterface()
        {
            var queryResult = (from o in QueryFactory.CreateLinqQuery <Order> ()
                               orderby o.OrderNumber
                               select(IOrder) o).First();

            Assert.That(queryResult, Is.EqualTo(DomainObjectIDs.Order1.GetObject <Order> ()));
        }