Skip to content

Commit

Permalink
Add method to add several FsWorksheets + unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Mar 16, 2023
1 parent 0062c62 commit 4999caf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/FsSpreadsheet/FsWorkbook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ type FsWorkbook() =
workbook.AddWorksheet sheet |> ignore
workbook

/// <summary>Adds a collection of FsWorksheets to the FsWorkbook.</summary>
member self.AddWorksheets(sheets : seq<FsWorksheet>) =
sheets
|> Seq.iter (self.AddWorksheet >> ignore)
self

/// <summary>Adds a collection of FsWorksheets to an FsWorkbook.</summary>
static member addWorksheets sheets (workbook : FsWorkbook) =
workbook.AddWorksheets sheets

/// Returns all FsWorksheets.
member self.GetWorksheets() =
_worksheets
Expand Down
11 changes: 10 additions & 1 deletion tests/FsSpreadsheet.Tests/FsWorkbook.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open FsSpreadsheet
let dummyWorkbook = new FsWorkbook()
let dummyWorksheet1 = FsWorksheet("dummyWorksheet1")
let dummyWorksheet2 = FsWorksheet("dummyWorksheet2")
let dummyWorksheetList = [dummyWorksheet1; dummyWorksheet2]
let dummyTables = [
FsTable("dummyTable1", FsRangeAddress("A1:B2"))
FsTable("dummyTable2", FsRangeAddress("C3:F5"))
Expand All @@ -33,8 +34,16 @@ let fsWorkbookTests =
Expect.throws (fun () -> dummyWorkbook.GetWorksheetByName "bla" |> ignore) "did not throw exception"
]
testList "GetTables" [
testCase "got correct FsTables" <| fun _ ->
testCase "gets correct FsTables" <| fun _ ->
let tablesGotten = dummyWorkbook.GetTables()
Expect.equal tablesGotten dummyTables "Did not get correct FsTables"
]
testList "AddWorksheets" [
testCase "adds all FsWorksheets correctly" <| fun _ ->
let testWorkbook = new FsWorkbook()
testWorkbook.AddWorksheets [dummyWorksheet1; dummyWorksheet2] |> ignore
let testWorkbookWorksheetNames = testWorkbook.GetWorksheets() |> List.map (fun ws -> ws.Name)
let dummyWorksheetNames = dummyWorksheetList |> List.map (fun ws -> ws.Name)
Expect.containsAll testWorkbookWorksheetNames dummyWorksheetNames "Does not contain all FsWorksheets"
]
]

0 comments on commit 4999caf

Please sign in to comment.