-
Notifications
You must be signed in to change notification settings - Fork 59
/
PFWeatherClientTests.m
89 lines (68 loc) · 2.38 KB
/
PFWeatherClientTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
////////////////////////////////////////////////////////////////////////////////
//
// TYPHOON FRAMEWORK
// Copyright 2013, Typhoon Framework Contributors
// All Rights Reserved.
//
// NOTICE: The authors permit you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
#import <XCTest/XCTest.h>
#import "PFWeatherClient.h"
#import "PFWeatherReport.h"
#import "TyphoonAssembly.h"
#import "PFCoreComponents.h"
#import "TyphoonConfigPostProcessor.h"
#import "TyphoonTestUtils.h"
#import "PFApplicationAssembly.h"
@interface PFWeatherClientTests : XCTestCase
@end
@implementation PFWeatherClientTests
{
id <PFWeatherClient> weatherClient;
}
//-------------------------------------------------------------------------------------------
#pragma mark - Invoking weather service methods
- (void)setUp
{
PFApplicationAssembly *assembly = [[PFApplicationAssembly new] activated];
TyphoonConfigPostProcessor* config = [TyphoonConfigPostProcessor forResourceNamed:@"Configuration.plist"];
[assembly attachDefinitionPostProcessor:config];
weatherClient = [assembly.coreComponents weatherClient];
}
- (void)test_should_retrieve_a_weather_report_given_a_valid_city
{
__block PFWeatherReport* retrievedReport;
[weatherClient loadWeatherReportFor:@"Manila" onSuccess:^(PFWeatherReport* weatherReport)
{
retrievedReport = weatherReport;
} onError:^(NSString* message)
{
LogDebug(@"Got this error: %@", message);
}];
[TyphoonTestUtils waitForCondition:^BOOL
{
typhoon_asynch_condition(retrievedReport != nil);
} andPerformTests:^
{
LogDebug(@"################### Result: %@", retrievedReport);
assertThat(retrievedReport.forecast, isNot(isEmpty()));
}];
}
- (void)test_should_trigger_the_error_handler_if_the_city_name_is_not_valid
{
__block NSString* errorMessage;
[weatherClient loadWeatherReportFor:@"Dooglefog" onSuccess:nil onError:^(NSString* message)
{
errorMessage = message;
}];
[TyphoonTestUtils waitForCondition:^BOOL
{
typhoon_asynch_condition(errorMessage != nil);
} andPerformTests:^
{
assertThat(errorMessage, equalTo(@"Unable to find any matching weather location to the query submitted!"));
}];
}
@end