Esempio n. 1
0
        public void VisitUnaryExpression_NotSupported()
        {
            var unaryExpression = Expression.TypeAs(Expression.Constant("1"), typeof(string));

            SqlGeneratingExpressionVisitor.GenerateSql(
                unaryExpression, _commandBuilder, _stageMock);
        }
Esempio n. 2
0
        public void GenerateSql_UnsupportedExpression()
        {
            var unknownExpression = new CustomExpression(typeof(int));

            SqlGeneratingExpressionVisitor.GenerateSql(
                unknownExpression, _commandBuilder, _stageMock);
        }
Esempio n. 3
0
        public void NumberExpression()
        {
            var ordering1 = new Ordering(Expression.Constant("order1"), OrderingDirection.Asc);
            var ordering2 = new Ordering(Expression.Constant("order2"), OrderingDirection.Desc);
            var sqlRowNumberRÉxpression =
                new SqlRowNumberExpression(
                    new[]
            {
                ordering1,
                ordering2
            });

            _stageMock
            .Expect(mock => mock.GenerateTextForOrdering(_commandBuilder, ordering1))
            .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("order1 ASC"));
            _stageMock
            .Expect(mock => mock.GenerateTextForOrdering(_commandBuilder, ordering2))
            .WhenCalled(mi => ((SqlCommandBuilder)mi.Arguments[0]).Append("order2 DESC"));
            _stageMock.Replay();

            SqlGeneratingExpressionVisitor.GenerateSql(sqlRowNumberRÉxpression, _commandBuilder, _stageMock);

            _stageMock.VerifyAllExpectations();
            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("ROW_NUMBER() OVER (ORDER BY order1 ASC, order2 DESC)"));
        }
Esempio n. 4
0
        public void VisitSqlConvertExpression()
        {
            var sqlConvertExpression = new SqlConvertExpression(typeof(string), Expression.Constant("1"));

            SqlGeneratingExpressionVisitor.GenerateSql(sqlConvertExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("CONVERT(NVARCHAR(MAX), @1)"));
        }
Esempio n. 5
0
        public void VisitSqlLiteralExpression_Double()
        {
            var expression = new SqlLiteralExpression(1.1);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("1.1"));
        }
Esempio n. 6
0
        public void VisitSqlLikeExpression()
        {
            var sqlInExpression = new SqlLikeExpression(new SqlLiteralExpression(1), new SqlLiteralExpression(2), new SqlLiteralExpression(@"\"));

            SqlGeneratingExpressionVisitor.GenerateSql(sqlInExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo(@"1 LIKE 2 ESCAPE '\'"));
        }
Esempio n. 7
0
        public void GenerateSql_VisitSqlColumnExpressionWithStar()
        {
            var sqlColumnExpression = new SqlColumnDefinitionExpression(typeof(Cook), "c", "*", false);

            SqlGeneratingExpressionVisitor.GenerateSql(sqlColumnExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[c].*"));
        }
Esempio n. 8
0
        public void VisitSqlCustomTextGeneratorExpression()
        {
            var expression = new TestableSqlCustomTextGeneratorExpression(typeof(string));

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("TestableSqlCustomTextGeneratorExpression"));
        }
Esempio n. 9
0
        public void GenerateSql_VisitSqlColumnDefinitionExpression()
        {
            var sqlColumnExpression = new SqlColumnDefinitionExpression(typeof(int), "s", "ID", false);

            SqlGeneratingExpressionVisitor.GenerateSql(sqlColumnExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[s].[ID]"));
        }
Esempio n. 10
0
        public void VisitConstantExpression_StringParameter()
        {
            var expression = Expression.Constant("Test");

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandParameters().Length, Is.EqualTo(1));
            Assert.That(_commandBuilder.GetCommandParameters()[0].Value, Is.EqualTo("Test"));
        }
Esempio n. 11
0
        public void VisitLiteralExpression()
        {
            var expression = new SqlLiteralExpression(5);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("5"));
            Assert.That(_commandBuilder.GetCommandParameters(), Is.Empty);
        }
Esempio n. 12
0
        public void VisitConstantExpression_NullValue()
        {
            var expression = Expression.Constant(null);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandParameters().Length, Is.EqualTo(0));
            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("NULL"));
        }
