<commit_before>$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace(".Tests", "")
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\..\psmake\ext\psmake.core.ps1"
. "$here\$sut"

# Prepare test projects
call "$($env:windir)\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "$PSScriptRoot\TestSolution\Testsolution.sln" /t:"Clean,Build" /p:Configuration=Release /m /verbosity:m /nologo /p:TreatWarningsAsErrors=true


Describe "Define-NUnitTests" {
    
    It "It should use group name as report name if second is not sepcified" {
        $def = Define-NUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'my_group'
    }

    It "It should define tests with group name and report name" {
        $def = Define-NUnitTests -GroupName 'my group' -ReportName 'test-reports' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'test-reports'
    }

    It "It should define tests with default runner version" {
        $def = Define-NUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '2.6.3'
    }

    It "It should define tests with sepcified runner version" {
        $def = Define-NUnitTests -GroupName 'my group' -NUnitVersion '2.6.4' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '2.6.4'
    }
        
    It "It should allow to specify one assembly" {
        $def = Define-NUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\Passing.NUnit.Tests1\bin\Release\Passing.NUnit.Tests1.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 1
        $def.Assemblies[0] | Should Be "$PSScriptRoot\TestSolution\Passing.NUnit.Tests1\bin\Release\Passing.NUnit.Tests1.dll"
    }

    It "It should allow to specify multiple assemblies" {
        $def = Define-NUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\Passing.NUnit.Tests1\bin\Release\Passing.NUnit.Tests1.dll", "$PSScriptRoot\TestSolution\Passing.NUnit.Tests2\bin\Release\Passing.NUnit.Tests2.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 2
        $def.Assemblies[0] | Should Be "$PSScriptRoot\TestSolution\Passing.NUnit.Tests1\bin\Release\Passing.NUnit.Tests1.dll"
        $def.Assemblies[1] | Should Be "$PSScriptRoot\TestSolution\Passing.NUnit.Tests2\bin\Release\Passing.NUnit.Tests2.dll"
    }

    It "It should resolve assembly names with wildcards" {
        $def = Define-NUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\*\bin\Release\*.NUnit.Tests*.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 3
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Passing.NUnit.Tests1\bin\Release\Passing.NUnit.Tests1.dll") | Should Be $true
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Passing.NUnit.Tests2\bin\Release\Passing.NUnit.Tests2.dll") | Should Be $true
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Failing.NUnit.Tests\bin\Release\Failing.NUnit.Tests.dll") | Should Be $true
    }
}

Describe "Define-MbUnitTests" {
    
    It "It should use group name as report name if second is not sepcified" {
        $def = Define-MbUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'my_group'
    }

    It "It should define tests with group name and report name" {
        $def = Define-MbUnitTests -GroupName 'my group' -ReportName 'test-reports' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'test-reports'
    }

    It "It should define tests with default runner version" {
        $def = Define-MbUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '3.4.14.0'
    }

    It "It should define tests with sepcified runner version" {
        $def = Define-MbUnitTests -GroupName 'my group' -MbUnitVersion '3.4.15.0' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '3.4.15.0'
    }
        
    It "It should allow to specify one assembly" {
        $def = Define-MbUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests1\bin\Release\Passing.MbUnit.Tests1.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 1
        $def.Assemblies[0] | Should Be "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests1\bin\Release\Passing.MbUnit.Tests1.dll"
    }

    It "It should allow to specify multiple assemblies" {
        $def = Define-MbUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests1\bin\Release\Passing.MbUnit.Tests1.dll", "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests2\bin\Release\Passing.MbUnit.Tests2.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 2
        $def.Assemblies[0] | Should Be "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests1\bin\Release\Passing.MbUnit.Tests1.dll"
        $def.Assemblies[1] | Should Be "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests2\bin\Release\Passing.MbUnit.Tests2.dll"
    }

    It "It should resolve assembly names with wildcards" {
        $def = Define-MbUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\*\bin\Release\*.MbUnit.Tests*.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 3
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Passing.MbUnit.Tests1\bin\Release\Passing.MbUnit.Tests1.dll") | Should Be $true
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Passing.MbUnit.Tests2\bin\Release\Passing.MbUnit.Tests2.dll") | Should Be $true
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Failing.MbUnit.Tests\bin\Release\Failing.MbUnit.Tests.dll") | Should Be $true
    }
}

