Skip to content

Commit

Permalink
Merge pull request #21 from rulasg/20-bug-get-docsname-does-not-set-p…
Browse files Browse the repository at this point in the history
…roper-date

bug: Get-DocsName does not set proper date
  • Loading branch information
rulasg committed Oct 6, 2023
2 parents c75c6b1 + 49e5034 commit 3429993
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
16 changes: 10 additions & 6 deletions Docs.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,10 @@ function Get-DocsName{

foreach ($file in $files) {

$ret = $file | ConvertTo-DocsDocName @param

# #4 feat: [function]How Can I Create File Names Based on Their Time Stamp?
# Set default values for file name based on the file
$param.Date = [string]::IsNullOrWhiteSpace($param.Date) ? $file.CreationTime.ToString("yyMMdd") : $param.Date

$ret = $file | ConvertTo-DocsDocName @param
$ret.Date = [string]::IsNullOrWhiteSpace($ret.Date) ? $file.CreationTime.ToString("yyMMdd") : $ret.Date

$ret | Add-MyMember -NotePropertyName Path -NotePropertyValue $file
$ret | Add-MyMember -NotePropertyName NewName -NotePropertyValue $ret.Name()
Expand Down Expand Up @@ -1029,8 +1027,14 @@ function Test-DocsFile {

$Path ??= "."

# file name format
$files = Get-ChildItem -Path $Path -File 2> $null
try {
# if file does not exist Actions pipe fails.
# Adding try catch to avoid terminating exceptions
$files = Get-ChildItem -Path $Path -File 2> $null
}
catch {
$files = $null
}

if ($files.Length -eq 0) {
return $false
Expand Down
25 changes: 19 additions & 6 deletions DocsTest/DocsTest.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function DocsTest_GetDocsName_Parameters{
Assert-Contains -Expected "test2" -Presented $result.Description
}

function DocsTest_GetDocsName_DefaultDate{
function DocsTest_GetDocsName_DefaultDate_FileReationTime{

$CreationTime = (Get-Date).Adddays(-5)

Expand All @@ -90,6 +90,24 @@ function DocsTest_GetDocsName_DefaultDate{
Assert-IsTrue -Condition $result.NewName.StartsWith($CreationTime.ToString("yyMMdd"))
}

function DocsTest_GetDocsName_ReadFilesNameValues{

$fileName = (New-DocsDocName -Owner "MyOwner" -Target "MyTarget" -What "MyWhat" -Type "MyType" -Amount "999#99" -Date "111111" -Description "MyDescription").Name()

New-TestingFile -Name $fileName

$result = Get-DocsName -Path $fileName

Assert-AreEqual -Expected "MyOwner" -Presented $result.Owner
Assert-AreEqual -Expected "MyTarget" -Presented $result.Target
Assert-AreEqual -Expected "MyWhat" -Presented $result.What
Assert-AreEqual -Expected "MyType" -Presented $result.Type
Assert-AreEqual -Expected "999#99" -Presented $result.Amount
Assert-AreEqual -Expected "MyDescription" -Presented $result.Description

Assert-AreEqual -Expected "111111" -Presented $result.Date
}

function DocsTest_ResetStores {

$TestStoreList = ResetDocsList -PassThru
Expand Down Expand Up @@ -1804,11 +1822,6 @@ function DocsTest_ConvertToFile_Pipe_String{
Assert-Count -Expected 3 -Presented (Get-ChildItem)
}

function DocsTest_GetDocsName_Simple{

Assert-NotImplemented
}

function SetupScenario1 () {

$Evidence = New-Object 'System.Collections.Generic.Dictionary[[string],[string]]'
Expand Down

0 comments on commit 3429993

Please sign in to comment.