diff --git a/.github/actions/Build-PSModule/src/helpers/Build/Add-ContentFromItem.ps1 b/.github/actions/Build-PSModule/src/helpers/Build/Add-ContentFromItem.ps1 index 9046b204..095b7d98 100644 --- a/.github/actions/Build-PSModule/src/helpers/Build/Add-ContentFromItem.ps1 +++ b/.github/actions/Build-PSModule/src/helpers/Build/Add-ContentFromItem.ps1 @@ -1,4 +1,4 @@ -function Add-ContentFromItem { +function Add-ContentFromItem { <# .SYNOPSIS Add the content of a folder or file to the root module file. @@ -22,13 +22,10 @@ [Parameter(Mandatory)] [string] $RootPath ) - # Get the path separator for the current OS - $pathSeparator = [System.IO.Path]::DirectorySeparatorChar + $separators = [char[]]@([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar) - $relativeFolderPath = $Path -replace $RootPath, '' - $relativeFolderPath = $relativeFolderPath -replace $file.Extension, '' - $relativeFolderPath = $relativeFolderPath.TrimStart($pathSeparator) - $relativeFolderPath = $relativeFolderPath -split $pathSeparator | ForEach-Object { "[$_]" } + $relativeFolderPath = [System.IO.Path]::GetRelativePath($RootPath, $Path) + $relativeFolderPath = $relativeFolderPath.Split($separators, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object { "[$_]" } $relativeFolderPath = $relativeFolderPath -join ' - ' Add-Content -Path $RootModuleFilePath -Force -Value @" @@ -37,11 +34,11 @@ Write-Debug "[`$scriptName] - $relativeFolderPath - Processing folder" "@ $files = $Path | Get-ChildItem -File -Force -Filter '*.ps1' | Sort-Object -Property FullName + foreach ($file in $files) { - $relativeFilePath = $file.FullName -replace $RootPath, '' - $relativeFilePath = $relativeFilePath -replace $file.Extension, '' - $relativeFilePath = $relativeFilePath.TrimStart($pathSeparator) - $relativeFilePath = $relativeFilePath -split $pathSeparator | ForEach-Object { "[$_]" } + $relativeFilePath = [System.IO.Path]::GetRelativePath($RootPath, $file.FullName) + $relativeFilePath = [System.IO.Path]::ChangeExtension($relativeFilePath, $null).TrimEnd('.') + $relativeFilePath = $relativeFilePath.Split($separators, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object { "[$_]" } $relativeFilePath = $relativeFilePath -join ' - ' Add-Content -Path $RootModuleFilePath -Force -Value @" diff --git a/.github/actions/Build-PSModule/src/helpers/Build/Build-PSModuleRootModule.ps1 b/.github/actions/Build-PSModule/src/helpers/Build/Build-PSModuleRootModule.ps1 index 02aaa984..619a5d95 100644 --- a/.github/actions/Build-PSModule/src/helpers/Build/Build-PSModuleRootModule.ps1 +++ b/.github/actions/Build-PSModule/src/helpers/Build/Build-PSModuleRootModule.ps1 @@ -48,8 +48,7 @@ [System.IO.DirectoryInfo] $ModuleOutputFolder ) - # Get the path separator for the current OS - $pathSeparator = [System.IO.Path]::DirectorySeparatorChar + $separators = [char[]]@([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar) Set-GitHubLogGroup 'Build root module' { $rootModuleFile = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -Force @@ -185,22 +184,21 @@ Write-Debug "[$scriptName] - [data] - Done" ) foreach ($scriptFolder in $scriptFoldersToProcess) { - $scriptFolder = Join-Path -Path $ModuleOutputFolder -ChildPath $scriptFolder - if (-not (Test-Path -Path $scriptFolder)) { + $scriptFolderPath = Join-Path -Path $ModuleOutputFolder -ChildPath $scriptFolder + if (-not (Test-Path -Path $scriptFolderPath)) { continue } - Add-ContentFromItem -Path $scriptFolder -RootModuleFilePath $rootModuleFile -RootPath $ModuleOutputFolder - Remove-Item -Path $scriptFolder -Force -Recurse + Add-ContentFromItem -Path $scriptFolderPath -RootModuleFilePath $rootModuleFile -RootPath $ModuleOutputFolder + Remove-Item -Path $scriptFolderPath -Force -Recurse } #endregion - Add content from subfolders #region - Add content from *.ps1 files on module root $files = $ModuleOutputFolder | Get-ChildItem -File -Force -Filter '*.ps1' | Sort-Object -Property FullName foreach ($file in $files) { - $relativePath = $file.FullName -replace $ModuleOutputFolder, '' - $relativePath = $relativePath -replace $file.Extension, '' - $relativePath = $relativePath.TrimStart($pathSeparator) - $relativePath = $relativePath -split $pathSeparator | ForEach-Object { "[$_]" } + $relativePath = [System.IO.Path]::GetRelativePath($ModuleOutputFolder, $file.FullName) + $relativePath = [System.IO.Path]::ChangeExtension($relativePath, $null).TrimEnd('.') + $relativePath = $relativePath.Split($separators, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object { "[$_]" } $relativePath = $relativePath -join ' - ' Add-Content -Path $rootModuleFile -Force -Value @" diff --git a/.github/workflows/Lint-Repository.yml b/.github/workflows/Lint-Repository.yml index 02c77590..52822090 100644 --- a/.github/workflows/Lint-Repository.yml +++ b/.github/workflows/Lint-Repository.yml @@ -54,6 +54,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} DEFAULT_WORKSPACE: ${{ fromJson(env.Settings).WorkingDirectory }} FILTER_REGEX_INCLUDE: ${{ fromJson(env.Settings).WorkingDirectory }} + FILTER_REGEX_EXCLUDE: ${{ fromJson(env.Settings).WorkingDirectory }}/src/classes/public/.*\.ps1$ ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: false SAVE_SUPER_LINTER_SUMMARY: true diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 2c5664a2..e57c709c 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -28,6 +28,7 @@ jobs: uses: super-linter/super-linter@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0 env: GITHUB_TOKEN: ${{ github.token }} + FILTER_REGEX_EXCLUDE: 'tests/src(TestRepo|WithManifestTestRepo)/src/classes/public/.*\.ps1$' VALIDATE_BIOME_FORMAT: false VALIDATE_GITHUB_ACTIONS: false VALIDATE_JSCPD: false diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index a845c2a4..1e346454 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -13,6 +13,7 @@ on: - synchronize - labeled paths: + - '.github/actions/**' - '.github/workflows/**' - '!.github/workflows/Release.yml' - '!.github/workflows/Linter.yml' diff --git a/.github/workflows/Workflow-Test-Default.yml b/.github/workflows/Workflow-Test-Default.yml index e5b012e5..511b4b1c 100644 --- a/.github/workflows/Workflow-Test-Default.yml +++ b/.github/workflows/Workflow-Test-Default.yml @@ -6,6 +6,7 @@ on: workflow_dispatch: pull_request: paths: + - '.github/actions/**' - '.github/workflows/**' - '!.github/workflows/Release.yml' - '!.github/workflows/Linter.yml' @@ -43,4 +44,5 @@ jobs: ImportantFilePatterns: | ^src/ ^README\.md$ + ^\.github/actions/ ^\.github/workflows/(?!Release\.yml$|Linter\.yml$) diff --git a/.github/workflows/Workflow-Test-WithManifest.yml b/.github/workflows/Workflow-Test-WithManifest.yml index 4b179d9a..82f80f55 100644 --- a/.github/workflows/Workflow-Test-WithManifest.yml +++ b/.github/workflows/Workflow-Test-WithManifest.yml @@ -6,6 +6,7 @@ on: workflow_dispatch: pull_request: paths: + - '.github/actions/**' - '.github/workflows/**' - '!.github/workflows/Release.yml' - '!.github/workflows/Linter.yml' @@ -43,4 +44,5 @@ jobs: ImportantFilePatterns: | ^src/ ^README\.md$ + ^\.github/actions/ ^\.github/workflows/(?!Release\.yml$|Linter\.yml$) diff --git a/tests/srcTestRepo/src/classes/public/ActiveLoanRegister.ps1 b/tests/srcTestRepo/src/classes/public/ActiveLoanRegister.ps1 new file mode 100644 index 00000000..fb4e98cd --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/ActiveLoanRegister.ps1 @@ -0,0 +1,11 @@ +class ActiveLoanRegister { + [System.Collections.Generic.List[BookLoan]] $Loans + + ActiveLoanRegister() { + $this.Loans = [System.Collections.Generic.List[BookLoan]]::new() + } + + [void] AddLoan([BookLoan]$Loan) { + $this.Loans.Add($Loan) + } +} diff --git a/tests/srcTestRepo/src/classes/public/AlphaCirculationNode.ps1 b/tests/srcTestRepo/src/classes/public/AlphaCirculationNode.ps1 new file mode 100644 index 00000000..d7e10b5e --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/AlphaCirculationNode.ps1 @@ -0,0 +1,9 @@ +class AlphaCirculationNode { + [string] $Id + [ZetaCirculationNode] $Next + + AlphaCirculationNode([string]$Id, [ZetaCirculationNode]$Next) { + $this.Id = $Id + $this.Next = $Next + } +} diff --git a/tests/srcTestRepo/src/classes/public/AuthorIndex.ps1 b/tests/srcTestRepo/src/classes/public/AuthorIndex.ps1 new file mode 100644 index 00000000..c379af92 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/AuthorIndex.ps1 @@ -0,0 +1,11 @@ +class AuthorIndex { + [string] $Name + [AuthorProfile[]] $Authors + [ZCatalog] $Catalog + + AuthorIndex([string]$Name, [ZCatalog]$Catalog) { + $this.Name = $Name + $this.Catalog = $Catalog + $this.Authors = @() + } +} diff --git a/tests/srcTestRepo/src/classes/public/AuthorProfile.ps1 b/tests/srcTestRepo/src/classes/public/AuthorProfile.ps1 new file mode 100644 index 00000000..6a86fa35 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/AuthorProfile.ps1 @@ -0,0 +1,9 @@ +class AuthorProfile { + [string] $Name + [Book[]] $PublishedBooks + + AuthorProfile([string]$Name, [Book[]]$PublishedBooks) { + $this.Name = $Name + $this.PublishedBooks = $PublishedBooks + } +} diff --git a/tests/srcTestRepo/src/classes/public/Book.ps1 b/tests/srcTestRepo/src/classes/public/Book.ps1 index 8917d9ab..a3c7a7ca 100644 --- a/tests/srcTestRepo/src/classes/public/Book.ps1 +++ b/tests/srcTestRepo/src/classes/public/Book.ps1 @@ -44,93 +44,6 @@ } } -class BookList { - # Static property to hold the list of books - static [System.Collections.Generic.List[Book]] $Books - # Static method to initialize the list of books. Called in the other - # static methods to avoid needing to explicit initialize the value. - static [void] Initialize() { [BookList]::Initialize($false) } - static [bool] Initialize([bool]$force) { - if ([BookList]::Books.Count -gt 0 -and -not $force) { - return $false - } - - [BookList]::Books = [System.Collections.Generic.List[Book]]::new() - - return $true - } - # Ensure a book is valid for the list. - static [void] Validate([book]$Book) { - $Prefix = @( - 'Book validation failed: Book must be defined with the Title,' - 'Author, and PublishDate properties, but' - ) -join ' ' - if ($null -eq $Book) { throw "$Prefix was null" } - if ([string]::IsNullOrEmpty($Book.Title)) { - throw "$Prefix Title wasn't defined" - } - if ([string]::IsNullOrEmpty($Book.Author)) { - throw "$Prefix Author wasn't defined" - } - if ([datetime]::MinValue -eq $Book.PublishDate) { - throw "$Prefix PublishDate wasn't defined" - } - } - # Static methods to manage the list of books. - # Add a book if it's not already in the list. - static [void] Add([Book]$Book) { - [BookList]::Initialize() - [BookList]::Validate($Book) - if ([BookList]::Books.Contains($Book)) { - throw "Book '$Book' already in list" - } - - $FindPredicate = { - param([Book]$b) - - $b.Title -eq $Book.Title -and - $b.Author -eq $Book.Author -and - $b.PublishDate -eq $Book.PublishDate - }.GetNewClosure() - if ([BookList]::Books.Find($FindPredicate)) { - throw "Book '$Book' already in list" - } - - [BookList]::Books.Add($Book) - } - # Clear the list of books. - static [void] Clear() { - [BookList]::Initialize() - [BookList]::Books.Clear() - } - # Find a specific book using a filtering scriptblock. - static [Book] Find([scriptblock]$Predicate) { - [BookList]::Initialize() - return [BookList]::Books.Find($Predicate) - } - # Find every book matching the filtering scriptblock. - static [Book[]] FindAll([scriptblock]$Predicate) { - [BookList]::Initialize() - return [BookList]::Books.FindAll($Predicate) - } - # Remove a specific book. - static [void] Remove([Book]$Book) { - [BookList]::Initialize() - [BookList]::Books.Remove($Book) - } - # Remove a book by property value. - static [void] RemoveBy([string]$Property, [string]$Value) { - [BookList]::Initialize() - $Index = [BookList]::Books.FindIndex({ - param($b) - $b.$Property -eq $Value - }.GetNewClosure()) - if ($Index -ge 0) { - [BookList]::Books.RemoveAt($Index) - } - } -} - enum Binding { Hardcover Paperback diff --git a/tests/srcTestRepo/src/classes/public/BookCopy.ps1 b/tests/srcTestRepo/src/classes/public/BookCopy.ps1 new file mode 100644 index 00000000..bee184b1 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/BookCopy.ps1 @@ -0,0 +1,11 @@ +class BookCopy { + [string] $InventoryId + [Book] $Book + [ShelfLocation] $Location + + BookCopy([string]$InventoryId, [Book]$Book, [ShelfLocation]$Location) { + $this.InventoryId = $InventoryId + $this.Book = $Book + $this.Location = $Location + } +} diff --git a/tests/srcTestRepo/src/classes/public/BookInventory.ps1 b/tests/srcTestRepo/src/classes/public/BookInventory.ps1 new file mode 100644 index 00000000..cf7948e3 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/BookInventory.ps1 @@ -0,0 +1,11 @@ +class BookInventory { + [string] $Name + [BookCopy[]] $Copies + [ZCatalog] $Catalog + + BookInventory([string]$Name, [ZCatalog]$Catalog) { + $this.Name = $Name + $this.Catalog = $Catalog + $this.Copies = @() + } +} diff --git a/tests/srcTestRepo/src/classes/public/BookList.ps1 b/tests/srcTestRepo/src/classes/public/BookList.ps1 new file mode 100644 index 00000000..bf421618 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/BookList.ps1 @@ -0,0 +1,57 @@ +class BookList { + static [System.Collections.Generic.List[Book]] $Books + + static [void] Initialize() { [BookList]::Initialize($false) } + static [bool] Initialize([bool]$force) { + if ([BookList]::Books.Count -gt 0 -and -not $force) { + return $false + } + + [BookList]::Books = [System.Collections.Generic.List[Book]]::new() + + return $true + } + + static [void] Validate([Book]$Book) { + $Prefix = @( + 'Book validation failed: Book must be defined with the Title,' + 'Author, and PublishDate properties, but' + ) -join ' ' + if ($null -eq $Book) { throw "$Prefix was null" } + if ([string]::IsNullOrEmpty($Book.Title)) { throw "$Prefix Title wasn't defined" } + if ([string]::IsNullOrEmpty($Book.Author)) { throw "$Prefix Author wasn't defined" } + if ([datetime]::MinValue -eq $Book.PublishDate) { throw "$Prefix PublishDate wasn't defined" } + } + + static [void] Add([Book]$Book) { + [BookList]::Initialize() + [BookList]::Validate($Book) + if ([BookList]::Books.Contains($Book)) { throw "Book '$Book' already in list" } + + $findPredicate = { + param([Book]$b) + + $b.Title -eq $Book.Title -and + $b.Author -eq $Book.Author -and + $b.PublishDate -eq $Book.PublishDate + }.GetNewClosure() + if ([BookList]::Books.Find($findPredicate)) { throw "Book '$Book' already in list" } + + [BookList]::Books.Add($Book) + } + + static [void] Clear() { + [BookList]::Initialize() + [BookList]::Books.Clear() + } + + static [Book] Find([scriptblock]$Predicate) { + [BookList]::Initialize() + return [BookList]::Books.Find($Predicate) + } + + static [Book[]] FindAll([scriptblock]$Predicate) { + [BookList]::Initialize() + return [BookList]::Books.FindAll($Predicate) + } +} diff --git a/tests/srcTestRepo/src/classes/public/BookLoan.ps1 b/tests/srcTestRepo/src/classes/public/BookLoan.ps1 new file mode 100644 index 00000000..fc0f6163 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/BookLoan.ps1 @@ -0,0 +1,13 @@ +class BookLoan { + [BookCopy] $Copy + [MemberAccount] $Member + [datetime] $LoanDate + [datetime] $DueDate + + BookLoan([BookCopy]$Copy, [MemberAccount]$Member, [DueDatePolicy]$Policy) { + $this.Copy = $Copy + $this.Member = $Member + $this.LoanDate = Get-Date + $this.DueDate = $this.LoanDate.AddDays($Policy.StandardLoanDays) + } +} diff --git a/tests/srcTestRepo/src/classes/public/BranchLibrary.ps1 b/tests/srcTestRepo/src/classes/public/BranchLibrary.ps1 new file mode 100644 index 00000000..3ee2fd20 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/BranchLibrary.ps1 @@ -0,0 +1,11 @@ +class BranchLibrary { + [string] $Code + [string] $Name + [OpeningHours] $Hours + + BranchLibrary([string]$Code, [string]$Name, [OpeningHours]$Hours) { + $this.Code = $Code + $this.Name = $Name + $this.Hours = $Hours + } +} diff --git a/tests/srcTestRepo/src/classes/public/CatalogSection.ps1 b/tests/srcTestRepo/src/classes/public/CatalogSection.ps1 new file mode 100644 index 00000000..10352122 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/CatalogSection.ps1 @@ -0,0 +1,9 @@ +class CatalogSection { + [string] $Name + [Book[]] $Books + + CatalogSection([string]$Name, [Book[]]$Books) { + $this.Name = $Name + $this.Books = $Books + } +} diff --git a/tests/srcTestRepo/src/classes/public/DueDatePolicy.ps1 b/tests/srcTestRepo/src/classes/public/DueDatePolicy.ps1 new file mode 100644 index 00000000..2803f489 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/DueDatePolicy.ps1 @@ -0,0 +1,9 @@ +class DueDatePolicy { + [int] $StandardLoanDays + [int] $GraceDays + + DueDatePolicy([int]$StandardLoanDays, [int]$GraceDays) { + $this.StandardLoanDays = $StandardLoanDays + $this.GraceDays = $GraceDays + } +} diff --git a/tests/srcTestRepo/src/classes/public/LibraryReport.ps1 b/tests/srcTestRepo/src/classes/public/LibraryReport.ps1 new file mode 100644 index 00000000..dfa84fe7 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/LibraryReport.ps1 @@ -0,0 +1,18 @@ +class LibraryReport { + [AuthorIndex] $Authors + [ActiveLoanRegister] $ActiveLoans + [BookInventory] $Inventory + [ZCatalog] $Catalog + + LibraryReport( + [AuthorIndex]$Authors, + [ActiveLoanRegister]$ActiveLoans, + [BookInventory]$Inventory, + [ZCatalog]$Catalog + ) { + $this.Authors = $Authors + $this.ActiveLoans = $ActiveLoans + $this.Inventory = $Inventory + $this.Catalog = $Catalog + } +} diff --git a/tests/srcTestRepo/src/classes/public/MemberAccount.ps1 b/tests/srcTestRepo/src/classes/public/MemberAccount.ps1 new file mode 100644 index 00000000..c292f231 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/MemberAccount.ps1 @@ -0,0 +1,11 @@ +class MemberAccount { + [string] $MemberId + [string] $DisplayName + [ReadingList] $ReadingList + + MemberAccount([string]$MemberId, [string]$DisplayName, [ReadingList]$ReadingList) { + $this.MemberId = $MemberId + $this.DisplayName = $DisplayName + $this.ReadingList = $ReadingList + } +} diff --git a/tests/srcTestRepo/src/classes/public/OpeningHours.ps1 b/tests/srcTestRepo/src/classes/public/OpeningHours.ps1 new file mode 100644 index 00000000..4be09375 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/OpeningHours.ps1 @@ -0,0 +1,9 @@ +class OpeningHours { + [timespan] $OpenAt + [timespan] $CloseAt + + OpeningHours([timespan]$OpenAt, [timespan]$CloseAt) { + $this.OpenAt = $OpenAt + $this.CloseAt = $CloseAt + } +} diff --git a/tests/srcTestRepo/src/classes/public/ReadingList.ps1 b/tests/srcTestRepo/src/classes/public/ReadingList.ps1 new file mode 100644 index 00000000..9acadeff --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/ReadingList.ps1 @@ -0,0 +1,7 @@ +class ReadingList { + [Book[]] $Books + + ReadingList([Book[]]$Books) { + $this.Books = $Books + } +} diff --git a/tests/srcTestRepo/src/classes/public/ShelfLocation.ps1 b/tests/srcTestRepo/src/classes/public/ShelfLocation.ps1 new file mode 100644 index 00000000..e492d713 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/ShelfLocation.ps1 @@ -0,0 +1,11 @@ +class ShelfLocation { + [string] $BranchCode + [string] $Section + [string] $Shelf + + ShelfLocation([string]$BranchCode, [string]$Section, [string]$Shelf) { + $this.BranchCode = $BranchCode + $this.Section = $Section + $this.Shelf = $Shelf + } +} diff --git a/tests/srcTestRepo/src/classes/public/ZCatalog.ps1 b/tests/srcTestRepo/src/classes/public/ZCatalog.ps1 new file mode 100644 index 00000000..1458c4d7 --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/ZCatalog.ps1 @@ -0,0 +1,11 @@ +class ZCatalog { + [string] $CatalogName + [CatalogSection[]] $Sections + [BranchLibrary[]] $Branches + + ZCatalog([string]$CatalogName, [CatalogSection[]]$Sections, [BranchLibrary[]]$Branches) { + $this.CatalogName = $CatalogName + $this.Sections = $Sections + $this.Branches = $Branches + } +} diff --git a/tests/srcTestRepo/src/classes/public/ZetaCirculationNode.ps1 b/tests/srcTestRepo/src/classes/public/ZetaCirculationNode.ps1 new file mode 100644 index 00000000..5ecd524e --- /dev/null +++ b/tests/srcTestRepo/src/classes/public/ZetaCirculationNode.ps1 @@ -0,0 +1,9 @@ +class ZetaCirculationNode { + [string] $Id + [AlphaCirculationNode] $Previous + + ZetaCirculationNode([string]$Id, [AlphaCirculationNode]$Previous) { + $this.Id = $Id + $this.Previous = $Previous + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/ActiveLoanRegister.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/ActiveLoanRegister.ps1 new file mode 100644 index 00000000..fb4e98cd --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/ActiveLoanRegister.ps1 @@ -0,0 +1,11 @@ +class ActiveLoanRegister { + [System.Collections.Generic.List[BookLoan]] $Loans + + ActiveLoanRegister() { + $this.Loans = [System.Collections.Generic.List[BookLoan]]::new() + } + + [void] AddLoan([BookLoan]$Loan) { + $this.Loans.Add($Loan) + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/AlphaCirculationNode.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/AlphaCirculationNode.ps1 new file mode 100644 index 00000000..d7e10b5e --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/AlphaCirculationNode.ps1 @@ -0,0 +1,9 @@ +class AlphaCirculationNode { + [string] $Id + [ZetaCirculationNode] $Next + + AlphaCirculationNode([string]$Id, [ZetaCirculationNode]$Next) { + $this.Id = $Id + $this.Next = $Next + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/AuthorIndex.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/AuthorIndex.ps1 new file mode 100644 index 00000000..c379af92 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/AuthorIndex.ps1 @@ -0,0 +1,11 @@ +class AuthorIndex { + [string] $Name + [AuthorProfile[]] $Authors + [ZCatalog] $Catalog + + AuthorIndex([string]$Name, [ZCatalog]$Catalog) { + $this.Name = $Name + $this.Catalog = $Catalog + $this.Authors = @() + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/AuthorProfile.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/AuthorProfile.ps1 new file mode 100644 index 00000000..6a86fa35 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/AuthorProfile.ps1 @@ -0,0 +1,9 @@ +class AuthorProfile { + [string] $Name + [Book[]] $PublishedBooks + + AuthorProfile([string]$Name, [Book[]]$PublishedBooks) { + $this.Name = $Name + $this.PublishedBooks = $PublishedBooks + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/Book.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/Book.ps1 index 8917d9ab..a3c7a7ca 100644 --- a/tests/srcWithManifestTestRepo/src/classes/public/Book.ps1 +++ b/tests/srcWithManifestTestRepo/src/classes/public/Book.ps1 @@ -44,93 +44,6 @@ } } -class BookList { - # Static property to hold the list of books - static [System.Collections.Generic.List[Book]] $Books - # Static method to initialize the list of books. Called in the other - # static methods to avoid needing to explicit initialize the value. - static [void] Initialize() { [BookList]::Initialize($false) } - static [bool] Initialize([bool]$force) { - if ([BookList]::Books.Count -gt 0 -and -not $force) { - return $false - } - - [BookList]::Books = [System.Collections.Generic.List[Book]]::new() - - return $true - } - # Ensure a book is valid for the list. - static [void] Validate([book]$Book) { - $Prefix = @( - 'Book validation failed: Book must be defined with the Title,' - 'Author, and PublishDate properties, but' - ) -join ' ' - if ($null -eq $Book) { throw "$Prefix was null" } - if ([string]::IsNullOrEmpty($Book.Title)) { - throw "$Prefix Title wasn't defined" - } - if ([string]::IsNullOrEmpty($Book.Author)) { - throw "$Prefix Author wasn't defined" - } - if ([datetime]::MinValue -eq $Book.PublishDate) { - throw "$Prefix PublishDate wasn't defined" - } - } - # Static methods to manage the list of books. - # Add a book if it's not already in the list. - static [void] Add([Book]$Book) { - [BookList]::Initialize() - [BookList]::Validate($Book) - if ([BookList]::Books.Contains($Book)) { - throw "Book '$Book' already in list" - } - - $FindPredicate = { - param([Book]$b) - - $b.Title -eq $Book.Title -and - $b.Author -eq $Book.Author -and - $b.PublishDate -eq $Book.PublishDate - }.GetNewClosure() - if ([BookList]::Books.Find($FindPredicate)) { - throw "Book '$Book' already in list" - } - - [BookList]::Books.Add($Book) - } - # Clear the list of books. - static [void] Clear() { - [BookList]::Initialize() - [BookList]::Books.Clear() - } - # Find a specific book using a filtering scriptblock. - static [Book] Find([scriptblock]$Predicate) { - [BookList]::Initialize() - return [BookList]::Books.Find($Predicate) - } - # Find every book matching the filtering scriptblock. - static [Book[]] FindAll([scriptblock]$Predicate) { - [BookList]::Initialize() - return [BookList]::Books.FindAll($Predicate) - } - # Remove a specific book. - static [void] Remove([Book]$Book) { - [BookList]::Initialize() - [BookList]::Books.Remove($Book) - } - # Remove a book by property value. - static [void] RemoveBy([string]$Property, [string]$Value) { - [BookList]::Initialize() - $Index = [BookList]::Books.FindIndex({ - param($b) - $b.$Property -eq $Value - }.GetNewClosure()) - if ($Index -ge 0) { - [BookList]::Books.RemoveAt($Index) - } - } -} - enum Binding { Hardcover Paperback diff --git a/tests/srcWithManifestTestRepo/src/classes/public/BookCopy.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/BookCopy.ps1 new file mode 100644 index 00000000..bee184b1 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/BookCopy.ps1 @@ -0,0 +1,11 @@ +class BookCopy { + [string] $InventoryId + [Book] $Book + [ShelfLocation] $Location + + BookCopy([string]$InventoryId, [Book]$Book, [ShelfLocation]$Location) { + $this.InventoryId = $InventoryId + $this.Book = $Book + $this.Location = $Location + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/BookInventory.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/BookInventory.ps1 new file mode 100644 index 00000000..cf7948e3 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/BookInventory.ps1 @@ -0,0 +1,11 @@ +class BookInventory { + [string] $Name + [BookCopy[]] $Copies + [ZCatalog] $Catalog + + BookInventory([string]$Name, [ZCatalog]$Catalog) { + $this.Name = $Name + $this.Catalog = $Catalog + $this.Copies = @() + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/BookList.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/BookList.ps1 new file mode 100644 index 00000000..bf421618 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/BookList.ps1 @@ -0,0 +1,57 @@ +class BookList { + static [System.Collections.Generic.List[Book]] $Books + + static [void] Initialize() { [BookList]::Initialize($false) } + static [bool] Initialize([bool]$force) { + if ([BookList]::Books.Count -gt 0 -and -not $force) { + return $false + } + + [BookList]::Books = [System.Collections.Generic.List[Book]]::new() + + return $true + } + + static [void] Validate([Book]$Book) { + $Prefix = @( + 'Book validation failed: Book must be defined with the Title,' + 'Author, and PublishDate properties, but' + ) -join ' ' + if ($null -eq $Book) { throw "$Prefix was null" } + if ([string]::IsNullOrEmpty($Book.Title)) { throw "$Prefix Title wasn't defined" } + if ([string]::IsNullOrEmpty($Book.Author)) { throw "$Prefix Author wasn't defined" } + if ([datetime]::MinValue -eq $Book.PublishDate) { throw "$Prefix PublishDate wasn't defined" } + } + + static [void] Add([Book]$Book) { + [BookList]::Initialize() + [BookList]::Validate($Book) + if ([BookList]::Books.Contains($Book)) { throw "Book '$Book' already in list" } + + $findPredicate = { + param([Book]$b) + + $b.Title -eq $Book.Title -and + $b.Author -eq $Book.Author -and + $b.PublishDate -eq $Book.PublishDate + }.GetNewClosure() + if ([BookList]::Books.Find($findPredicate)) { throw "Book '$Book' already in list" } + + [BookList]::Books.Add($Book) + } + + static [void] Clear() { + [BookList]::Initialize() + [BookList]::Books.Clear() + } + + static [Book] Find([scriptblock]$Predicate) { + [BookList]::Initialize() + return [BookList]::Books.Find($Predicate) + } + + static [Book[]] FindAll([scriptblock]$Predicate) { + [BookList]::Initialize() + return [BookList]::Books.FindAll($Predicate) + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/BookLoan.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/BookLoan.ps1 new file mode 100644 index 00000000..fc0f6163 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/BookLoan.ps1 @@ -0,0 +1,13 @@ +class BookLoan { + [BookCopy] $Copy + [MemberAccount] $Member + [datetime] $LoanDate + [datetime] $DueDate + + BookLoan([BookCopy]$Copy, [MemberAccount]$Member, [DueDatePolicy]$Policy) { + $this.Copy = $Copy + $this.Member = $Member + $this.LoanDate = Get-Date + $this.DueDate = $this.LoanDate.AddDays($Policy.StandardLoanDays) + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/BranchLibrary.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/BranchLibrary.ps1 new file mode 100644 index 00000000..3ee2fd20 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/BranchLibrary.ps1 @@ -0,0 +1,11 @@ +class BranchLibrary { + [string] $Code + [string] $Name + [OpeningHours] $Hours + + BranchLibrary([string]$Code, [string]$Name, [OpeningHours]$Hours) { + $this.Code = $Code + $this.Name = $Name + $this.Hours = $Hours + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/CatalogSection.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/CatalogSection.ps1 new file mode 100644 index 00000000..10352122 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/CatalogSection.ps1 @@ -0,0 +1,9 @@ +class CatalogSection { + [string] $Name + [Book[]] $Books + + CatalogSection([string]$Name, [Book[]]$Books) { + $this.Name = $Name + $this.Books = $Books + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/DueDatePolicy.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/DueDatePolicy.ps1 new file mode 100644 index 00000000..2803f489 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/DueDatePolicy.ps1 @@ -0,0 +1,9 @@ +class DueDatePolicy { + [int] $StandardLoanDays + [int] $GraceDays + + DueDatePolicy([int]$StandardLoanDays, [int]$GraceDays) { + $this.StandardLoanDays = $StandardLoanDays + $this.GraceDays = $GraceDays + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/LibraryReport.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/LibraryReport.ps1 new file mode 100644 index 00000000..dfa84fe7 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/LibraryReport.ps1 @@ -0,0 +1,18 @@ +class LibraryReport { + [AuthorIndex] $Authors + [ActiveLoanRegister] $ActiveLoans + [BookInventory] $Inventory + [ZCatalog] $Catalog + + LibraryReport( + [AuthorIndex]$Authors, + [ActiveLoanRegister]$ActiveLoans, + [BookInventory]$Inventory, + [ZCatalog]$Catalog + ) { + $this.Authors = $Authors + $this.ActiveLoans = $ActiveLoans + $this.Inventory = $Inventory + $this.Catalog = $Catalog + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/MemberAccount.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/MemberAccount.ps1 new file mode 100644 index 00000000..c292f231 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/MemberAccount.ps1 @@ -0,0 +1,11 @@ +class MemberAccount { + [string] $MemberId + [string] $DisplayName + [ReadingList] $ReadingList + + MemberAccount([string]$MemberId, [string]$DisplayName, [ReadingList]$ReadingList) { + $this.MemberId = $MemberId + $this.DisplayName = $DisplayName + $this.ReadingList = $ReadingList + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/OpeningHours.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/OpeningHours.ps1 new file mode 100644 index 00000000..4be09375 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/OpeningHours.ps1 @@ -0,0 +1,9 @@ +class OpeningHours { + [timespan] $OpenAt + [timespan] $CloseAt + + OpeningHours([timespan]$OpenAt, [timespan]$CloseAt) { + $this.OpenAt = $OpenAt + $this.CloseAt = $CloseAt + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/ReadingList.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/ReadingList.ps1 new file mode 100644 index 00000000..9acadeff --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/ReadingList.ps1 @@ -0,0 +1,7 @@ +class ReadingList { + [Book[]] $Books + + ReadingList([Book[]]$Books) { + $this.Books = $Books + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/ShelfLocation.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/ShelfLocation.ps1 new file mode 100644 index 00000000..e492d713 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/ShelfLocation.ps1 @@ -0,0 +1,11 @@ +class ShelfLocation { + [string] $BranchCode + [string] $Section + [string] $Shelf + + ShelfLocation([string]$BranchCode, [string]$Section, [string]$Shelf) { + $this.BranchCode = $BranchCode + $this.Section = $Section + $this.Shelf = $Shelf + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/ZCatalog.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/ZCatalog.ps1 new file mode 100644 index 00000000..1458c4d7 --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/ZCatalog.ps1 @@ -0,0 +1,11 @@ +class ZCatalog { + [string] $CatalogName + [CatalogSection[]] $Sections + [BranchLibrary[]] $Branches + + ZCatalog([string]$CatalogName, [CatalogSection[]]$Sections, [BranchLibrary[]]$Branches) { + $this.CatalogName = $CatalogName + $this.Sections = $Sections + $this.Branches = $Branches + } +} diff --git a/tests/srcWithManifestTestRepo/src/classes/public/ZetaCirculationNode.ps1 b/tests/srcWithManifestTestRepo/src/classes/public/ZetaCirculationNode.ps1 new file mode 100644 index 00000000..5ecd524e --- /dev/null +++ b/tests/srcWithManifestTestRepo/src/classes/public/ZetaCirculationNode.ps1 @@ -0,0 +1,9 @@ +class ZetaCirculationNode { + [string] $Id + [AlphaCirculationNode] $Previous + + ZetaCirculationNode([string]$Id, [AlphaCirculationNode]$Previous) { + $this.Id = $Id + $this.Previous = $Previous + } +}