Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Nov 8, 2022
1 parent ca8c47f commit c385ddf
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions tests/Unit/SharePointDsc/SharePointDsc.Util.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,117 @@ try
}
}

Context -Name "Validate Get-SPDscServerPatchStatus" -Fixture {
BeforeAll {
try
{
[Microsoft.SharePoint.Administration.SPProductVersions]
}
catch
{
Add-Type -TypeDefinition @"
namespace Microsoft.SharePoint.Administration {
public class serverProductInfo {
public string GetUpgradeStatus(System.Object farm, System.Object server)
{
return "NoActionRequired";
}
public string InstallStatus
{
get
{
return "NoActionRequired";
}
}
}
public class ProductVersions {
public object GetServerProductInfo(System.Object server)
{
return new serverProductInfo();
}
}
public class SPProductVersions {
public static object GetProductVersions(System.Object obj)
{
return new ProductVersions();
}
}
}
"@ -ErrorAction SilentlyContinue
}

Mock -CommandName Get-SPFarm -MockWith { return "" }
Mock -CommandName Get-SPServer -MockWith {
return @{
Id = (New-Guid)
}
}
}

It "should return the patch status of the current server" {
Get-SPDscServerPatchStatus | Should -Be "NoActionRequired"
}
}

Context -Name "Validate Get-SPDscAllServersPatchStatus" -Fixture {
BeforeAll {
try
{
[Microsoft.SharePoint.Administration.SPProductVersions]
}
catch
{
Add-Type -TypeDefinition @"
namespace Microsoft.SharePoint.Administration {
public class serverProductInfo {
public string GetUpgradeStatus(System.Object farm, System.Object server)
{
return "NoActionRequired";
}
public string InstallStatus
{
get
{
return "NoActionRequired";
}
}
}
public class ProductVersions {
public object GetServerProductInfo(System.Object server)
{
return new serverProductInfo();
}
}
public class SPProductVersions {
public static object GetProductVersions(System.Object obj)
{
return new ProductVersions();
}
}
}
"@ -ErrorAction SilentlyContinue
}

Mock -CommandName Get-SPFarm -MockWith { return "" }
Mock -CommandName Get-SPServer -MockWith {
return @{
Name = "WFE01"
Id = (New-Guid)
Role = "WebFrontEnd"
}
}
}

It "should return the patch status of the current server" {
[array]$result = Get-SPDscAllServersPatchStatus
$result.Count | Should -Be 1
$result[0].Name | Should -Be "WFE01"
}
}


Context -Name "Validate Export-SPDscDiagnosticData" -Fixture {
BeforeAll {
Mock -CommandName "New-Object" `
Expand Down

0 comments on commit c385ddf

Please sign in to comment.