test.ps1

param
(
    [string] $login = $(throw "Please specify a fex.net login."),
    [string] $password =  $(throw "Please specify a fex.net password.")
)

Import-Module -Name "$PSScriptRoot\FexTools.psd1"  -Verbose

$uploadfolder = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(),[System.IO.Path]::GetRandomFileName())
$downloadfolder = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(),[System.IO.Path]::GetRandomFileName())

[System.IO.Directory]::CreateDirectory($uploadfolder)
[System.IO.Directory]::CreateDirectory($downloadfolder)

[System.IO.Directory]::CreateDirectory("$uploadfolder\1\11")

[System.IO.File]::WriteAllText("$uploadfolder\1\1.txt", "test1")
[System.IO.File]::WriteAllText("$uploadfolder\1\11\11.txt", "test2")

Try
{
    [Net.Fex.Api.IConnection] $connection = New-FexConnection "https://fex.net" $login $password

    if ($connection.IsSignedIn)
    {
        Try
        {
            $token = $connection.CreateObject().Token
            Try
            {
                $connection.ObjectSetDeleteTime($token, [System.DateTime]::Now.AddHours(1));
                Send-FexFolder $connection $token $uploadfolder
                Receive-FexFolder $connection $token $downloadfolder
            }
            Finally
            {
                $connection.DeleteObject($token);
            }
        }
        Finally
        {
            $connection.SignOut();
            [System.Diagnostics.Trace]::Flush()        
        }
    }

    $ok = [System.IO.Directory]::Exists("$uploadfolder\1")
    $ok = $ok -and [System.IO.Directory]::Exists("$uploadfolder\1\11")
    $ok = $ok -and [System.IO.File]::Exists("$uploadfolder\1\11\11.txt")
    $ok = $ok -and [System.IO.File]::Exists("$uploadfolder\1\1.txt")

    [bool]$bFilesAreEqual = [System.Linq.Enumerable]::SequenceEqual([System.IO.File]::ReadAllBytes("$uploadfolder\1\1.txt"), [System.IO.File]::ReadAllBytes("$downloadfolder\1\1.txt"))
    $ok = $ok -and $bFilesAreEqual

    [bool]$bFilesAreEqual = [System.Linq.Enumerable]::SequenceEqual([System.IO.File]::ReadAllBytes("$uploadfolder\1\11\11.txt"), [System.IO.File]::ReadAllBytes("$downloadfolder\1\11\11.txt"))
    $ok = $ok -and $bFilesAreEqual

    if (!$ok)
    {
        Write-Error "Comparsion error"
    }
}
Finally
{
    [System.IO.Directory]::Delete($uploadfolder, $true)
    [System.IO.Directory]::Delete($downloadfolder, $true)
}