Skip to content

Commit c715753

Browse files
CopilotJustinGrote
andcommitted
Update Pester tests for new C# project structure; fix code review issues
Co-authored-by: JustinGrote <15258962+JustinGrote@users.noreply.github.com> Agent-Logs-Url: https://github.com/JustinGrote/ModuleFast/sessions/eac9df56-fca6-48d7-8e04-c899cdbbb277
1 parent 00727bc commit c715753

File tree

7 files changed

+67
-111
lines changed

7 files changed

+67
-111
lines changed

ModuleFast.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
FunctionsToExport = 'Install-ModuleFast', 'Get-ModuleFastPlan', 'Clear-ModuleFastCache'
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75-
CmdletsToExport = 'Get-ModuleFastPlan', 'Clear-ModuleFastCache'
75+
CmdletsToExport = @()
7676

7777
# Variables to export from this module
7878
#VariablesToExport = '*'

ModuleFast.psm1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ if (Test-Path $binaryModulePath) {
3030
if (-not $accelerators::Get.ContainsKey('ModuleFastInfo')) {
3131
$accelerators::Add('ModuleFastInfo', [ModuleFast.ModuleFastInfo])
3232
}
33+
34+
# Clean up type accelerators when this module is removed
35+
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
36+
$accelerators = [psobject].Assembly.GetType('System.Management.Automation.TypeAccelerators')
37+
$accelerators::Remove('ModuleFastSpec')
38+
$accelerators::Remove('ModuleFastInfo')
39+
}
3340
}
3441

3542
#Because we are changing state, we want to be safe

ModuleFast.tests.ps1

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,78 @@ using namespace Microsoft.PowerShell.Commands
33
using namespace System.Collections.Generic
44
using namespace System.Diagnostics.CodeAnalysis
55
using namespace NuGet.Versioning
6+
using namespace ModuleFast
67

7-
. $PSScriptRoot/ModuleFast.ps1 -ImportNuGetVersioning
8-
Import-Module $PSScriptRoot/ModuleFast.psm1 -Force
8+
Import-Module $PSScriptRoot/ModuleFast.psd1 -Force
99

1010
BeforeAll {
1111
if ($env:MFURI) {
1212
$PSDefaultParameterValues['*-ModuleFast*:Source'] = $env:MFURI
1313
}
1414
}
1515

