Exemplo n.º 1
0
        public void CreateSequenceQuery_EntityQuery_WithFetchRequestWithSortExpressionBasedOnMixinPropertyNotPartOfInterface_ThrowsNotSupportedException()
        {
            var fakeSqlQuery =
                CreateSqlQueryGeneratorResult(
                    selectedEntityType: typeof(RelationTarget));
            var targetTypeQueryModel =
                QueryModelObjectMother.Create(
                    Expression.Constant(null, typeof(RelationTarget)));

            _sqlQueryGeneratorMock.Stub(stub => stub.CreateSqlQuery(targetTypeQueryModel)).Return(fakeSqlQuery);

            var fetchQueryModelBuilder =
                CreateFetchManyQueryModelBuilder(
                    (RelationTarget o) => o.CollectionProperty,
                    targetTypeQueryModel);
            var fakeFetchSqlQueryResult = CreateSqlQueryGeneratorResult("FETCH");

            _sqlQueryGeneratorMock
            .Stub(mock => mock.CreateSqlQuery(Arg <QueryModel> .Is.Anything))
            .Return(fakeFetchSqlQueryResult);

            Assert.That(
                () => _generator.CreateSequenceQuery <int> ("id", TestDomainStorageProviderDefinition, targetTypeQueryModel, new[] { fetchQueryModelBuilder }),
                Throws.TypeOf <NotSupportedException>().And.Message.EqualTo(
                    "The member 'Remotion.Data.DomainObjects.UnitTests.Linq.TestDomain.Error.SortExpressionForPropertyWithoutInterface.RelationMixin.SortProperty' "
                    + "is not part of any interface introduced onto the target class "
                    + "'Remotion.Data.DomainObjects.UnitTests.Linq.TestDomain.Error.SortExpressionForPropertyWithoutInterface.MixinTarget'. "
                    + "Only mixed properties that are part of an introduced interface can be used within the sort-expression of a collection property."));
        }
Exemplo n.º 2
0
        public void CreateSequenceQuery_EntityQuery_WithFetchRequestWithSortExpressionBasedOnMixinProperty()
        {
            var fakeSqlQuery         = CreateSqlQueryGeneratorResult(selectedEntityType: typeof(RelationTargetForPersistentMixin));
            var targetTypeQueryModel = QueryModelObjectMother.Create(Expression.Constant(null, typeof(RelationTargetForPersistentMixin)));

            _sqlQueryGeneratorMock.Stub(stub => stub.CreateSqlQuery(targetTypeQueryModel)).Return(fakeSqlQuery);

            var fetchQueryModelBuilder  = CreateFetchManyQueryModelBuilder((RelationTargetForPersistentMixin o) => o.RelationProperty4, targetTypeQueryModel);
            var fakeFetchSqlQueryResult = CreateSqlQueryGeneratorResult("FETCH");

            _sqlQueryGeneratorMock
            .Expect(mock => mock.CreateSqlQuery(Arg <QueryModel> .Is.Anything))
            .Return(fakeFetchSqlQueryResult)
            .WhenCalled(mi =>
            {
                var actualQueryModel = (QueryModel)mi.Arguments[0];
                var fetchQueryModel  = fetchQueryModelBuilder.GetOrCreateFetchQueryModel();

                Assert.That(actualQueryModel.MainFromClause.FromExpression, Is.TypeOf <SubQueryExpression> ());
                CheckActualFetchQueryModel(((SubQueryExpression)actualQueryModel.MainFromClause.FromExpression).QueryModel, fetchQueryModel);

                Assert.That(actualQueryModel.BodyClauses, Has.Some.TypeOf <OrderByClause> ());
                var orderByClause      = (OrderByClause)actualQueryModel.BodyClauses.Single();
                var endPointDefinition = ((VirtualRelationEndPointDefinition)GetEndPointDefinition(typeof(RelationTargetForPersistentMixin), "RelationProperty4"));
                Assert.That(endPointDefinition.SortExpressionText,
                            Is.EqualTo("Remotion.Data.DomainObjects.UnitTests.MixedDomains.TestDomain.MixinAddingPersistentProperties.PersistentProperty ASC"));
                var sortedByMember = NormalizingMemberInfoFromExpressionUtility.GetProperty((IMixinAddingPersistentProperties o) => o.PersistentProperty);
                Assert.That(((MemberExpression)orderByClause.Orderings[0].Expression).Member, Is.SameAs(sortedByMember));
                Assert.That(orderByClause.Orderings[0].OrderingDirection, Is.EqualTo(OrderingDirection.Asc));
            });
            _generator.CreateSequenceQuery <int> ("id", TestDomainStorageProviderDefinition, targetTypeQueryModel, new[] { fetchQueryModelBuilder });

            _sqlQueryGeneratorMock.VerifyAllExpectations();
        }
