Beispiel #1
0
        public void CreateFetchQueryModel()
        {
            // expected: from <x> in (from sd in ExpressionHelper.CreateKitchenQueryable() select sd.Cook).Take (1)
            //           select <x>

            var fetchRequestPartialMock = new MockRepository().PartialMock <FetchRequestBase> (_assistantsMember);

            QueryModel modifiedQueryModel = null;

            fetchRequestPartialMock
            .Expect(mock => PrivateInvoke.InvokeNonPublicMethod(mock, "ModifyFetchQueryModel", Arg <QueryModel> .Is.Anything))
            .WhenCalled(mi => modifiedQueryModel = (QueryModel)mi.Arguments[0]);

            fetchRequestPartialMock.Replay();

            var fetchQueryModel = fetchRequestPartialMock.CreateFetchQueryModel(_cookFromKitchenQueryModel);

            fetchRequestPartialMock.VerifyAllExpectations();
            Assert.That(modifiedQueryModel, Is.SameAs(fetchQueryModel));

            Assert.That(fetchQueryModel.MainFromClause.FromExpression, Is.InstanceOf(typeof(SubQueryExpression)));

            var subQueryExpression = (SubQueryExpression)fetchQueryModel.MainFromClause.FromExpression;

            Assert.That(subQueryExpression.QueryModel, Is.SameAs(_cookFromKitchenQueryModel));

            Assert.That(_cookFromKitchenQueryModel.BodyClauses.Count, Is.EqualTo(0));
            Assert.That(((QuerySourceReferenceExpression)fetchQueryModel.SelectClause.Selector).ReferencedQuerySource,
                        Is.SameAs(fetchQueryModel.MainFromClause));

            Assert.That(fetchQueryModel.ResultTypeOverride, Is.Null);
        }