/
DogTest.m
122 lines (87 loc) · 2.95 KB
/
DogTest.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// DogTest.m
// active_resource
//
// Created by James Burka on 10/15/08.
// Copyright 2008 Burkaprojects. All rights reserved.
//
#import "DogTest.h"
#import "Dog.h"
#import "Person.h"
#import "NSString+XMLSerializableSupport.h"
#import "ItemIds.h"
@implementation DogTest
static Person *owner;
-(void) setUp {
[ObjectiveResourceConfig setSite:@"http://localhost:36313/"];
[ObjectiveResourceConfig setResponseType:JSONResponse];
//[ObjectiveResource setResponseType:XmlResponse];
[ObjectiveResourceConfig setUser:nil];
[ObjectiveResourceConfig setPassword:nil];
owner = [Person findRemote:[NSString stringWithFormat:@"%i",DOG_OWNER]];
}
-(void) testDogProperties {
Dog * aDog = [[Dog alloc] init];
STAssertTrue([aDog respondsToSelector: @selector(dogId)],@"Didn't find dogId");
[aDog release];
}
-(void) testDogCount {
NSArray * dogs = [owner findAllDogs];
STAssertTrue(20 == [dogs count], @"Should have %i dogs , %d found" ,
20 ,[dogs count]);
}
- (void) testDogWithEscapableChars {
int shouldBe = [[owner findAllDogs] count] + 1;
Dog* aDog = [[Dog alloc] init];
aDog.personId = owner.personId;
aDog.name = @"Helio's Coffee & Chairs";
[aDog saveRemote];
NSArray * dogs = [owner findAllDogs];
STAssertTrue(shouldBe == [dogs count], @"Should have %i dogs , %d found" ,
shouldBe ,[dogs count]);
STAssertTrue([[aDog.name toXMLValue] isEqualToString: @"Helio's Coffee & Chairs"],@"Should be Helio's Coffee & Chairs , got %@" , [aDog.name toXMLValue]);
STAssertTrue([[NSString fromXmlString:aDog.name] isEqualToString: @"Helio's Coffee & Chairs"],@"Should be Helio's Coffee & Chairs , got %@" , [aDog.name toXMLValue]);
}
-(void) testDogSave{
int shouldBe = [[owner findAllDogs]count] + 1;
Dog * aDog = [[Dog alloc] init];
aDog.personId = owner.personId;
aDog.name = @"Judge";
[aDog saveRemote];
NSArray * dogs = [owner findAllDogs];
STAssertTrue(shouldBe == [dogs count], @"Should have %i dogs , %d found" ,
shouldBe ,[dogs count]);
[aDog release];
}
-(void) testDogUpdate{
NSArray * dogs = [owner findAllDogs];
BOOL found = NO;
Dog *aDog = [dogs objectAtIndex:0];
aDog.name = @"Judge";
[aDog updateRemote];
aDog = [dogs objectAtIndex:0];
for(Dog *dog in dogs) {
if([dog isEqual:aDog]) {
STAssertTrue([dog.name isEqualToString: aDog.name],@"Should be Judge , got %@" , aDog.name);
found = YES;
}
}
STAssertTrue(found,@"Should found the record");
}
-(void) testDogDelete {
BOOL found = NO;
NSArray * dogs = [owner findAllDogs];
int shouldBe = [dogs count] - 1;
Dog *toDelete = (Dog *)[dogs objectAtIndex:0];
[toDelete destroyRemote];
dogs = [owner findAllDogs];
STAssertTrue(shouldBe == [dogs count], @"Should have %i dogs , %d found" ,
shouldBe ,[dogs count]);
for(Dog *dog in dogs) {
if([dog isEqual:toDelete]) {
found = YES;
}
}
STAssertFalse(found,@"Should not found the record");
}
@end