Esempio n. 13
0
        public void GenerateSql_VisitSqlColumnReferenceExpression_WithNamedEntity()
        {
            var entityExpression    = SqlStatementModelObjectMother.CreateSqlEntityDefinitionExpression(typeof(Cook), "Test");
            var sqlColumnExpression = new SqlColumnReferenceExpression(typeof(int), "s", "ID", false, entityExpression);

            SqlGeneratingExpressionVisitor.GenerateSql(sqlColumnExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[s].[Test_ID]"));
        }
Esempio n. 14
0
        public void GenerateSql_BoolExpression_PredicateSemantics()
        {
            var boolExpression = Expression.Equal(Expression.Constant("hugo"), Expression.Constant("sepp"));

            SqlGeneratingExpressionVisitor.GenerateSql(
                boolExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("(@1 = @2)"));
        }
Esempio n. 15
0
        public void VisitAggregationExpression_Count()
        {
            var columnExpression = new SqlColumnDefinitionExpression(typeof(string), "c", "Name", false);
            var expression       = new AggregationExpression(typeof(int), columnExpression, AggregationModifier.Count);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("COUNT(*)"));
        }
Esempio n. 16
0
        public void VisitSqlCollectionExpression_Empty()
        {
            var items = new Expression[0];
            var sqlCollectionExpression = new SqlCollectionExpression(typeof(List <object>), items);

            SqlGeneratingExpressionVisitor.GenerateSql(sqlCollectionExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("(SELECT NULL WHERE 1 = 0)"));
        }
Esempio n. 17
0
        public void VisitSqlConvertedBooleanExpression()
        {
            var expression = new SqlConvertedBooleanExpression(Expression.Constant(1));

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("@1"));
            Assert.That(_commandBuilder.GetCommandParameters()[0].Value, Is.EqualTo(1));
        }
Esempio n. 18
0
        public void VisitNamedExpression()
        {
            var columnExpression = new SqlColumnDefinitionExpression(typeof(string), "c", "Name", false);
            var expression       = new NamedExpression("xx", columnExpression);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[c].[Name]"));
        }
Esempio n. 19
0
        public void VisitAggregationExpression_Average()
        {
            var columnExpression = new NamedExpression(null, new SqlColumnDefinitionExpression(typeof(string), "c", "Name", false));
            var expression       = new AggregationExpression(typeof(double), columnExpression, AggregationModifier.Average);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("AVG([c].[Name])"));
        }
Esempio n. 20
0
        public void VisitSqlFunctionExpression()
        {
            var sqlFunctionExpression = new SqlFunctionExpression(typeof(int), "LENFUNC", new SqlLiteralExpression("test"), new SqlLiteralExpression(1));

            SqlGeneratingExpressionVisitor.GenerateSql(
                sqlFunctionExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("LENFUNC('test', 1)"));
        }
Esempio n. 21
0
        public void VisitSqlIsNotNullExpression()
        {
            var expression             = Expression.Constant("test");
            var sqlIsNotNullExpression = new SqlIsNotNullExpression(expression);

            SqlGeneratingExpressionVisitor.GenerateSql(
                sqlIsNotNullExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("(@1 IS NOT NULL)"));
        }
Esempio n. 22
0
        public void VisitSqlCollectionExpression()
        {
            var items = new Expression[] { Expression.Constant(7), new SqlLiteralExpression("Hello"), new SqlLiteralExpression(12) };
            var sqlCollectionExpression = new SqlCollectionExpression(typeof(List <object>), items);

            SqlGeneratingExpressionVisitor.GenerateSql(sqlCollectionExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("(@1, 'Hello', 12)"));
            Assert.That(_commandBuilder.GetCommandParameters(), Is.EqualTo(new[] { new CommandParameter("@1", 7) }));
        }
