Skip to content

Commit 655fba8

Browse files
committed
UserServiceProtocol, User
1 parent 1440cb9 commit 655fba8

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

Sources/MultiUser/User.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// User.swift
3+
//
4+
//
5+
// Created by Sascha Müllner on 29.02.20.
6+
//
7+
8+
import Foundation
9+
10+
struct User : Codable {
11+
private var uuid:UUID
12+
13+
var username: String?
14+
var firstname: String?
15+
var lastname: String?
16+
var birthday: Date?
17+
var emails: [String]?
18+
var attributes: [String: String]?
19+
var icon: [Data]?
20+
var data: [Data]?
21+
22+
init() {
23+
self.uuid = UUID()
24+
}
25+
26+
init(from decoder: Decoder) throws {
27+
let values = try decoder.container(keyedBy: CodingKeys.self)
28+
uuid = try values.decode(UUID.self, forKey: .uuid)
29+
}
30+
31+
func encode(to encoder: Encoder) throws {
32+
var container = encoder.container(keyedBy: CodingKeys.self)
33+
try container.encode(uuid, forKey: .uuid)
34+
try container.encode(firstname, forKey: .firstname)
35+
try container.encode(lastname, forKey: .lastname)
36+
try container.encode(birthday, forKey: .birthday)
37+
try container.encode(emails, forKey: .emails)
38+
try container.encode(attributes, forKey: .attributes)
39+
try container.encode(data, forKey: .data)
40+
}
41+
42+
var id: String {
43+
get {
44+
return self.uuid.uuidString
45+
}
46+
}
47+
48+
private enum CodingKeys: String, CodingKey {
49+
case uuid, username, firstname, lastname, birthday, emails, attributes, icon, data
50+
}
51+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// UserServiceProtocol.swift
3+
//
4+
//
5+
// Created by Sascha Müllner on 29.02.20.
6+
//
7+
8+
import Foundation
9+
10+
protocol UserServiceProtocol {
11+
func create() -> User
12+
func save(user: User)
13+
func delete(user: User)
14+
var all: [User] { get }
15+
var hasUsers: Bool { get }
16+
var current: User? { get set }
17+
}

Tests/LinuxMain.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import XCTest
2+
3+
import MultiUserTests
4+
5+
var tests = [XCTestCaseEntry]()
6+
tests += MultiUserTests.allTests()
7+
XCTMain(tests)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import XCTest
2+
@testable import MultiUser
3+
4+
final class MultiUserTests: XCTestCase {
5+
func testExample() {
6+
// This is an example of a functional test case.
7+
// Use XCTAssert and related functions to verify your tests produce the correct
8+
// results.
9+
let userService = UserService()
10+
XCTAssertEqual(userService.hasUsers, false)
11+
}
12+
13+
static var allTests = [
14+
("testExample", testExample),
15+
]
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import XCTest
2+
3+
#if !canImport(ObjectiveC)
4+
public func allTests() -> [XCTestCaseEntry] {
5+
return [
6+
testCase(MultiUserTests.allTests),
7+
]
8+
}
9+
#endif

0 commit comments

Comments
 (0)