public void Can_Build_SelectCommand_From_SelectCommandBuilder_With_Or_Clause()
    {
        // Arrange
        var command = new SelectCommandBuilder();

        // Act
        var actual = command
                     .From("Table")
                     .Select("Field1", "Field2")
                     .Where("Field1 = @field1")
                     .Or("Field2 IS NOT NULL")
                     .AppendParameter("field1", "some value")
                     .Build();

        // Assert
        actual.CommandText.Should().Be("SELECT Field1, Field2 FROM Table WHERE Field1 = @field1 OR Field2 IS NOT NULL");
        actual.CommandParameters.Should().BeAssignableTo <IDictionary <string, object> >();
        var parameters = actual.CommandParameters as IDictionary <string, object>;

        if (parameters != null)
        {
            parameters.Should().HaveCount(1);
            parameters.First().Key.Should().Be("field1");
            parameters.First().Value.Should().Be("some value");
        }
    }
Пример #2
0
        public static SelectCommandBuilder Select(this IDataContext context, string table)
        {
            var builder = new SelectCommandBuilder(context);

            builder.From(table);

            return(builder);
        }
    public void Can_Build_SelectCommand_From_SelectCommandBuilder_Without_Fields()
    {
        // Arrange
        var command = new SelectCommandBuilder();

        // Act
        var actual = command
                     .From("Table")
                     .Build();

        // Assert
        actual.CommandText.Should().Be("SELECT * FROM Table");
    }
    public void Can_Build_SelectCommand_From_SelectCommandBuilder_With_CrossJoin_Clause()
    {
        // Arrange
        var command = new SelectCommandBuilder();

        // Act
        var actual = command
                     .From("Table")
                     .CrossJoin("Table2")
                     .Select("Table.Field1", "Table.Field2", "Table2.Field3")
                     .Build();

        // Assert
        actual.CommandText.Should().Be("SELECT Table.Field1, Table.Field2, Table2.Field3 FROM Table CROSS JOIN Table2");
    }
    public void Can_Build_SelectCommand_From_SelectCommandBuilder_With_RightOuterJoin_Clause()
    {
        // Arrange
        var command = new SelectCommandBuilder();

        // Act
        var actual = command
                     .From("Table")
                     .RightOuterJoin("Table2 ON Table.Id = Table2.FkId")
                     .Select("Table.Field1", "Table.Field2", "Table2.Field3")
                     .Build();

        // Assert
        actual.CommandText.Should().Be("SELECT Table.Field1, Table.Field2, Table2.Field3 FROM Table RIGHT OUTER JOIN Table2 ON Table.Id = Table2.FkId");
    }
    public void Can_Build_SelectCommand_From_SelectCommandBuilder_With_OrderBy_Clause()
    {
        // Arrange
        var command = new SelectCommandBuilder();

        // Act
        var actual = command
                     .From("Table")
                     .Select("Field1", "Field2")
                     .OrderBy("Field1")
                     .Build();

        // Assert
        actual.CommandText.Should().Be("SELECT Field1, Field2 FROM Table ORDER BY Field1");
    }
    public void Can_Build_SelectCommand_From_SelectCommandBuilder_With_GroupBy_And_Having_Clauses()
    {
        // Arrange
        var command = new SelectCommandBuilder();

        // Act
        var actual = command
                     .From("Table")
                     .Select("Field1, Field2, COUNT(Field3)") // use single string, works as well
                     .GroupBy("Field3")
                     .Having("Field3 IS NOT NULL")
                     .Build();

        // Assert
        actual.CommandText.Should().Be("SELECT Field1, Field2, COUNT(Field3) FROM Table GROUP BY Field3 HAVING Field3 IS NOT NULL");
    }