-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #495 from TortugaResearch/Chain-4.3
Chain 4.3
- Loading branch information
Showing
3,358 changed files
with
795,906 additions
and
7,514 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
Tortuga.Chain/Shared/Tests/Aggregation/ComplexAggregateTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
using Tests.Models; | ||
using Tortuga.Chain.Aggregates; | ||
|
||
namespace Tests.Aggregate; | ||
|
||
[TestClass] | ||
public class ComplexAggregateTests : TestBase | ||
{ | ||
const string Filter = "EmployeeKey < 100"; //So we don't overlfow on Sum/Avg | ||
|
||
[DataTestMethod, TablesAndViewData(DataSourceGroup.All)] | ||
public void MinMaxAvg(string dataSourceName, DataSourceType mode, string tableName) | ||
{ | ||
var dataSource = DataSource(dataSourceName, mode); | ||
|
||
try | ||
{ | ||
//PostgreSQL is case sensitive, so we need to ensure we're using the correct name. | ||
var table = dataSource.DatabaseMetadata.GetTableOrViewFromClass<Employee>(); | ||
var columnName = table.Columns["EmployeeKey"].SqlName; | ||
|
||
var result = dataSource.From<Employee>(Filter).AsAggregate( | ||
new AggregateColumn(AggregateType.Min, columnName, "MinEmployeeKey"), | ||
new AggregateColumn(AggregateType.Max, columnName, "MaxEmployeeKey"), | ||
new AggregateColumn(AggregateType.Count, columnName, "CountEmployeeKey") | ||
).ToRow().Execute(); | ||
|
||
Assert.IsTrue(result.ContainsKey("MinEmployeeKey")); | ||
Assert.IsTrue(result.ContainsKey("MaxEmployeeKey")); | ||
Assert.IsTrue(result.ContainsKey("CountEmployeeKey")); | ||
} | ||
finally | ||
{ | ||
Release(dataSource); | ||
} | ||
} | ||
|
||
[DataTestMethod, TablesAndViewData(DataSourceGroup.All)] | ||
public void MinMaxAvg_WithGroup(string dataSourceName, DataSourceType mode, string tableName) | ||
{ | ||
var dataSource = DataSource(dataSourceName, mode); | ||
try | ||
{ | ||
//PostgreSQL is case sensitive, so we need to ensure we're using the correct name. | ||
var table = dataSource.DatabaseMetadata.GetTableOrViewFromClass<Employee>(); | ||
var ekColumnName = table.Columns["EmployeeKey"].SqlName; | ||
var gColumnName = table.Columns["Gender"].SqlName; | ||
|
||
var result = dataSource.From<Employee>(Filter).AsAggregate( | ||
new AggregateColumn(AggregateType.Min, ekColumnName, "MinEmployeeKey"), | ||
new AggregateColumn(AggregateType.Max, ekColumnName, "MaxEmployeeKey"), | ||
new AggregateColumn(AggregateType.Count, ekColumnName, "CountEmployeeKey"), | ||
new GroupByColumn(gColumnName, "Gender"), | ||
new CustomAggregateColumn($"Max({ekColumnName}) - Min({ekColumnName})", "Range") | ||
).ToTable().Execute(); | ||
|
||
Assert.IsTrue(result.ColumnNames.Contains("MinEmployeeKey")); | ||
Assert.IsTrue(result.ColumnNames.Contains("MaxEmployeeKey")); | ||
Assert.IsTrue(result.ColumnNames.Contains("CountEmployeeKey")); | ||
Assert.IsTrue(result.ColumnNames.Contains("Gender")); | ||
Assert.IsTrue(result.ColumnNames.Contains("Range")); | ||
} | ||
finally | ||
{ | ||
Release(dataSource); | ||
} | ||
} | ||
|
||
[DataTestMethod, TablesAndViewData(DataSourceGroup.All)] | ||
public void AggregateObject(string dataSourceName, DataSourceType mode, string tableName) | ||
{ | ||
var dataSource = DataSource(dataSourceName, mode); | ||
try | ||
{ | ||
//PostgreSQL is case sensitive, so we need to ensure we're using the correct name. | ||
var table = dataSource.DatabaseMetadata.GetTableOrViewFromClass<Employee>(); | ||
var ekColumnName = table.Columns["EmployeeKey"].SqlName; | ||
var gColumnName = table.Columns["Gender"].SqlName; | ||
|
||
var result = dataSource.From<Employee>(Filter).AsAggregate<EmployeeReport>().ToObject().Execute(); | ||
} | ||
finally | ||
{ | ||
Release(dataSource); | ||
} | ||
} | ||
|
||
[DataTestMethod, TablesAndViewData(DataSourceGroup.All)] | ||
public void AggregateObject_WithGroup(string dataSourceName, DataSourceType mode, string tableName) | ||
{ | ||
var dataSource = DataSource(dataSourceName, mode); | ||
try | ||
{ | ||
//PostgreSQL is case sensitive, so we need to ensure we're using the correct name. | ||
var table = dataSource.DatabaseMetadata.GetTableOrViewFromClass<Employee>(); | ||
var ekColumnName = table.Columns["EmployeeKey"].SqlName; | ||
var gColumnName = table.Columns["Gender"].SqlName; | ||
|
||
var result = dataSource.From<Employee>(Filter).AsAggregate<GroupedEmployeeReport>().ToCollection().Execute(); | ||
} | ||
finally | ||
{ | ||
Release(dataSource); | ||
} | ||
} | ||
|
||
public class GroupedEmployeeReport | ||
{ | ||
#if POSTGRESQL | ||
const string ekColumnName = "employeekey"; | ||
#else | ||
const string ekColumnName = "EmployeeKey"; | ||
#endif | ||
|
||
[AggregateColumn(AggregateType.Min, "EmployeeKey")] | ||
public int MinEmployeeKey { get; set; } | ||
|
||
[AggregateColumn(AggregateType.Max, "EmployeeKey")] | ||
public int MaxEmployeeKey { get; set; } | ||
|
||
[AggregateColumn(AggregateType.Count, "EmployeeKey")] | ||
public int CountEmployeeKey { get; set; } | ||
|
||
[GroupByColumn] | ||
public string Gender { get; set; } | ||
|
||
[CustomAggregateColumn($"Max({ekColumnName}) - Min({ekColumnName})")] | ||
public int Range { get; set; } | ||
} | ||
|
||
public class EmployeeReport | ||
{ | ||
[AggregateColumn(AggregateType.Min, "EmployeeKey")] | ||
public int MinEmployeeKey { get; set; } | ||
|
||
[AggregateColumn(AggregateType.Max, "EmployeeKey")] | ||
public int MaxEmployeeKey { get; set; } | ||
|
||
[AggregateColumn(AggregateType.Count, "EmployeeKey")] | ||
public int CountEmployeeKey { get; set; } | ||
} | ||
} |
Oops, something went wrong.