public void VisitNewExpression_ForObjectID_GeneratesNullCheckInInMemoryProjection()
        {
            var constructorInfo = typeof(ObjectID).GetConstructor(new[] { typeof(string), typeof(object) });

            Assertion.IsNotNull(constructorInfo);
            var newObjectIDExpression = Expression.New(
                constructorInfo,
                new SqlColumnDefinitionExpression(typeof(string), "t0", "CustomerClassID", false),
                Expression.Convert(new SqlColumnDefinitionExpression(typeof(Guid), "t0", "CustomerID", false), typeof(object)));
            var compoundExpression = NamedExpression.CreateNewExpressionWithNamedArguments(newObjectIDExpression);

            ExtendedSqlGeneratingOuterSelectExpressionVisitor.GenerateSql(compoundExpression, _commandBuilder, _stageMock, _someSetOperationsMode);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[t0].[CustomerClassID] AS [m0],[t0].[CustomerID] AS [m1]"));

            Expression <Func <IDatabaseResultRow, ObjectID> > expectedInMemoryProjection =
                row => ExtendedSqlGeneratingOuterSelectExpressionVisitor.GetObjectIDOrNull(
                    row.GetValue <string> (new ColumnID("m0", 0)),
                    row.GetValue <object> (new ColumnID("m1", 1)));
            var expectedInMemoryProjectionBody = PartialEvaluatingExpressionVisitor.EvaluateIndependentSubtrees(
                expectedInMemoryProjection.Body,
                new TestEvaluatableExpressionFilter());

            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedInMemoryProjectionBody, _commandBuilder.GetInMemoryProjectionBody());
        }
        public void GenerateTextForOuterSelectExpression_UsesExtendedVisitor()
        {
            var constructorInfo = typeof(ObjectID).GetConstructor(new[] { typeof(string), typeof(object) });

            Assertion.IsNotNull(constructorInfo);
            var newObjectIDExpression = Expression.New(
                constructorInfo,
                new SqlColumnDefinitionExpression(typeof(string), "t0", "CustomerClassID", false),
                Expression.Convert(new SqlColumnDefinitionExpression(typeof(Guid), "t0", "CustomerID", false), typeof(object)));
            var compoundExpression = NamedExpression.CreateNewExpressionWithNamedArguments(newObjectIDExpression);

            var someSetOperationsMode = SetOperationsMode.StatementIsSetCombined;

            _stage.GenerateTextForOuterSelectExpression(_commandBuilder, compoundExpression, someSetOperationsMode);

            Assert.That(_commandBuilder.GetInMemoryProjectionBody().NodeType, Is.EqualTo(ExpressionType.Call));
            var getObjectIDOrNullMethod =
                MemberInfoFromExpressionUtility.GetMethod(() => ExtendedSqlGeneratingOuterSelectExpressionVisitor.GetObjectIDOrNull(null, null));

            Assert.That(((MethodCallExpression)_commandBuilder.GetInMemoryProjectionBody()).Method, Is.EqualTo(getObjectIDOrNullMethod));
        }
        public void GetObjectIDOrNull_Null()
        {
            var result = ExtendedSqlGeneratingOuterSelectExpressionVisitor.GetObjectIDOrNull(DomainObjectIDs.Order1.ClassID, null);

            Assert.That(result, Is.Null);
        }
        public void GenerateSql_Collection()
        {
            var expression = Expression.Constant(new Order[] { });

            ExtendedSqlGeneratingOuterSelectExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock, _someSetOperationsMode);
        }