From 0b21f1b335c7d4a7716aacf6be474cacba58a040 Mon Sep 17 00:00:00 2001 From: rulasg Date: Fri, 6 Oct 2023 16:48:02 +0200 Subject: [PATCH 1/4] bug: Get-DocsName does not set proper date --- Docs.psm1 | 6 ++---- DocsTest/DocsTest.psm1 | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Docs.psm1 b/Docs.psm1 index 2d5eced..9c0d8d3 100755 --- a/Docs.psm1 +++ b/Docs.psm1 @@ -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() diff --git a/DocsTest/DocsTest.psm1 b/DocsTest/DocsTest.psm1 index 21bdf56..aa17d6c 100755 --- a/DocsTest/DocsTest.psm1 +++ b/DocsTest/DocsTest.psm1 @@ -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) @@ -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 From 44897713caf4999d2e336778191b2190c3c63a7a Mon Sep 17 00:00:00 2001 From: rulasg Date: Fri, 6 Oct 2023 16:51:19 +0200 Subject: [PATCH 2/4] remove NotImplemented test --- DocsTest/DocsTest.psm1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/DocsTest/DocsTest.psm1 b/DocsTest/DocsTest.psm1 index aa17d6c..b7a8871 100755 --- a/DocsTest/DocsTest.psm1 +++ b/DocsTest/DocsTest.psm1 @@ -1822,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]]' From 5cbe3f6588bfd42d2f89e27ac34acf9c0f98edbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 6 Oct 2023 15:43:50 +0000 Subject: [PATCH 3/4] bug: Pipe failing --- Docs.psm1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Docs.psm1 b/Docs.psm1 index 9c0d8d3..e70e7d8 100755 --- a/Docs.psm1 +++ b/Docs.psm1 @@ -1027,8 +1027,15 @@ function Test-DocsFile { $Path ??= "." - # file name format - $files = Get-ChildItem -Path $Path -File 2> $null + + try { + # if file does not exist Actions pipe files. + # 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 From 49e5034d139a73632b85a24f392af70c84220fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Fri, 6 Oct 2023 15:55:17 +0000 Subject: [PATCH 4/4] format --- Docs.psm1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Docs.psm1 b/Docs.psm1 index e70e7d8..7b4b4ab 100755 --- a/Docs.psm1 +++ b/Docs.psm1 @@ -1027,9 +1027,8 @@ function Test-DocsFile { $Path ??= "." - try { - # if file does not exist Actions pipe files. + # if file does not exist Actions pipe fails. # Adding try catch to avoid terminating exceptions $files = Get-ChildItem -Path $Path -File 2> $null }