public void TestSqlConnectionAverageViaTableNameTypedResultViaQueryGroup() { // Setup var tables = Helper.CreateIdentityTables(10); var fields = new[] { new QueryField(nameof(IdentityTable.ColumnInt), Operation.GreaterThan, 5), new QueryField(nameof(IdentityTable.ColumnInt), Operation.LessThanOrEqual, 8) }; var queryGroup = new QueryGroup(fields); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <double?>(ClassMappedNameCache.Get <IdentityTable>(), new Field("ColumnInt"), queryGroup); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt > 5 && t.ColumnInt <= 8).Average(t => t.ColumnInt), result); } }
public void TestSqlServerConnectionAverageWithoutExpression() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var result = connection.Average <CompleteTable>(e => e.ColumnInt, (object)null); // Assert Assert.AreEqual(tables.Average(e => e.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlServerConnectionAverageWithExpression() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var ids = new[] { tables.First().Id, tables.Last().Id }; var result = connection.Average <CompleteTable>(e => e.ColumnInt, e => ids.Contains(e.Id)); // Assert Assert.AreEqual(tables.Where(e => ids.Contains(e.Id)).Average(e => e.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlServerConnectionAverageViaTableNameWithoutExpression() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var result = connection.Average(ClassMappedNameCache.Get <CompleteTable>(), Field.Parse <CompleteTable>(e => e.ColumnInt).First(), (object)null); // Assert Assert.AreEqual(tables.Average(e => e.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlServerConnectionAverageViaTableNameWithExpression() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new SqlConnection(Database.ConnectionString)) { // Act var ids = new[] { tables.First().Id, tables.Last().Id }; var result = connection.Average(ClassMappedNameCache.Get <CompleteTable>(), Field.Parse <CompleteTable>(e => e.ColumnInt).First(), new QueryField("Id", Operation.In, ids)); // Assert Assert.AreEqual(tables.Where(e => ids.Contains(e.Id)).Average(e => e.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlConnectionAverageViaDynamic() { // Setup var tables = Helper.CreateIdentityTables(10); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <IdentityTable>(e => e.ColumnInt, new { ColumnInt = 1 }); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt == 1).Average(t => t.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlConnectionAverageWithoutCondition() { // Setup var tables = Helper.CreateIdentityTables(10); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <IdentityTable>(e => e.ColumnInt, (object)null); // Assert Assert.AreEqual(tables.Average(t => t.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlConnectionAverageTypedResultViaExpression() { // Setup var tables = Helper.CreateIdentityTables(10); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <IdentityTable, double?>(e => e.ColumnInt, item => item.ColumnInt > 5 && item.ColumnInt <= 8); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt > 5 && t.ColumnInt <= 8).Average(t => t.ColumnInt), result); } }
public void TestSqlConnectionAverageViaQueryField() { // Setup var tables = Helper.CreateIdentityTables(10); var field = new QueryField(nameof(IdentityTable.ColumnInt), Operation.GreaterThan, 5); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <IdentityTable>(e => e.ColumnInt, field); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt > 5).Average(t => t.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlConnectionAverageViaTableNameTypedResultViaDynamic() { // Setup var tables = Helper.CreateIdentityTables(10); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <double?>(ClassMappedNameCache.Get <IdentityTable>(), new Field("ColumnInt"), new { ColumnInt = 1 }); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt == 1).Average(t => t.ColumnInt), result); } }
public void TestSqlConnectionAverageViaTableNameWithoutCondition() { // Setup var tables = Helper.CreateIdentityTables(10); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average(ClassMappedNameCache.Get <IdentityTable>(), new Field("ColumnInt"), (object)null); // Assert Assert.AreEqual(tables.Average(t => t.ColumnInt), Convert.ToDouble(result)); } }
public void TestSqlConnectionAverageViaTableNameViaQueryField() { // Setup var tables = Helper.CreateIdentityTables(10); var field = new QueryField(nameof(IdentityTable.ColumnInt), Operation.GreaterThan, 5); using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average(ClassMappedNameCache.Get <IdentityTable>(), new Field("ColumnInt"), field); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt > 5).Average(t => t.ColumnInt), result); } }
public void TestSqlConnectionAverageTypedResultViaQueryFields() { // Setup var tables = Helper.CreateIdentityTables(10); var fields = new[] { new QueryField(nameof(IdentityTable.ColumnInt), Operation.GreaterThan, 5), new QueryField(nameof(IdentityTable.ColumnInt), Operation.LessThanOrEqual, 8) }; using (var connection = new SqlConnection(Database.ConnectionStringForRepoDb)) { // Act connection.InsertAll(tables); // Act var result = connection.Average <IdentityTable, double?>(e => e.ColumnInt, fields); // Assert Assert.AreEqual(tables.Where(t => t.ColumnInt > 5 && t.ColumnInt <= 8).Average(t => t.ColumnInt), result); } }