16-
InModuleScope 'ModuleFast' {
17-
Describe 'ModuleFastSpec' {
18-
Context 'Constructors' {
19-
It 'Getters' {
20-
$spec = [ModuleFastSpec]'Test'
21-
'Name', 'Guid', 'Min', 'Max', 'Required' | ForEach-Object {
22-
$spec.PSObject.Properties.name | Should -Contain $PSItem
23-
}
16+
# ModuleFastSpec is a public C# class — no InModuleScope needed
17+
Describe 'ModuleFastSpec' {
18+
Context 'Constructors' {
19+
It 'Getters' {
20+
$spec = [ModuleFastSpec]'Test'
21+
'Name', 'Guid', 'Min', 'Max', 'Required' | ForEach-Object {
22+
$spec.PSObject.Properties.name | Should -Contain $PSItem
2423
}
24+
}
2525

26-
It 'Name' {
27-
$spec = [ModuleFastSpec]'Test'
28-
$spec.Name | Should -Be 'Test'
29-
$spec.Guid | Should -Be ([Guid]::Empty)
30-
$spec.Min | Should -BeNull
31-
$spec.Max | Should -BeNull
32-
$spec.Required | Should -BeNull
33-
}
26+
It 'Name' {
27+
$spec = [ModuleFastSpec]'Test'
28+
$spec.Name | Should -Be 'Test'
29+
$spec.Guid | Should -Be ([Guid]::Empty)
30+
$spec.Min | Should -BeNull
31+
$spec.Max | Should -BeNull
32+
$spec.Required | Should -BeNull
33+
}
3434

35-
It 'Has non-settable properties' {
36-
$spec = [ModuleFastSpec]'Test'
37-
{ $spec.Min = '1' } | Should -Throw
38-
{ $spec.Max = '1' } | Should -Throw
39-
{ $spec.Required = '1' } | Should -Throw
40-
{ $spec.Name = 'fake' } | Should -Throw
41-
{ $spec.Guid = New-Guid } | Should -Throw
42-
}
35+
It 'Has non-settable properties' {
36+
$spec = [ModuleFastSpec]'Test'
37+
{ $spec.Min = '1' } | Should -Throw
38+
{ $spec.Max = '1' } | Should -Throw
39+
{ $spec.Required = '1' } | Should -Throw
40+
{ $spec.Name = 'fake' } | Should -Throw
41+
{ $spec.Guid = New-Guid } | Should -Throw
42+
}
4343

44-
It 'ModuleSpecification' {
45-
$in = [ModuleSpecification]@{
46-
ModuleName = 'Test'
47-
ModuleVersion = '2.1.5'
48-
}
49-
$spec = [ModuleFastSpec]$in
50-
$spec.Name | Should -Be 'Test'
51-
$spec.Guid | Should -Be ([Guid]::Empty)
52-
$spec.Min | Should -Be '2.1.5'
53-
$spec.Max | Should -BeNull
54-
$spec.Required | Should -BeNull
44+
It 'ModuleSpecification' {
45+
$in = [ModuleSpecification]@{
46+
ModuleName = 'Test'
47+
ModuleVersion = '2.1.5'
5548
}
49+
$spec = [ModuleFastSpec]$in
50+
$spec.Name | Should -Be 'Test'
51+
$spec.Guid | Should -Be ([Guid]::Empty)
52+
$spec.Min | Should -Be '2.1.5'
53+
$spec.Max | Should -BeNull
54+
$spec.Required | Should -BeNull
5655
}
56+
}
5757

58-
Context 'ModuleSpecification Conversion' {
59-
It 'Name' {
60-
$spec = [ModuleSpecification][ModuleFastSpec]'Test'
61-
$spec.Name | Should -Be 'Test'
62-
$spec.Version | Should -Be '0.0'
63-
$spec.RequiredVersion | Should -BeNull
64-
$spec.MaximumVersion | Should -BeNull
65-
}
66-
It 'RequiredVersion' {
67-
$spec = [ModuleSpecification][ModuleFastSpec]::new('Test', '1.2.3')
68-
$spec.Name | Should -Be 'Test'
69-
$spec.RequiredVersion | Should -Be '1.2.3.0'
70-
$spec.Version | Should -BeNull
71-
$spec.MaximumVersion | Should -BeNull
72-
}
58+
Context 'ModuleSpecification Conversion' {
59+
It 'Name' {
60+
$spec = [ModuleSpecification][ModuleFastSpec]'Test'
61+
$spec.Name | Should -Be 'Test'
62+
$spec.Version | Should -Be '0.0'
63+
$spec.RequiredVersion | Should -BeNull
64+
$spec.MaximumVersion | Should -BeNull
65+
}
66+
It 'RequiredVersion' {
67+
$spec = [ModuleSpecification][ModuleFastSpec]::new('Test', '1.2.3')
68+
$spec.Name | Should -Be 'Test'
69+
$spec.RequiredVersion | Should -Be '1.2.3.0'
70+
$spec.Version | Should -BeNull
71+
$spec.MaximumVersion | Should -BeNull
7372
}
7473
}
74+
}
7575

76+
# Import-ModuleManifest is a private PS function — InModuleScope required
77+
InModuleScope 'ModuleFast' {
7678
Describe 'Import-ModuleManifest' {
7779
It 'Reads Dynamic Manifest' {
7880
$Mocks = "$PSScriptRoot/Test/Mocks"

src/ModuleFast/Commands/ClearModuleFastCacheCommand.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/ModuleFast/Commands/GetModuleFastPlanCommand.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/ModuleFast/ModuleFastClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace ModuleFast;
55

66
public static class ModuleFastClient
77
{
8-
public static HttpClient Create(string? credential = null, int timeoutSeconds = 30)
8+
public static HttpClient Create(int timeoutSeconds = 30)
99
{
1010
var handler = new SocketsHttpHandler
1111
{
1212
MaxConnectionsPerServer = 10,
1313
InitialHttp2StreamWindowSize = 16777216,
14-
AutomaticDecompression = DecompressionMethods.All
14+
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.Brotli
1515
};
1616
var client = new HttpClient(handler)
1717
{

src/ModuleFast/ModuleFastSpec.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public bool SatisfiedBy(NuGetVersion version, bool strictSemVer)
227227
public bool Overlap(VersionRange other)
228228
{
229229
var subset = VersionRange.CommonSubSet(new List<VersionRange> { _versionRange, other });
230-
return subset.ToString() != "(0.0.0, 0.0.0)";
230+
return !subset.Equals(VersionRange.None);
231231
}
232232

233233
// --- Interface implementations ---
@@ -263,8 +263,8 @@ public int CompareTo(object? other)
263263
}
264264

265265
if (_versionRange.Satisfies(version!)) return 0;
266-
if (_versionRange.MinVersion != null && _versionRange.MinVersion > version) return 1;
267-
if (_versionRange.MaxVersion != null && _versionRange.MaxVersion < version) return -1;
266+
if (_versionRange.MinVersion != null && _versionRange.MinVersion > version!) return 1;
267+
if (_versionRange.MaxVersion != null && _versionRange.MaxVersion < version!) return -1;
268268
throw new InvalidOperationException("Could not compare. This is a bug.");
269269
}
270270

0 commit comments

Comments
 (0)