Skip to content

Instantly share code, notes, and snippets.

@llinardos
Last active May 8, 2018 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llinardos/374b03559c449171f4cd3d3b7ba7bc52 to your computer and use it in GitHub Desktop.
Save llinardos/374b03559c449171f4cd3d3b7ba7bc52 to your computer and use it in GitHub Desktop.
class ServicesTest: XCTestCase {
let service = ProfileService()
setup() {
// handle authentication if needed
// let authService = ...
// let authMethod = ...
// authService.auth(authMethod)
}
func create(profile: Profile) -> Result<Profile> {
let createResult = service.createProfile(profile)
let getResult = service.getProfile()
return getResult
}
func assertEqualProfiles(_ expected: Profile, _ getResult: Result<Profile>) {
do {
let updatedProfile = try getResult.get()
XCTAssertEquals(expected.name, updatedProfile.name)
XCTAssertEquals(expected.thing, updatedProfile.thing)
} catch {
XCTFails()
}
}
func testCreateProfileWithThing() {
let profile = Profile(name: "Name", thing: Thing())
let result = create(profile: profile)
assertEqualProfiles(profile, result.get())
}
func testCreateProfileWithoutThing() {
let profile = Profile(name: "Name", thing: nil)
let result = create(profile: profile)
assertEqualProfiles(profile, result.get())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment