public void AverageThrowsArgumentExceptionForNullColumnAlias() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty); var exception = Assert.Throws<ArgumentException>( () => sqlBuilder.Average("Column", null)); Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("columnAlias"), exception.Message); }
public void SelectAverageWithSqlCharacters() { var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, (string)null); var sqlQuery = sqlBuilder .Average("CreditLimit") .From(typeof(Customer)) .Where("CustomerStatusId").IsEqualTo(CustomerStatus.Active) .ToSqlQuery(); Assert.Equal("SELECT AVG([CreditLimit]) AS CreditLimit FROM [Sales].[Customers] WHERE ([CustomerStatusId] = @p0)", sqlQuery.CommandText); Assert.Equal(1, sqlQuery.Arguments.Count); Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType); Assert.Equal(CustomerStatus.Active, sqlQuery.Arguments[0].Value); }
public void SelectAverageWithOtherColumn() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Id"); var sqlQuery = sqlBuilder .Average("CreditLimit") .From(typeof(Customer)) .Where("CustomerStatusId").IsEqualTo(CustomerStatus.Active) .GroupBy("CustomerStatusId") .ToSqlQuery(); Assert.Equal("SELECT Id,AVG(CreditLimit) AS CreditLimit FROM Sales.Customers WHERE (CustomerStatusId = ?) GROUP BY CustomerStatusId", sqlQuery.CommandText); Assert.Equal(1, sqlQuery.Arguments.Count); Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType); Assert.Equal(CustomerStatus.Active, sqlQuery.Arguments[0].Value); }
public void SelectAverageWithAlias() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, (string)null); var sqlQuery = sqlBuilder .Average("CreditLimit", columnAlias: "AverageCreditLimit") .From(typeof(Customer)) .Where("CustomerStatusId").IsEqualTo(CustomerStatus.Active) .ToSqlQuery(); Assert.Equal("SELECT AVG(CreditLimit) AS AverageCreditLimit FROM Sales.Customers WHERE (CustomerStatusId = ?)", sqlQuery.CommandText); Assert.Equal(1, sqlQuery.Arguments.Count); Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType); Assert.Equal(CustomerStatus.Active, sqlQuery.Arguments[0].Value); }