-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
SwiftModelTests.swift
58 lines (52 loc) · 1.62 KB
/
SwiftModelTests.swift
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
//
// SwiftModelTests.swift
// MJExtensionTests
//
// Created by Frank on 2020/8/21.
// Copyright © 2020 MJ Lee. All rights reserved.
//
import XCTest
class SwiftModelTests: XCTestCase {
override class func setUp() {
MJTester.mj_setupAllowedPropertyNames {
nil
}
MJUser.mj_setupAllowedPropertyNames {
nil
}
}
// MARK: 🌈 Use Swift model
func testNormalModel() throws {
let testerDict: [String: Any] = [
"isSpecialAgent": true,
"identifier": "007",
"age": 22,
"name": "Juan"
]
guard let tester = MJTester.mj_object(withKeyValues: testerDict) else {
XCTAssert(false, "conversion failed")
return
}
XCTAssert(tester.isSpecialAgent)
XCTAssert(tester.identifier == testerDict["identifier"] as? String)
XCTAssert(tester.age == testerDict["age"] as! Int)
XCTAssert(tester.name == testerDict["name"] as? String)
}
// MARK: 🌈 Use Objective-C model code
func testOBJCModel() throws {
let userDict: [String: Any] = [
"rich": true,
"name": "007",
"age": 22,
"price": "1.5"
]
guard let user = MJUser.mj_object(withKeyValues: userDict) else {
XCTAssert(false, "conversion failed")
return
}
XCTAssert(user.rich)
XCTAssert(user.price == Double(userDict["price"] as! String))
XCTAssert(user.age == userDict["age"] as! Int)
XCTAssert(user.name == userDict["name"] as? String)
}
}