Skip to content

Commit

Permalink
Minor changes and improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lipkau committed Sep 12, 2018
1 parent 50f317c commit 3e37cfc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
22 changes: 11 additions & 11 deletions AtlassianPS.Configuration/AtlassianPS.Configuration.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public MessageStyle()
FunctionName = true;
}

public MessageStyle(UInt32 _Indent, Boolean _TimeStamp, Boolean _BreadCrumbs, Boolean _FunctionName)
public MessageStyle(UInt32 Indent, Boolean TimeStamp, Boolean BreadCrumbs, Boolean FunctionName)
{
Indent = _Indent;
TimeStamp = _TimeStamp;
BreadCrumbs = _BreadCrumbs;
FunctionName = _FunctionName;
this.Indent = Indent;
this.TimeStamp = TimeStamp;
this.BreadCrumbs = BreadCrumbs;
this.FunctionName = FunctionName;
}

public UInt32 Indent { get; set; }
Expand All @@ -39,15 +39,15 @@ public MessageStyle(UInt32 _Indent, Boolean _TimeStamp, Boolean _BreadCrumbs, Bo
[Serializable]
public class ServerData
{
public ServerData(UInt32 _Id, String _Name, String _Uri, ServerType _Type)
public ServerData(UInt32 Id, String Name, String Url, ServerType Type)
{
Uri tempUri;
Uri.TryCreate(_Uri, UriKind.RelativeOrAbsolute, out tempUri);
Uri.TryCreate(Url, UriKind.RelativeOrAbsolute, out tempUri);

Id = _Id;
Name = _Name;
Uri = tempUri;
Type = _Type;
this.Id = Id;
this.Name = Name;
this.Uri = tempUri;
this.Type = Type;
}

public ServerData(IDictionary Table)
Expand Down
18 changes: 11 additions & 7 deletions Tests/AtlassianPS.Configuration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,34 @@ Describe "General project validation" -Tag Unit {
{ Test-ModuleManifest -Path $env:BHManifestToTest -ErrorAction Stop } | Should -Not -Throw
}

It "module '$env:BHProjectName' can import cleanly" {
{ Import-Module $env:BHManifestToTest } | Should Not Throw
It "imports '$env:BHProjectName' cleanly" {
Import-Module $env:BHManifestToTest

$module = Get-Module $env:BHProjectName

$module | Should BeOfType [PSModuleInfo]
}

It "module '$env:BHProjectName' exports functions" {
It "has public functions" {
Import-Module $env:BHManifestToTest

(Get-Command -Module $env:BHProjectName | Measure-Object).Count | Should -BeGreaterThan 0
}

It "module uses the correct root module" {
It "uses the correct root module" {
Configuration\Get-Metadata -Path $env:BHManifestToTest -PropertyName RootModule | Should -Be 'AtlassianPS.Configuration.psm1'
}

It "module uses the correct guid" {
It "uses the correct guid" {
Configuration\Get-Metadata -Path $env:BHManifestToTest -PropertyName Guid | Should -Be 'f946e1f7-ed4f-43da-aa24-6d57a25117cb'
}

It "module uses a valid version" {
It "uses a valid version" {
[Version](Configuration\Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion) | Should -Not -BeNullOrEmpty
[Version](Configuration\Get-Metadata -Path $env:BHManifestToTest -PropertyName ModuleVersion) | Should -BeOfType [Version]
}

It "module requires Configuration" {
It "requires Configuration" {
# this workaround will be obsolete with
# https://github.com/PoshCode/Configuration/pull/20
$pureExpression = Configuration\Get-Metadata -Path $env:BHManifestToTest -PropertyName RequiredModules -Passthru
Expand Down
22 changes: 21 additions & 1 deletion Tests/Classes/AtlassianPS.ServerData.Unit.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#requires -modules BuildHelpers
#requires -modules @{ ModuleName = "Pester"; ModuleVersion = "4.3.1" }

Describe "[AtlassianPS.ServerType] Tests" -Tag Unit {
Describe "[AtlassianPS.ServerData] Tests" -Tag Unit {

BeforeAll {
Remove-Item -Path Env:\BH*
Expand Down Expand Up @@ -70,4 +70,24 @@ Describe "[AtlassianPS.ServerType] Tests" -Tag Unit {

$object.ToString() | Should -Be "Name (https://google.com/)"
}

Context "Types of properties" {
$object = [AtlassianPS.ServerData]@{ Id = 1; Name = "Name"; Uri = "https://google.com"; Type = "Jira" }

It "has a Id of type UInt32" {
$object.Id | Should -BeOfType [UInt32]
}

It "has a Name of type String" {
$object.Name | Should -BeOfType [String]
}

It "has a Uri of type Uri" {
$object.Uri | Should -BeOfType [Uri]
}

It "has a Type of type AtlassianPS.ServerType" {
$object.Type | Should -BeOfType [AtlassianPS.ServerType]
}
}
}
8 changes: 6 additions & 2 deletions Tests/Examples.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ Describe "Validation of example codes in the documentation" -Tag Documentation,
Import-Module $env:BHManifestToTest

# backup current configuration
& (Get-Module $env:BHProjectName) {$script:previousConfig = $script:configuration}
& (Get-Module $env:BHProjectName) {
$script:previousConfig = $script:Configuration
$script:Configuration = @{}
$script:Configuration.Add("ServerList",[System.Collections.Generic.List[AtlassianPS.ServerData]]::new())
}
}
AfterAll {
#restore previous configuration
& (Get-Module $env:BHProjectName) {
$script:configuration = $script:previousConfig
$script:Configuration = $script:previousConfig
Save-Configuration
}

Expand Down

0 comments on commit 3e37cfc

Please sign in to comment.