Exemplo n.º 3
0
        public void CreateSequenceQuery_EntityQuery_WithMixinFetchRequest()
        {
            var fakeSqlQuery         = CreateSqlQueryGeneratorResult(selectedEntityType: typeof(TargetClassForPersistentMixin));
            var targetTypeQueryModel = QueryModelObjectMother.Create(Expression.Constant(null, typeof(TargetClassForPersistentMixin)));

            _sqlQueryGeneratorMock.Stub(stub => stub.CreateSqlQuery(targetTypeQueryModel)).Return(fakeSqlQuery);

            var fetchQueryModelBuilder  = CreateFetchOneQueryModelBuilder((IMixinAddingPersistentProperties o) => o.RelationProperty);
            var fakeFetchSqlQueryResult = CreateSqlQueryGeneratorResult("FETCH");

            _sqlQueryGeneratorMock
            .Expect(mock => mock.CreateSqlQuery(Arg <QueryModel> .Is.Anything))
            .Return(fakeFetchSqlQueryResult)
            .WhenCalled(mi =>
            {
                var actualQueryModel = (QueryModel)mi.Arguments[0];
                var fetchQueryModel  = fetchQueryModelBuilder.GetOrCreateFetchQueryModel();
                CheckActualFetchQueryModel(actualQueryModel, fetchQueryModel);
            });

            var result = _generator.CreateSequenceQuery <int> ("id", TestDomainStorageProviderDefinition, targetTypeQueryModel, new[] { fetchQueryModelBuilder });

            _sqlQueryGeneratorMock.VerifyAllExpectations();
            var expectedEndPointDefinition = GetEndPointDefinition(
                typeof(TargetClassForPersistentMixin), typeof(MixinAddingPersistentProperties), "RelationProperty");

            CheckSingleFetchRequest(result.EagerFetchQueries, expectedEndPointDefinition, "FETCH");
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            _preparationStageMock = MockRepository.GenerateStrictMock <ISqlPreparationStage> ();
            _resolutionStageMock  = MockRepository.GenerateStrictMock <IMappingResolutionStage> ();
            _generationStageMock  = MockRepository.GenerateStrictMock <ISqlGenerationStage> ();

            _sqlQueryGenerator = new SqlQueryGenerator(_preparationStageMock, _resolutionStageMock, _generationStageMock);

            _queryModel = QueryModelObjectMother.Create();
        }
Exemplo n.º 5
0
        public override void SetUp()
        {
            base.SetUp();

            _sqlQueryGeneratorMock              = MockRepository.GenerateStrictMock <ISqlQueryGenerator> ();
            _typeConversionProvider             = SafeServiceLocator.Current.GetInstance <ITypeConversionProvider>();
            _storageTypeInformationProviderStub = MockRepository.GenerateStub <IStorageTypeInformationProvider>();

            _generator = new DomainObjectQueryGenerator(
                _sqlQueryGeneratorMock,
                _typeConversionProvider,
                _storageTypeInformationProviderStub,
                Configuration);

            _customerClassDefinition = GetTypeDefinition(typeof(Customer));
            _customerQueryModel      = QueryModelObjectMother.Create(Expression.Constant(null, typeof(Customer)));
        }
        public override void SetUp()
        {
            base.SetUp();

            _queryGeneratorMock = MockRepository.GenerateStrictMock <IDomainObjectQueryGenerator>();
            _queryExecutor      = new DomainObjectQueryExecutor(TestDomainStorageProviderDefinition, _queryGeneratorMock);

            _queryManagerMock = MockRepository.GenerateStrictMock <IQueryManager> ();
            var transaction = ClientTransactionObjectMother.CreateTransactionWithQueryManager <ClientTransaction> (_queryManagerMock);

            _transactionScope = transaction.EnterDiscardingScope();

            _someQueryModel = QueryModelObjectMother.Create();
            MockRepository.GenerateStub <IQuery>();
            _someOrder = DomainObjectMother.CreateFakeObject <Order>();

            _scalarExecutableQueryMock     = MockRepository.GenerateStrictMock <IExecutableQuery <int> >();
            _collectionExecutableQueryMock = MockRepository.GenerateStrictMock <IExecutableQuery <IEnumerable <Order> > > ();
        }