-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
335 additions
and
44 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
33 changes: 0 additions & 33 deletions
33
FlexibleModelProtocol/FlexibleModelProtocolTests/FlexibleModelProtocolTests.swift
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
FlexibleModelProtocol/FlexibleModelProtocolTests/FromTest.swift
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,85 @@ | ||
// | ||
// FromTest.swift | ||
// FlexibleModelProtocolTests | ||
// | ||
// Created by hanwe on 2020/10/13. | ||
// | ||
|
||
import UIKit | ||
import XCTest | ||
@testable import FlexibleModelProtocol | ||
|
||
class FromTest: XCTestCase { | ||
override func setUpWithError() throws { | ||
|
||
} | ||
|
||
override func tearDownWithError() throws { | ||
|
||
} | ||
|
||
func testFromJson() { | ||
if let path = Bundle(for: type(of: self)).path(forResource: "SampleJson", ofType: "json") { | ||
do { | ||
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) | ||
if let myModel:MyModel = MyModel.fromJson(jsonData: data, object: MyModel()) { | ||
let mainModel = myModel.lostArticleBizInfo | ||
if mainModel.list_total_count == "" { | ||
XCTAssertTrue(false) | ||
} | ||
if mainModel.result.code == "" { | ||
XCTAssertTrue(false) | ||
} | ||
if mainModel.result.message == "" { | ||
XCTAssertTrue(false) | ||
} | ||
if mainModel.row.isEmpty { | ||
XCTAssertTrue(false) | ||
} | ||
XCTAssertTrue(true) | ||
} | ||
else { | ||
XCTAssertTrue(false) | ||
} | ||
} catch { | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
else { | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
|
||
func testFromXml() { | ||
if let path = Bundle(for: type(of: self)).path(forResource: "SampleXML", ofType: "xml") { | ||
do { | ||
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe) | ||
if let myModel:MyModel = MyModel.fromXML(xmlData: data, object: MyModel()) { | ||
let mainModel = myModel.lostArticleBizInfo | ||
if mainModel.list_total_count == "" { | ||
XCTAssertTrue(false) | ||
} | ||
if mainModel.result.code == "" { | ||
XCTAssertTrue(false) | ||
} | ||
if mainModel.result.message == "" { | ||
XCTAssertTrue(false) | ||
} | ||
if mainModel.row.isEmpty { | ||
XCTAssertTrue(false) | ||
} | ||
XCTAssertTrue(true) | ||
} | ||
else { | ||
XCTAssertTrue(false) | ||
} | ||
} catch { | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
else { | ||
XCTAssertTrue(false) | ||
} | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
FlexibleModelProtocol/FlexibleModelProtocolTests/Mock/SampleJson.json
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,41 @@ | ||
{ | ||
"lostArticleBizInfo": { | ||
"list_total_count": "234", | ||
"result": { | ||
"code": "INFO-000", | ||
"message": "Success" | ||
}, | ||
"row": [ | ||
{ | ||
"idx": "580", | ||
"code": "t1", | ||
"location": "new york", | ||
"company": "Coach" | ||
}, | ||
{ | ||
"idx": "520", | ||
"code": "b2", | ||
"location": "san francisco", | ||
"company": "Facebook" | ||
}, | ||
{ | ||
"idx": "521", | ||
"code": "b2", | ||
"location": "paris", | ||
"company": "Sandro" | ||
}, | ||
{ | ||
"idx": "588", | ||
"code": "t1", | ||
"location": "seoul", | ||
"company": "Samsung" | ||
}, | ||
{ | ||
"idx": "589", | ||
"code": "t1", | ||
"location": "cupertino", | ||
"company": "Apple" | ||
} | ||
] | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
FlexibleModelProtocol/FlexibleModelProtocolTests/Mock/SampleXML.xml
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<lostArticleBizInfo> | ||
<list_total_count>234</list_total_count> | ||
<result> | ||
<code>INFO-000</code> | ||
<message>Success</message> | ||
</result> | ||
<row> | ||
<idx>580</idx> | ||
<code>t1</code> | ||
<location>new york</location> | ||
<company>Coach</company> | ||
</row> | ||
<row> | ||
<idx>520</idx> | ||
<code>b2</code> | ||
<location>san francisco</location> | ||
<company>Facebook</company> | ||
</row> | ||
<row> | ||
<idx>521</idx> | ||
<code>b2</code> | ||
<location>paris</location> | ||
<company>Sandro</company> | ||
</row> | ||
<row> | ||
<idx>588</idx> | ||
<code>t1</code> | ||
<location>seoul</location> | ||
<company>Samsung</company> | ||
</row> | ||
<row> | ||
<idx>589</idx> | ||
<code>t1</code> | ||
<location>cupertino</location> | ||
<company>Apple</company> | ||
</row> | ||
</lostArticleBizInfo> | ||
|
32 changes: 32 additions & 0 deletions
32
FlexibleModelProtocol/FlexibleModelProtocolTests/Mock/TestModel.swift
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,32 @@ | ||
// | ||
// TestModel.swift | ||
// FlexibleModelProtocolTests | ||
// | ||
// Created by hanwe on 2020/10/13. | ||
// | ||
@testable import FlexibleModelProtocol | ||
import Foundation | ||
|
||
|
||
struct MyModel: FlexibleModelProtocol { | ||
var lostArticleBizInfo:MySubModel = MySubModel() | ||
} | ||
struct MySubModel: FlexibleModelProtocol { | ||
var list_total_count:String = "" | ||
var result:MyResultModel = MyResultModel() | ||
var row:Array<MyRowModel> = Array() | ||
} | ||
|
||
struct MyResultModel: FlexibleModelProtocol { | ||
var code:String = "" | ||
var message:String = "" | ||
} | ||
|
||
struct MyRowModel: FlexibleModelProtocol { | ||
var idx:String = "" | ||
var code:String = "" | ||
var location:String = "" | ||
var company:String = "" | ||
} | ||
|
||
|
Oops, something went wrong.