Esempio n. 1
0
        public void ResolveMemberAccess_OnEntityRefMemberExpression_NoOptimization()
        {
            var memberInfo = typeof(Cook).GetProperty("Substitution");
            var entityRefMemberExpression = SqlStatementModelObjectMother.CreateSqlEntityRefMemberExpression();

            _resolverMock
            .Stub(mock => mock.TryResolveOptimizedMemberExpression(entityRefMemberExpression, memberInfo))
            .Return(null);

            var fakeEntityExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook));

            _stageMock
            .Expect(
                mock =>
                mock.ResolveEntityRefMemberExpression(
                    Arg.Is(entityRefMemberExpression),
                    Arg <UnresolvedJoinInfo> .Matches(j =>
                                                      j.OriginatingEntity == entityRefMemberExpression.OriginatingEntity &&
                                                      j.MemberInfo == entityRefMemberExpression.MemberInfo &&
                                                      j.Cardinality == JoinCardinality.One),
                    Arg.Is(_mappingResolutionContext)))
            .Return(fakeEntityExpression);

            var fakeResult = Expression.Constant(0);

            _resolverMock
            .Expect(mock => mock.ResolveMemberExpression(fakeEntityExpression, memberInfo))
            .Return(fakeResult);

            var result = MemberAccessResolver.ResolveMemberAccess(entityRefMemberExpression, memberInfo, _resolverMock, _stageMock, _mappingResolutionContext);

            _stageMock.VerifyAllExpectations();
            _resolverMock.VerifyAllExpectations();
            Assert.That(result, Is.SameAs(fakeResult));
        }
        public void VisitSqlEntityRefMemberExpression_ResolveFlagFalse()
        {
            var entityRefMemberExpression = SqlStatementModelObjectMother.CreateSqlEntityRefMemberExpression();

            var visitor = CreateVisitor(false);
            var result  = visitor.Visit(entityRefMemberExpression);

            Assert.That(result, Is.SameAs(entityRefMemberExpression));
        }
Esempio n. 3
0
        public void ResolveMemberAccess_OnEntityRefMemberExpression_WithSuccessfulOptimization()
        {
            var memberInfo = typeof(Cook).GetProperty("Substitution");
            var entityRefMemberExpression = SqlStatementModelObjectMother.CreateSqlEntityRefMemberExpression();

            var fakeResolvedExpression = ExpressionHelper.CreateExpression();

            _resolverMock
            .Expect(mock => mock.TryResolveOptimizedMemberExpression(entityRefMemberExpression, memberInfo))
            .Return(fakeResolvedExpression);

            var result = MemberAccessResolver.ResolveMemberAccess(entityRefMemberExpression, memberInfo, _resolverMock, _stageMock, _mappingResolutionContext);

            _resolverMock.VerifyAllExpectations();
            _stageMock.AssertWasNotCalled(
                mock => mock.ResolveEntityRefMemberExpression(
                    Arg <SqlEntityRefMemberExpression> .Is.Anything, Arg <IJoinInfo> .Is.Anything, Arg <IMappingResolutionContext> .Is.Anything));
            Assert.That(result, Is.SameAs(fakeResolvedExpression));
        }
        public void VisitSqlEntityRefMemberExpression_ResolveFlagTrue()
        {
            var entityRefMemberExpression = SqlStatementModelObjectMother.CreateSqlEntityRefMemberExpression();

            var fakeResolvedExpression = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression();

            _stageMock
            .Expect(
                mock => mock.ResolveEntityRefMemberExpression(
                    Arg.Is(entityRefMemberExpression),
                    Arg <UnresolvedJoinInfo> .Matches(
                        ji =>
                        ji.OriginatingEntity == entityRefMemberExpression.OriginatingEntity && ji.MemberInfo == entityRefMemberExpression.MemberInfo &&
                        ji.Cardinality == JoinCardinality.One),
                    Arg.Is(_mappingResolutionContext)))
            .Return(fakeResolvedExpression);

            var visitor = CreateVisitor(true);
            var result  = visitor.Visit(entityRefMemberExpression);

            Assert.That(result, Is.SameAs(fakeResolvedExpression));
        }