Skip to content

Commit

Permalink
Issue 4 - feat: [function]How Can I Create File Names Based on Their …
Browse files Browse the repository at this point in the history
…Time Stamp? (#16)
  • Loading branch information
rulasg committed Jun 12, 2023
1 parent 09ecc2e commit 72cd579
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 51 deletions.
11 changes: 6 additions & 5 deletions Docs.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ function Get-DocsFile {
} # Export-ModuleMember -Function Get-DocsFile


function global:Get-DocsName{
function Get-DocsName{
[CmdletBinding()]
[Alias("gdn")]
Param(
Expand All @@ -776,10 +776,6 @@ function global:Get-DocsName{
)

# 201001-rulasg-edp-FacturaLuzGas-203#08-1HSN201000025360.pdf

begin{

}

process{

Expand All @@ -798,6 +794,11 @@ function global:Get-DocsName{

foreach ($file in $files) {


# #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 | Add-MyMember -NotePropertyName Path -NotePropertyValue $file
Expand Down
71 changes: 25 additions & 46 deletions DocsTest/DocsTest.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ResetDocsList([switch]$PassThru) {
}
}

function Get-SampleFunction1{
function Get-ParameterObject{
[CmdletBinding()]

param(
Expand All @@ -40,7 +40,7 @@ function Get-SampleFunction1{
[parameter(ValueFromPipelineByPropertyName)][string]$Type
)


process{
$result = @{
Description = $Description
PreDescription = $PreDescription
Expand All @@ -53,62 +53,41 @@ function Get-SampleFunction1{
}

return $result
}

}

function Get-SampleFunction2{
[CmdletBinding()]
function DocsTest_GetDocsName_Parameters{

param(
[parameter(ValueFromPipelineByPropertyName)][string]$Description,
[parameter(ValueFromPipelineByPropertyName)][string]$PreDescription,
[parameter(ValueFromPipelineByPropertyName)][string]$Date,
[parameter(ValueFromPipelineByPropertyName)][string]$Owner,
[parameter(ValueFromPipelineByPropertyName)][string]$Target,
[parameter(ValueFromPipelineByPropertyName)][string]$Amount,
[parameter(ValueFromPipelineByPropertyName)][string]$What,
[parameter(ValueFromPipelineByPropertyName)][string]$Type
)
New-TestingFile -Name "test1.txt" -Content "test"
New-TestingFile -Name "test2.txt" -Content "test"

$result = Get-ChildItem | Get-DocsName -Owner "MyOwner" -Target "MyTarget" -What "MyWhat" -Type "MyType" -Amount "MyAmount" -Date "111111"

begin {
}
Assert-Count -Expected 2 -Presented $result

process{
$result = @{
Description = $Description
PreDescription = $PreDescription
Date = $Date
Owner = $Owner
Target = $Target
Amount = $Amount
What = $What
Type = $Type
}

return $result
}
Assert-AreEqual -Expected @("MyOwner","MyOwner").ToString() -Presented $result.Owner.ToString().ToString()
Assert-AreEqual -Expected @("MyTarget","MyTarget").ToString() -Presented $result.Target.ToString()
Assert-AreEqual -Expected @("MyWhat","MyWhat").ToString() -Presented $result.What.ToString()
Assert-AreEqual -Expected @("MyType","MyType").ToString() -Presented $result.Type.ToString()
Assert-AreEqual -Expected @("MyAmount","MyAmount").ToString() -Presented $result.Amount.ToString()
Assert-AreEqual -Expected @("111111","111111").ToString() -Presented $result.Date.ToString()

Assert-Contains -Expected "test1" -Presented $result.Description
Assert-Contains -Expected "test2" -Presented $result.Description
}

function DocsTest_NamedParameter{
function DocsTest_GetDocsName_DefaultDate{

$files = @()
$files += New-TestingFile -Name "test1.txt" -Content "test" -PassThru
$files += New-TestingFile -Name "test2.txt" -Content "test" -PassThru
$CreationTime = (Get-Date).Adddays(-5)

$file = New-TestingFile -Name "test1.txt" -Content "test" -PassThru

$docName = Get-ChildItem $files | Get-DocsName -Owner "MyOwner" -Target "MyTarget" -What MyWhat -Type MyType -Amount MyAmount
$file.CreationTime = $CreationTime

$result1 = $docName | Get-SampleFunction1

Assert-AreEqual -Expected "MyOwner" -Presented $result1.Owner

$result2 = $docName | Get-SampleFunction2

Assert-AreEqual -Expected @("MyOwner","MyOwner").ToString() -Presented $result2.Owner.ToString()

$result3 = $docName | Get-DocsName

Assert-AreEqual -Expected @("MyOwner","MyOwner").ToString() -Presented $result3.Owner.ToString()
$result = Get-ChildItem | Get-DocsName

Assert-IsTrue -Condition $result.NewName.StartsWith($CreationTime.ToString("yyMMdd"))
}

function DocsTest_ResetStores {
Expand Down

0 comments on commit 72cd579

Please sign in to comment.