-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cancel all operations method in base datasource.
- Loading branch information
Showing
11 changed files
with
251 additions
and
40 deletions.
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
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
15 changes: 15 additions & 0 deletions
15
BIObjCHelpersTests/Mocks/Operations/MockBIOperationNotifierListener.h
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,15 @@ | ||
// | ||
// MockBIOperationNotifierListener.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 6/22/16. | ||
// Copyright © 2016 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <BIObjCHelpers/BIObjCHelpers.h> | ||
|
||
@interface MockBIOperationNotifierListener : NSObject<BIOperationNotifierListener> | ||
|
||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
BIObjCHelpersTests/Mocks/Operations/MockBIOperationNotifierListener.m
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,13 @@ | ||
// | ||
// MockBIOperationNotifierListener.m | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 6/22/16. | ||
// Copyright © 2016 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "MockBIOperationNotifierListener.h" | ||
|
||
@implementation MockBIOperationNotifierListener | ||
|
||
@end |
100 changes: 100 additions & 0 deletions
100
BIObjCHelpersTests/Tests/Datasource/Base/BIDatasourceBaseTestCase.m
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,100 @@ | ||
// | ||
// BIDatasourceBaseTestCase.m | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 6/22/16. | ||
// Copyright © 2016 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <BIObjCHelpers/BIObjCHelpers.h> | ||
|
||
#import "MockBIOperationNotifierListener.h" | ||
#import "BIOperationNotifier+Tests.h" | ||
|
||
@interface BIDatasourceBaseTestCase : XCTestCase | ||
|
||
@property (nonatomic, strong, nullable, readwrite) BIDatasourceBase *datasource; | ||
|
||
@end | ||
|
||
@implementation BIDatasourceBaseTestCase | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
self.datasource = [BIDatasourceBase new]; | ||
} | ||
|
||
#pragma mark - Test init | ||
|
||
- (void)test_init { | ||
BIDatasourceBase *datasource = [BIDatasourceBase new]; | ||
XCTAssertNotNil(datasource); | ||
XCTAssertNotNil(datasource.operations); | ||
XCTAssertEqual(datasource.operations.count, 0U); | ||
} | ||
|
||
#pragma mark - Test cancelAllCurrentOperations | ||
|
||
- (void)test_cancelAllCurrentOperations_silent { | ||
// GIVEN: A set of operations | ||
NSInteger countOperations = arc4random_uniform(10); | ||
NSMutableArray<BIOperationNotifier *> *operations = [NSMutableArray new]; | ||
__block NSError *returnedError; | ||
for (NSInteger index = 0; index < countOperations; index++) { | ||
BIOperationNotifier *operation = [BIOperationNotifier new]; | ||
operation.didFinishWithErrorCallback = ^(NSError *__nonnull error) { | ||
returnedError = error; | ||
}; | ||
MockBIOperationNotifierListener *listener = [MockBIOperationNotifierListener new]; | ||
[operation registerOperationFinishedListener:listener]; | ||
[self.datasource.operations addObject:operation]; | ||
[operations addObject:operation]; | ||
} | ||
// WHEN: cancelAllCurrentOperations method is called | ||
[self.datasource cancelAllCurrentOperations:YES]; | ||
// THEN: Datasource should have no operations | ||
XCTAssertEqual(self.datasource.operations.count, 0); | ||
// THEN: All operations should not have a didFinishWithErrorCallback set | ||
for (BIOperationNotifier *operation in operations) { | ||
XCTAssertNil(operation.didFinishWithErrorCallback); | ||
} | ||
// THEN: All operations should have no listeners | ||
for (BIOperationNotifier *operation in operations) { | ||
XCTAssertEqual(operation.operationFinishedListeners.count, 0); | ||
} | ||
|
||
// THEN: Operation's didFinishWithErrorCallback should not have been called | ||
XCTAssertNil(returnedError); | ||
} | ||
|
||
- (void)test_cancelAllCurrentOperations_notSilent { | ||
// GIVEN: A set of operations | ||
NSInteger countOperations = arc4random_uniform(10); | ||
NSMutableArray<BIOperationNotifier *> *operations = [NSMutableArray new]; | ||
__block NSError *returnedError; | ||
for (NSInteger index = 0; index < countOperations; index++) { | ||
BIOperationNotifier *operation = [BIOperationNotifier new]; | ||
operation.didFinishWithErrorCallback = ^(NSError *__nonnull error) { | ||
returnedError = error; | ||
}; | ||
MockBIOperationNotifierListener *listener = [MockBIOperationNotifierListener new]; | ||
[operation registerOperationFinishedListener:listener]; | ||
[self.datasource.operations addObject:operation]; | ||
[operations addObject:operation]; | ||
} | ||
// WHEN: cancelAllCurrentOperations method is called | ||
[self.datasource cancelAllCurrentOperations:NO]; | ||
// THEN: Datasource should have no operations | ||
XCTAssertEqual(self.datasource.operations.count, 0); | ||
// THEN: All operations should have a didFinishWithErrorCallback set | ||
for (BIOperationNotifier *operation in operations) { | ||
XCTAssertNotNil(operation.didFinishWithErrorCallback); | ||
} | ||
// THEN: All operations should have listeners | ||
for (BIOperationNotifier *operation in operations) { | ||
XCTAssertEqual(operation.operationFinishedListeners.count, 1); | ||
} | ||
} | ||
|
||
@end |
36 changes: 0 additions & 36 deletions
36
BIObjCHelpersTests/Tests/Datasource/TableView/BIDatasourceBaseTestCase.m
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
BIObjCHelpersTests/Tests/Operations/BIOperationNotifier+Tests.h
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,15 @@ | ||
// | ||
// BIOperationNotifier+Tests.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 6/22/16. | ||
// Copyright © 2016 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <BIObjCHelpers/BIObjCHelpers.h> | ||
|
||
@interface BIOperationNotifier (Tests) | ||
|
||
@property (nonatomic, strong, nullable, readwrite) NSHashTable <id<BIOperationNotifierListener>> *operationFinishedListeners; | ||
|
||
@end |
Oops, something went wrong.