Esempio n. 1
0
        public void GenerateSql_Collection_Grouping()
        {
            var expression = SqlStatementModelObjectMother.CreateSqlGroupingSelectExpression();

            SqlGeneratingSelectExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("@1"));
        }
Esempio n. 2
0
        public void GenerateTextForSelectExpression_CollectionInSelectProjection_StringsNotDetectedAsCollections()
        {
            var expression = Expression.Constant("test");

            SqlGeneratingSelectExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("@1"));
        }
Esempio n. 3
0
        public void VisitNamedExpression_NameIsNotNull()
        {
            var columnExpression = new SqlColumnDefinitionExpression(typeof(string), "c", "Name", false);
            var expression       = new NamedExpression("test", columnExpression);

            SqlGeneratingSelectExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[c].[Name] AS [test]"));
        }
Esempio n. 4
0
        public void VisitSqlGroupingSelectExpression_WithoutAggregationExpressions()
        {
            var groupingExpression = new SqlGroupingSelectExpression(Expression.Constant("keyExpression"), Expression.Constant("elementExpression"));

            SqlGeneratingSelectExpressionVisitor.GenerateSql(groupingExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("@1"));
            Assert.That(_commandBuilder.GetCommandParameters()[0].Value, Is.EqualTo("keyExpression"));
        }
Esempio n. 5
0
        public void VisitSqlGroupingSelectExpression_WithAggregationExpressions_AndNames()
        {
            var groupingExpression = SqlGroupingSelectExpression.CreateWithNames(Expression.Constant("keyExpression"), Expression.Constant("elementExpression"));

            groupingExpression.AddAggregationExpressionWithName(Expression.Constant("aggregation1"));
            groupingExpression.AddAggregationExpressionWithName(Expression.Constant("aggregation2"));

            SqlGeneratingSelectExpressionVisitor.GenerateSql(groupingExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("@1 AS [key], @2 AS [a0], @3 AS [a1]"));
            Assert.That(_commandBuilder.GetCommandParameters()[0].Value, Is.EqualTo("keyExpression"));
            Assert.That(_commandBuilder.GetCommandParameters()[1].Value, Is.EqualTo("aggregation1"));
            Assert.That(_commandBuilder.GetCommandParameters()[2].Value, Is.EqualTo("aggregation2"));
        }
Esempio n. 6
0
        public void GenerateSql_VisitSqlEntityExpression_NamedEntity_StarColumn()
        {
            var sqlColumnListExpression = new SqlEntityDefinitionExpression(
                typeof(string),
                "t",
                "Test",
                e => e.GetColumn(typeof(int), "ID", true),
                new[]
            {
                new SqlColumnDefinitionExpression(typeof(string), "t", "*", false)
            });

            SqlGeneratingSelectExpressionVisitor.GenerateSql(sqlColumnListExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[t].*"));
        }
Esempio n. 7
0
        public void GenerateSql_VisitSqlEntityExpression_NamedEntity_ReferencingNamed()
        {
            var referencedEntity = new SqlEntityDefinitionExpression(
                typeof(Cook),
                "c",
                "Cook",
                e => e,
                new[]
            {
                new SqlColumnDefinitionExpression(typeof(string), "t", "Name", false),
                new SqlColumnDefinitionExpression(typeof(string), "t", "City", false)
            });
            var entityExpression = new SqlEntityReferenceExpression(typeof(Cook), "c", "ref", referencedEntity);

            SqlGeneratingSelectExpressionVisitor.GenerateSql(entityExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[c].[Cook_Name] AS [ref_Name],[c].[Cook_City] AS [ref_City]"));
        }
Esempio n. 8
0
        public void GenerateSql_VisitSqlEntityExpression_UnnamedEntity()
        {
            var sqlColumnListExpression = new SqlEntityDefinitionExpression(
                typeof(string),
                "t",
                null,
                e => e,
                new[]
            {
                new SqlColumnDefinitionExpression(typeof(string), "t", "ID", true),
                new SqlColumnDefinitionExpression(typeof(string), "t", "Name", false),
                new SqlColumnDefinitionExpression(typeof(string), "t", "City", false)
            });

            SqlGeneratingSelectExpressionVisitor.GenerateSql(
                sqlColumnListExpression, _commandBuilder, _stageMock);

            Assert.That(_commandBuilder.GetCommandText(), Is.EqualTo("[t].[ID],[t].[Name],[t].[City]"));
        }
Esempio n. 9
0
        public void GenerateSql_Collection()
        {
            var expression = Expression.Constant(new Cook[] { });

            SqlGeneratingSelectExpressionVisitor.GenerateSql(expression, _commandBuilder, _stageMock);
        }