Describe "Define-MsTests" {
    
    It "It should use group name as report name if second is not sepcified" {
        $def = Define-MsTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'my_group'
    }

    It "It should define tests with group name and report name" {
        $def = Define-MsTests -GroupName 'my group' -ReportName 'test-reports' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'test-reports'
    }

    It "It should define tests with default runner version" {
        $def = Define-MsTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.Runner | Should Match '12\.0'
    }

    It "It should define tests with sepcified runner version" {
        $def = Define-MsTests -GroupName 'my group' -VisualStudioVersion '11.0' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.Runner | Should Match '11\.0'
    }
        
    It "It should allow to specify one assembly" {
        $def = Define-MsTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\Passing.MsTest.Tests1\bin\Release\Passing.MsTest.Tests1.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 1
        $def.Assemblies[0] | Should Be "$PSScriptRoot\TestSolution\Passing.MsTest.Tests1\bin\Release\Passing.MsTest.Tests1.dll"
    }

    It "It should allow to specify multiple assemblies" {
        $def = Define-MsTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\Passing.MsTest.Tests1\bin\Release\Passing.MsTest.Tests1.dll", "$PSScriptRoot\TestSolution\Passing.MsTest.Tests2\bin\Release\Passing.MsTest.Tests2.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 2
        $def.Assemblies[0] | Should Be "$PSScriptRoot\TestSolution\Passing.MsTest.Tests1\bin\Release\Passing.MsTest.Tests1.dll"
        $def.Assemblies[1] | Should Be "$PSScriptRoot\TestSolution\Passing.MsTest.Tests2\bin\Release\Passing.MsTest.Tests2.dll"
    }

    It "It should resolve assembly names with wildcards" {
        $def = Define-MsTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\*\bin\Release\*.MsTest.Tests*.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 3
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Passing.MsTest.Tests1\bin\Release\Passing.MsTest.Tests1.dll") | Should Be $true
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Passing.MsTest.Tests2\bin\Release\Passing.MsTest.Tests2.dll") | Should Be $true
        $def.Assemblies.Contains("$PSScriptRoot\TestSolution\Failing.MsTest.Tests\bin\Release\Failing.MsTest.Tests.dll") | Should Be $true
    }
}<commit_msg>psmake.mod.testing: added simple test run tests<commit_after>$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace(".Tests", "")
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\..\psmake\ext\psmake.core.ps1"
. "$here\$sut"

# Prepare test context
$Context = Create-Object @{MakeDirectory=$PSScriptRoot; NuGetExe='.nuget\nuget.exe';}

# Prepare test projects
call "$($env:windir)\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "$PSScriptRoot\TestSolution\Testsolution.sln" /t:"Clean,Build" /p:Configuration=Release /m /verbosity:m /nologo /p:TreatWarningsAsErrors=true

$PassingNUnit1 = "$PSScriptRoot\TestSolution\Passing.NUnit.Tests1\bin\Release\Passing.NUnit.Tests1.dll"
$PassingNUnit2 = "$PSScriptRoot\TestSolution\Passing.NUnit.Tests2\bin\Release\Passing.NUnit.Tests2.dll"
$FailingNUnit = "$PSScriptRoot\TestSolution\Failing.NUnit.Tests\bin\Release\Failing.NUnit.Tests.dll"

$PassingMbUnit1 = "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests1\bin\Release\Passing.MbUnit.Tests1.dll"
$PassingMbUnit2 = "$PSScriptRoot\TestSolution\Passing.MbUnit.Tests2\bin\Release\Passing.MbUnit.Tests2.dll"
$FailingMbUnit =  "$PSScriptRoot\TestSolution\Failing.MbUnit.Tests\bin\Release\Failing.MbUnit.Tests.dll"

