-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#41: tests refactoring - split helpers functions into appropriate cla…
…sses. Removed from Formater classes all report parameters. They are now reusable classes for any reports. Moved the StatsReportFromDate (version with Formater) in its own class.
- Loading branch information
Showing
8 changed files
with
2,055 additions
and
1,952 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// AttendanceRecordForPersonTests.swift | ||
// TimesheetsTests | ||
// | ||
// Created by Hugues Ferland on 2019-11-14. | ||
// | ||
|
||
import XCTest | ||
import CoreData | ||
@testable import Timesheets | ||
|
||
class AttendanceRecordForPersonTests: XCTestCase { | ||
var helpers = CoreDataTestSetupHelpers() | ||
var pilotJohnDo : Pilot! | ||
|
||
override func setUp() { | ||
let centre = helpers.createGlidingCentre("Middle Island") | ||
helpers.setDefaultCentre(centre) | ||
|
||
pilotJohnDo = helpers.createPilot(name: "John Do", typeOfParticipant: "COATS") | ||
} | ||
|
||
override func tearDown() { | ||
helpers.rollback() | ||
} | ||
|
||
func testCreateAttendanceRecordForPersonSigninPilot() | ||
{ | ||
print("Pilot is signed in? \(pilotJohnDo.signedIn)") | ||
dataModel.createAttendanceRecordForPerson(pilotJohnDo) | ||
|
||
XCTAssertTrue(pilotJohnDo.signedIn, "The pilot must now be signed in (as per the post condition of createAttendanceRecordForPerson.") | ||
} | ||
|
||
} |
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,186 @@ | ||
// | ||
// CoreDataTestSetupHelpers.swift | ||
// TimesheetsTests | ||
// | ||
// Created by Hugues Ferland on 2019-11-14. | ||
// | ||
|
||
import Foundation | ||
import CoreData | ||
@testable import Timesheets | ||
|
||
class CoreDataTestSetupHelpers | ||
{ | ||
var context: NSManagedObjectContext | ||
{ | ||
return dataModel.managedObjectContext | ||
} | ||
|
||
var defaultCentre : GlidingCentre! | ||
var defaultPilot : Pilot! | ||
|
||
func setDefaultCentre(_ centre: GlidingCentre) | ||
{ | ||
dataModel.glidingCentre = centre | ||
dataModel.previousRecordsGlidingCentre = centre | ||
defaultCentre = centre | ||
} | ||
|
||
func setDefaultPilot(_ pilot: Pilot) | ||
{ | ||
defaultPilot = pilot | ||
} | ||
|
||
func rollback() | ||
{ | ||
context.rollback() | ||
} | ||
|
||
func createGlidingCentre(_ name : String) -> GlidingCentre | ||
{ | ||
let centre = GlidingCentre(context: context) | ||
centre.name = "Middle Island" | ||
return centre | ||
} | ||
|
||
func createPilot(name: String, | ||
typeOfParticipant: String, | ||
withBirthDay birthday : Date = Calendar.current.date(byAdding: DateComponents(year: -20), to: Date())!) -> Pilot | ||
{ | ||
let pilot = Pilot(context: context) | ||
pilot.name = name | ||
pilot.firstName = name.components(separatedBy: " ")[0] | ||
pilot.fullName = name | ||
pilot.typeOfParticipant = typeOfParticipant | ||
pilot.glidingCentre = defaultCentre | ||
pilot.email = "\(pilot.name.replacingOccurrences(of: " ", with: ""))@hellkitchen.us" | ||
pilot.address = "13 Anywhere" | ||
pilot.aniversaryOfTowAPC = Date().advanced(by: -10) | ||
pilot.aniversaryOfGliderAPC = Date().advanced(by: -10) | ||
pilot.birthday = birthday | ||
pilot.inactive = false | ||
pilot.highestGliderQual = 3 | ||
return pilot | ||
} | ||
|
||
func createStaffCadet(name: String, | ||
withBirthDay birthday : Date = Calendar.current.date(byAdding: DateComponents(year: -17), to: Date())!, | ||
squadron : Int16 = 123) -> Pilot | ||
{ | ||
let pilot = createPilot(name: name, typeOfParticipant: "Staff Cadet", withBirthDay: birthday) | ||
pilot.squadron = squadron | ||
return pilot | ||
} | ||
|
||
func createCadet(name: String, | ||
withBirthDay birthday : Date = Calendar.current.date(byAdding: DateComponents(year: -15), to: Date())!, | ||
squadron : Int16 = 123) -> Pilot | ||
{ | ||
let pilot = createPilot(name: name, typeOfParticipant: "cadet", withBirthDay: birthday) | ||
pilot.squadron = squadron | ||
return pilot | ||
} | ||
|
||
func createFlight(_ aircraft: AircraftEntity, _ timesheet: AircraftTimesheet, startingOn startDate: Date, forMinutes duration: Int16, sequence: TowplaneSequence = .TowCourse, withPilot pilot : Pilot? = nil, withPassenger passenger : Pilot? = nil) -> FlightRecord | ||
{ | ||
let flight = FlightRecord(context: context) | ||
flight.aircraft = aircraft | ||
flight.timesheet = timesheet | ||
flight.flightSequence = sequence.rawValue | ||
flight.pilot = pilot ?? defaultPilot | ||
flight.passenger = passenger | ||
flight.timeUp = startDate | ||
flight.timeDown = Calendar.current.date(byAdding: Calendar.Component.minute, value: Int(duration), to: flight.timeUp)! | ||
flight.flightLengthInMinutes = duration | ||
return flight | ||
} | ||
|
||
func createGliderFlight(_ aircraft: AircraftEntity, _ timesheet: AircraftTimesheet, startingOn startDate: Date, forMinutes duration: Int16, sequence: GliderSequence = .StudentTrg, withPilot pilot : Pilot? = nil, withPassenger passenger : Pilot? = nil, towByFlight towFlight : FlightRecord? = nil) | ||
{ | ||
let flight = FlightRecord(context: context) | ||
flight.aircraft = aircraft | ||
flight.timesheet = timesheet | ||
flight.flightSequence = sequence.rawValue | ||
flight.pilot = pilot ?? defaultPilot | ||
flight.passenger = passenger | ||
flight.timeUp = startDate | ||
flight.timeDown = Calendar.current.date(byAdding: Calendar.Component.minute, value: Int(duration), to: flight.timeUp)! | ||
flight.flightLengthInMinutes = duration | ||
flight.connectedAircraftRecord = towFlight | ||
} | ||
|
||
func createTimesheet(_ aircraft : AircraftEntity, _ forDate : Date) -> AircraftTimesheet { | ||
let timesheet = aircraft.insertNewTimeSheetForAircraft(withContext: context) | ||
timesheet.date = forDate | ||
timesheet.glidingCentre = dataModel.glidingCentre | ||
timesheet.initialTTSN = 0 | ||
timesheet.glidingCentre = dataModel.glidingCentre | ||
timesheet.setTTSN() | ||
return timesheet | ||
} | ||
|
||
func createLaunch(glider : AircraftEntity, launcher : AircraftEntity, takeOffDate : Date, withPilot pilot : Pilot) | ||
{ | ||
let gliderTimesheet = createTimesheet(glider, takeOffDate) | ||
let launcherTimesheet = createTimesheet(launcher, takeOffDate) | ||
let launcherFlight = createFlight(launcher, launcherTimesheet, startingOn: takeOffDate, forMinutes: 20, sequence: .TowCourse) | ||
createGliderFlight(glider, gliderTimesheet, startingOn: takeOffDate, forMinutes: 20, sequence: .Famil, withPilot: pilot, towByFlight: launcherFlight) | ||
|
||
launcher.updateTTSN() | ||
glider.updateTTSN() | ||
} | ||
|
||
func createTowPlane(registration: String, tailNumber: String) -> AircraftEntity | ||
{ | ||
let aircraft = AircraftEntity(context: context) | ||
aircraft.registration = registration | ||
aircraft.tailNumber = tailNumber | ||
aircraft.type = .towplane | ||
aircraft.gliderOrTowplane = Int16(aircraft.type.rawValue) | ||
aircraft.glidingCentre = defaultCentre | ||
return aircraft | ||
} | ||
|
||
func createGlider(registration: String, tailNumber: String) -> AircraftEntity | ||
{ | ||
let aircraft = AircraftEntity(context: context) | ||
aircraft.registration = registration | ||
aircraft.tailNumber = tailNumber | ||
aircraft.type = .glider | ||
aircraft.gliderOrTowplane = Int16(aircraft.type.rawValue) | ||
aircraft.glidingCentre = defaultCentre | ||
return aircraft | ||
} | ||
|
||
func createAutoTow() -> AircraftEntity | ||
{ | ||
let aircraft = AircraftEntity(context: context) | ||
aircraft.registration = "AUTO" | ||
aircraft.tailNumber = "GO-UP" | ||
aircraft.type = .auto | ||
aircraft.gliderOrTowplane = Int16(aircraft.type.rawValue) | ||
aircraft.glidingCentre = defaultCentre | ||
return aircraft | ||
} | ||
|
||
func createWinchTow(registration : String, tailNumber : String) -> AircraftEntity | ||
{ | ||
let aircraft = AircraftEntity(context: context) | ||
aircraft.registration = registration | ||
aircraft.tailNumber = tailNumber | ||
aircraft.type = .winch | ||
aircraft.gliderOrTowplane = Int16(aircraft.type.rawValue) | ||
aircraft.glidingCentre = defaultCentre | ||
return aircraft | ||
} | ||
|
||
func createMaintenance(for aircraft: AircraftEntity, on date: Date, withComment comment: String) -> MaintenanceEvent | ||
{ | ||
let event = MaintenanceEvent(context: context) | ||
event.aircraft = aircraft | ||
event.date = date | ||
event.comment = comment | ||
return event | ||
} | ||
|
||
} |
Oops, something went wrong.