@@ -51,6 +51,25 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
5151 }
5252 }
5353
54+ func testCountSuccess_UnifiedEndpoint( ) async throws {
55+ let result = try await repository ( ) . aggregate (
56+ function: . count,
57+ predicate: NSPredicate ( value: true ) ,
58+ entityDesc: ManagedMovie . entity ( ) ,
59+ attributeDesc: XCTUnwrap (
60+ ManagedMovie . entity ( ) . attributesByName. values
61+ . first ( where: { $0. name == " boxOffice " } )
62+ ) ,
63+ as: Double . self
64+ )
65+ switch result {
66+ case let . success( value) :
67+ XCTAssertEqual ( value, 5 , " Result value (count) should equal number of movies. " )
68+ case . failure:
69+ XCTFail ( " Not expecting failure " )
70+ }
71+ }
72+
5473 func testCountSubscription( ) async throws {
5574 let task = Task {
5675 var resultCount = 0
@@ -128,6 +147,25 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
128147 }
129148 }
130149
150+ func testSumSuccess_UnifiedEndpoint( ) async throws {
151+ let result = try await repository ( ) . aggregate (
152+ function: . sum,
153+ predicate: NSPredicate ( value: true ) ,
154+ entityDesc: ManagedMovie . entity ( ) ,
155+ attributeDesc: XCTUnwrap (
156+ ManagedMovie . entity ( ) . attributesByName. values
157+ . first ( where: { $0. name == " boxOffice " } )
158+ ) ,
159+ as: Decimal . self
160+ )
161+ switch result {
162+ case let . success( value) :
163+ XCTAssertEqual ( value, 150 , " Result value (sum) should equal number of movies. " )
164+ case . failure:
165+ XCTFail ( " Not expecting failure " )
166+ }
167+ }
168+
131169 func testSumSubscription( ) async throws {
132170 let task = Task {
133171 var resultCount = 0
@@ -219,6 +257,29 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
219257 }
220258 }
221259
260+ func testAverageSuccess_UnifiedEndpoint( ) async throws {
261+ let result = try await repository ( ) . aggregate (
262+ function: . average,
263+ predicate: NSPredicate ( value: true ) ,
264+ entityDesc: ManagedMovie . entity ( ) ,
265+ attributeDesc: XCTUnwrap (
266+ ManagedMovie . entity ( ) . attributesByName. values
267+ . first ( where: { $0. name == " boxOffice " } )
268+ ) ,
269+ as: Decimal . self
270+ )
271+ switch result {
272+ case let . success( value) :
273+ XCTAssertEqual (
274+ value,
275+ 30 ,
276+ " Result value should equal average of movies box office. "
277+ )
278+ case . failure:
279+ XCTFail ( " Not expecting failure " )
280+ }
281+ }
282+
222283 func testAverageSubscription( ) async throws {
223284 let task = Task {
224285 var resultCount = 0
@@ -318,6 +379,29 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
318379 }
319380 }
320381
382+ func testMinSuccess_UnifiedEndpoint( ) async throws {
383+ let result = try await repository ( ) . aggregate (
384+ function: . min,
385+ predicate: NSPredicate ( value: true ) ,
386+ entityDesc: ManagedMovie . entity ( ) ,
387+ attributeDesc: XCTUnwrap (
388+ ManagedMovie . entity ( ) . attributesByName. values
389+ . first ( where: { $0. name == " boxOffice " } )
390+ ) ,
391+ as: Decimal . self
392+ )
393+ switch result {
394+ case let . success( value) :
395+ XCTAssertEqual (
396+ value,
397+ 10 ,
398+ " Result value should equal min of movies box office. "
399+ )
400+ case . failure:
401+ XCTFail ( " Not expecting failure " )
402+ }
403+ }
404+
321405 func testMinSubscription( ) async throws {
322406 let task = Task {
323407 var resultCount = 0
@@ -409,6 +493,29 @@ final class AggregateRepositoryTests: CoreDataXCTestCase {
409493 }
410494 }
411495
496+ func testMaxSuccess_UnifiedEndpoint( ) async throws {
497+ let result = try await repository ( ) . aggregate (
498+ function: . max,
499+ predicate: NSPredicate ( value: true ) ,
500+ entityDesc: ManagedMovie . entity ( ) ,
501+ attributeDesc: XCTUnwrap (
502+ ManagedMovie . entity ( ) . attributesByName. values
503+ . first ( where: { $0. name == " boxOffice " } )
504+ ) ,
505+ as: Decimal . self
506+ )
507+ switch result {
508+ case let . success( value) :
509+ XCTAssertEqual (
510+ value,
511+ 50 ,
512+ " Result value should equal max of movies box office. "
513+ )
514+ case . failure:
515+ XCTFail ( " Not expecting failure " )
516+ }
517+ }
518+
412519 func testMaxSubscription( ) async throws {
413520 let task = Task {
414521 var resultCount = 0
0 commit comments