forked from microsoft/PSRule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFromFileConventions.Rule.ps1
64 lines (55 loc) · 1.77 KB
/
FromFileConventions.Rule.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# Conventions for pesters tests
#
# Synopsis: A convention for unit testing
Export-PSRuleConvention 'Convention1' {
Write-Debug -Message 'Process convention1'
$PSRule.Data.count += 1;
} -Begin {
Write-Debug -Message 'Begin convention1'
$PSRule.Data.count += 1;
$PSRule.Data['Order'] += 'Convention1|'
} -End {
Write-Debug -Message 'End convention1'
}
# Synopsis: A convention for unit testing
Export-PSRuleConvention 'Convention2' {
Write-Debug -Message 'Process convention2'
$PSRule.Data.count *= 10;
} -Begin {
Write-Debug -Message 'Begin convention2'
$PSRule.Data.count *= 10;
} -End {
Write-Debug -Message 'End convention2'
}
# Synopsis: A convention for unit testing
Export-PSRuleConvention 'Convention3' -If { $Assert.HasFieldValue($TargetObject, 'IfTest', 1) } {
Write-Debug 'Convention3::Process'
$PSRule.Data.count += 1000;
}
# Synopsis: A convention for unit testing
Export-PSRuleConvention 'Convention.Expansion' -If { $TargetObject.Name -eq 'TestObject1' } -Begin {
$newObject = [PSCustomObject]@{
Name = 'TestObject2'
};
$PSRule.Import($newObject);
$PSRule.Import(@($newObject, $newObject));
}
# Synopsis: A convention for unit testing
Export-PSRuleConvention 'Convention.WithException' -Begin {
throw 'Some exception';
}
# Synopsis: A convention for unit testing
Export-PSRuleConvention 'Convention.Init' -Initialize {
$PSRule.AddService('Store', [PSCustomObject]@{
Name = 'TestObject1'
});
}
# Synopsis: A rule for testing conventions
Rule 'ConventionTest' {
$Assert.HasFieldValue($PSRule.Data, 'count', 1);
$store = $PSRule.GetService('Store');
$Assert.HasFieldValue($store, 'Name', 'TestObject1');
}