$PassingMsTest1 = "$PSScriptRoot\TestSolution\Passing.MsTest.Tests1\bin\Release\Passing.MsTest.Tests1.dll"
$PassingMsTest2 = "$PSScriptRoot\TestSolution\Passing.MsTest.Tests2\bin\Release\Passing.MsTest.Tests2.dll"
$FailingMsTest = "$PSScriptRoot\TestSolution\Failing.MsTest.Tests\bin\Release\Failing.MsTest.Tests.dll"

Describe "Define-NUnitTests" {
    
    It "It should use group name as report name if second is not sepcified" {
        $def = Define-NUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'my_group'
    }

    It "It should define tests with group name and report name" {
        $def = Define-NUnitTests -GroupName 'my group' -ReportName 'test-reports' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'test-reports'
    }

    It "It should define tests with default runner version" {
        $def = Define-NUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '2.6.3'
    }

    It "It should define tests with sepcified runner version" {
        $def = Define-NUnitTests -GroupName 'my group' -NUnitVersion '2.6.4' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '2.6.4'
    }
        
    It "It should allow to specify one assembly" {
        $def = Define-NUnitTests -GroupName 'group' -TestAssembly $PassingNUnit1
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 1
        $def.Assemblies[0] | Should Be $PassingNUnit1
    }

    It "It should allow to specify multiple assemblies" {
        $def = Define-NUnitTests -GroupName 'group' -TestAssembly $PassingNUnit1, $PassingNUnit2
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 2
        $def.Assemblies[0] | Should Be $PassingNUnit1
        $def.Assemblies[1] | Should Be $PassingNUnit2
    }

    It "It should resolve assembly names with wildcards" {
        $def = Define-NUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\*\bin\Release\*.NUnit.Tests*.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 3
        $def.Assemblies.Contains($PassingNUnit1) | Should Be $true
        $def.Assemblies.Contains($PassingNUnit2) | Should Be $true
        $def.Assemblies.Contains($FailingNUnit) | Should Be $true
    }
}

Describe "Define-MbUnitTests" {
    
    It "It should use group name as report name if second is not sepcified" {
        $def = Define-MbUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'my_group'
    }

    It "It should define tests with group name and report name" {
        $def = Define-MbUnitTests -GroupName 'my group' -ReportName 'test-reports' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'test-reports'
    }

    It "It should define tests with default runner version" {
        $def = Define-MbUnitTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '3.4.14.0'
    }

    It "It should define tests with sepcified runner version" {
        $def = Define-MbUnitTests -GroupName 'my group' -MbUnitVersion '3.4.15.0' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.PackageVersion | Should Be '3.4.15.0'
    }
        
    It "It should allow to specify one assembly" {
        $def = Define-MbUnitTests -GroupName 'group' -TestAssembly $PassingMbUnit1
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 1
        $def.Assemblies[0] | Should Be $PassingMbUnit1
    }

    It "It should allow to specify multiple assemblies" {
        $def = Define-MbUnitTests -GroupName 'group' -TestAssembly $PassingMbUnit1, $PassingMbUnit2
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 2
        $def.Assemblies[0] | Should Be $PassingMbUnit1
        $def.Assemblies[1] | Should Be $PassingMbUnit2
    }

    It "It should resolve assembly names with wildcards" {
        $def = Define-MbUnitTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\*\bin\Release\*.MbUnit.Tests*.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 3
        $def.Assemblies.Contains($PassingMbUnit1) | Should Be $true
        $def.Assemblies.Contains($PassingMbUnit2) | Should Be $true
        $def.Assemblies.Contains($FailingMbUnit) | Should Be $true
    }
}

