This repository was archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMSDateTests.m
More file actions
112 lines (94 loc) · 3.65 KB
/
MSDateTests.m
File metadata and controls
112 lines (94 loc) · 3.65 KB
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
//
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
//
#import <XCTest/XCTest.h>
#import <Foundation/Foundation.h>
#if SWIFT_PACKAGE
@import MSGraphClientModels;
#else
#import "MSDate.h"
#endif
@interface MSDate (Test)
@property (nonatomic, strong) NSDate *date;
@end
@interface MSDateTests : XCTestCase
@property NSInteger testYear;
@property NSInteger testMonth;
@property NSInteger testDay;
@property NSDateComponents *dateComponents;
@end
@implementation MSDateTests
- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
[super setUp];
self.testYear = 2016;
self.testMonth = 6;
self.testDay = 11;
self.dateComponents = [[NSDateComponents alloc] init];
self.dateComponents.year = _testYear;
self.dateComponents.month = _testMonth;
self.dateComponents.day = _testDay;
self.dateComponents.calendar = [NSCalendar currentCalendar];
}
- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
-(void)testInit{
MSDate *msdate = [MSDate date];
XCTAssertNotNil(msdate);
msdate = [MSDate dateWithYear:_testYear month:_testMonth day:_testDay];
XCTAssertNotNil(msdate);
XCTAssertNoThrow([MSDate dateWithYear:0 month:0 day:0]);
}
-(void)testInitWithNSDate{
NSDate *nowData = [NSDate date];
MSDate *msdate = [[MSDate alloc] initWithNSDate: nowData];
XCTAssertNotNil(msdate);
XCTAssertEqualObjects(msdate.date, nowData);
}
-(void)testInitWithNilNSDate{
MSDate *msdate = [[MSDate alloc] initWithNSDate: nil];
XCTAssertNotNil(msdate);
XCTAssertNil(msdate.date);
}
-(void)testInitWithYear{
MSDate *msdate = [[MSDate alloc] initWithYear:_testYear month:_testMonth day:_testDay];
XCTAssertEqualObjects(msdate.date, [_dateComponents date]);
}
-(void)testMSDatePropertiesFromInitWithYear{
MSDate *msdate = [[MSDate alloc] initWithYear:_testYear month:_testMonth day:_testDay];
XCTAssertEqual([msdate year], _testYear);
XCTAssertEqual(msdate.month, _testMonth);
XCTAssertEqual(msdate.day, _testDay);
}
-(void)testMSDateProertiesFromInitWithDate{
NSDate *nowData = [NSDate date];
MSDate *msdate = [[MSDate alloc] initWithNSDate: nowData];
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]];
XCTAssertEqual(msdate.year, components.year);
XCTAssertEqual(msdate.month, components.month);
XCTAssertEqual(msdate.day, components.day);
}
-(void)testMS_toString{
MSDate *msdate = [[MSDate alloc] initWithYear:_testYear month:_testMonth day:_testDay];
NSString *dateString = [msdate ms_toString];
NSString *expectedString =[NSString stringWithFormat:@"%@-0%@-%@",[@(_testYear) stringValue],[@(_testMonth) stringValue],[@(_testDay) stringValue]];
XCTAssertEqualObjects(dateString, expectedString);
}
-(void)testMS_dateFromString{
MSDate *msdate = [MSDate ms_dateFromString:[NSString stringWithFormat:@"%@-0%@-%@",[@(_testYear) stringValue],[@(_testMonth) stringValue],[@(_testDay) stringValue]]];
XCTAssertNotNil(msdate);
XCTAssertEqualObjects(msdate.date, [_dateComponents date]);
}
-(void)testMS_dateFromNilString{
MSDate *msdate = [MSDate ms_dateFromString:nil];
XCTAssertNotNil(msdate);
XCTAssertNil(msdate.date);
}
-(void)testMS_dateFromInvalidFormatterString{
MSDate *msdate = [MSDate ms_dateFromString:@"test"];
XCTAssertNotNil(msdate);
XCTAssertNil(msdate.date);
}
@end