Esempio n. 23
0
        public void VisitSqlEntityConstantExpression()
        {
            var entityConstant = new SqlEntityConstantExpression(typeof(Cook), new Cook(), Expression.Constant(0));

            Assert.That(
                () => SqlGeneratingExpressionVisitor.GenerateSql(entityConstant, _commandBuilder, _stageMock),
                Throws.TypeOf <NotSupportedException> ().With.Message.EqualTo(
                    "It is not supported to use a constant entity object in any other context than to compare it with another entity. "
                    + "Expression: ENTITY(0) (of type: 'Remotion.Linq.SqlBackend.UnitTests.TestDomain.Cook')."));
        }
Esempio n. 24
0
        public void VisitExistsExpression()
        {
            var expression = new SqlExistsExpression(Expression.Constant("test"));

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            var result = _commandBuilder.GetCommandText();

            Assert.That(result, Is.EqualTo("EXISTS(@1)"));
        }
Esempio n. 25
0
        public void VisitUnaryExpression_UnaryNot()
        {
            var unaryNotExpression = Expression.Not(Expression.Equal(Expression.Constant("hugo"), Expression.Constant("hugo")));

            SqlGeneratingExpressionVisitor.GenerateSql(
                unaryNotExpression, _commandBuilder, _stageMock);
            var result = _commandBuilder.GetCommandText();

            Assert.That(result, Is.EqualTo("NOT (@1 = @2)"));
        }
Esempio n. 26
0
        public void VisitUnaryExpression_UnaryPlus()
        {
            var unaryNotExpression = Expression.UnaryPlus(Expression.Constant(1));

            SqlGeneratingExpressionVisitor.GenerateSql(
                unaryNotExpression, _commandBuilder, _stageMock);
            var result = _commandBuilder.GetCommandText();

            Assert.That(result, Is.EqualTo("+@1"));
        }
Esempio n. 27
0
        public void VisitUnaryExpression_ConvertChecked()
        {
            var unaryNotExpression = Expression.ConvertChecked(Expression.Constant(1), typeof(double));

            SqlGeneratingExpressionVisitor.GenerateSql(
                unaryNotExpression, _commandBuilder, _stageMock);
            var result = _commandBuilder.GetCommandText();

            Assert.That(result, Is.EqualTo("@1"));
        }
Esempio n. 28
0
        public void VisitSqlLiteralExpression_Double_CultureAgnostic()
        {
            var expression = new SqlLiteralExpression(1.1);

            Assert.That(expression.Value.ToString(), Is.Not.EqualTo("1.1"));

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("1.1"));
        }
Esempio n. 29
0
        public void VisitSqlLengthExpression_Char()
        {
            var innnerExpression = Expression.Constant('t');
            var expression       = new SqlLengthExpression(innnerExpression);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("(LEN((@1 + '#')) - 1)"));
            Assert.That(_commandBuilder.GetCommandParameters()[0].Value, Is.EqualTo('t'));
        }
Esempio n. 30
0
        public void VisitSqlCaseExpression_NoElse()
        {
            var case1      = new SqlCaseExpression.CaseWhenPair(new SqlCustomTextExpression("test1", typeof(bool)), new SqlCustomTextExpression("value1", typeof(int)));
            var case2      = new SqlCaseExpression.CaseWhenPair(new SqlCustomTextExpression("test2", typeof(bool)), new SqlCustomTextExpression("value2", typeof(int)));
            var expression = new SqlCaseExpression(typeof(int?), new[] { case1, case2 }, null);

            SqlGeneratingExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("CASE WHEN test1 THEN value1 WHEN test2 THEN value2 END"));
        }