//
//  GagLoaderTests.swift
//  OutlanderTests
//
//  Created by Joseph McBride on 5/15/20.
//  Copyright © 2020 Joe McBride. All rights reserved.
//

import XCTest

class GagLoaderTests: XCTestCase {
    let fileSystem = InMemoryFileSystem()
    var loader: GagLoader?
    let context = GameContext()

    override func setUp() {
        loader = GagLoader(fileSystem)
    }

    func test_load() {
        fileSystem.contentToLoad = "#gag {Guard Report} {a class}\n#gag {coins into the Darkbox and reaches inside it}\n"

        loader!.load(context.applicationSettings, context: context)

        XCTAssertEqual(context.gags.count, 2)
    }

    func test_save() {
        fileSystem.contentToLoad = "#gag {Guard Report} {a class}\n#gag {coins into the Darkbox and reaches inside it}\n"

        loader!.load(context.applicationSettings, context: context)
        loader!.save(context.applicationSettings, gags: context.gags)

        XCTAssertEqual(fileSystem.savedContent ?? "",
                       """
                       #gag {Guard Report} {a class}
                       #gag {coins into the Darkbox and reaches inside it}

                       """)
    }

    func test_add() {
        var gagToAdd = "#gag {Guard Report} {a class}"
        let gag = Gag.from(gag: &gagToAdd)!
        context.addGag(gag: gag)
        loader!.save(context.applicationSettings, gags: context.gags)

        XCTAssertEqual(fileSystem.savedContent ?? "",
                       """
                       #gag {Guard Report} {a class}

                       """)
    }
}