Describe "Define-MsTests" {
    
    It "It should use group name as report name if second is not sepcified" {
        $def = Define-MsTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'my_group'
    }

    It "It should define tests with group name and report name" {
        $def = Define-MsTests -GroupName 'my group' -ReportName 'test-reports' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.GroupName | Should Be 'my group'
        $def.ReportName | Should Be 'test-reports'
    }

    It "It should define tests with default runner version" {
        $def = Define-MsTests -GroupName 'my group' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.Runner | Should Match '12\.0'
    }

    It "It should define tests with sepcified runner version" {
        $def = Define-MsTests -GroupName 'my group' -VisualStudioVersion '11.0' -TestAssembly "some.dll"
        $def | Should Not Be $null
        $def.Runner | Should Match '11\.0'
    }
        
    It "It should allow to specify one assembly" {
        $def = Define-MsTests -GroupName 'group' -TestAssembly $PassingMsTest1
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 1
        $def.Assemblies[0] | Should Be $PassingMsTest1
    }

    It "It should allow to specify multiple assemblies" {
        $def = Define-MsTests -GroupName 'group' -TestAssembly $PassingMsTest1, $PassingMsTest2
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 2
        $def.Assemblies[0] | Should Be $PassingMsTest1
        $def.Assemblies[1] | Should Be $PassingMsTest2
    }

    It "It should resolve assembly names with wildcards" {
        $def = Define-MsTests -GroupName 'group' -TestAssembly "$PSScriptRoot\TestSolution\*\bin\Release\*.MsTest.Tests*.dll"
        $def | Should Not Be $null
        $def.Assemblies.GetType() | Should Be 'string[]'
        $def.Assemblies.Length | Should Be 3
        $def.Assemblies.Contains($PassingMsTest1) | Should Be $true
        $def.Assemblies.Contains($PassingMsTest2) | Should Be $true
        $def.Assemblies.Contains($FailingMsTest) | Should Be $true
    }
}

Describe "Run-Tests" {
    
    It "It should allow to successfully run NUnit tests with one assembly and generate reports" {
        Define-NUnitTests -GroupName 'rt1' -TestAssembly $PassingNUnit1 | Run-Tests
        $? | Should Be $true
        Test-Path 'reports\rt1.xml' | Should Be $true
    }

    It "It should throw if NUnit fails any test" {
        try
        {
            Define-NUnitTests -GroupName 'rt2' -TestAssembly $FailingNUnit | Run-Tests
            throw 'Fail'
        }
        catch [Exception]
        {
            $_.Exception.Message | Should Be 'A program execution was not successful (Exit code: 1).'
            Test-Path 'reports\rt2.xml' | Should Be $true
        }
    }

    It "It should allow to successfully run MbUnit tests with one assembly and generate reports" {
        Define-MbUnitTests -GroupName 'rt3' -TestAssembly $PassingMbUnit1 | Run-Tests
        $? | Should Be $true
        Test-Path 'reports\rt3.xml' | Should Be $true
    }

    It "It should throw if MbUnit fails any test" {
        try
        {
            Define-MbUnitTests -GroupName 'rt4' -TestAssembly $FailingMbUnit | Run-Tests
            throw 'Fail'
        }
        catch [Exception]
        {
            $_.Exception.Message | Should Be 'A program execution was not successful (Exit code: 1).'
            Test-Path 'reports\rt4.xml' | Should Be $true
        }
    }

    It "It should allow to successfully run MsTest tests with one assembly and generate reports" {
        Define-MsTests -GroupName 'rt5' -TestAssembly $PassingMsTest1 | Run-Tests
        $? | Should Be $true
    }

    It "It should throw if MsTest fails any test" {
        try
        {
            Define-MsTests -GroupName 'rt6' -TestAssembly $FailingMsTest | Run-Tests
            throw 'Fail'
        }
        catch [Exception]
        {
            $_.Exception.Message | Should Be 'A program execution was not successful (Exit code: 1).'
        }
    }
}
{'fraction_non_alphanumeric': 0.11804434003817355, 'fraction_numerical': 0.01115842020261342, 'mean_word_length': 2.8409774436090225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5320835', 'n_tokens_mistral': 6734, 'n_tokens_neox': 6397, 'n_words': 1638}