-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathJudgeDreddTests.cs
64 lines (55 loc) · 1.93 KB
/
JudgeDreddTests.cs
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
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
namespace MegaCityOne.Tests
{
/// <summary>
/// Test if JudgeDredd features works properly.
/// </summary>
[TestClass]
public class JudgeDreddTests
{
/// <summary>
/// Test to see if a simple law works well.
/// </summary>
[TestMethod]
public void SimpleCompiledRuleSuccess()
{
JudgeDredd judge = new JudgeDredd();
judge.Laws.Add("CanSeeBankAccount",
(principal, arguments) => principal.IsInRole("BankingConsultant"));
judge.Principal = new GenericPrincipal(
WindowsIdentity.GetCurrent(),
new string[] { "BankingConsultant" });
judge.Enforce("CanSeeBankAccount");
}
/// <summary>
/// Insure that an Advise failure throws an LawgiverException.
/// </summary>
[TestMethod]
[ExpectedException(typeof(LawgiverException))]
public void SimpleCompiledRuleFail()
{
JudgeDredd judge = new JudgeDredd();
judge.Laws.Add("CanSeeBankAccount",
(principal, arguments) => principal.IsInRole("BankingConsultant"));
judge.Principal = new GenericPrincipal(
WindowsIdentity.GetCurrent(), new string[0]);
judge.Enforce("CanSeeBankAccount");
}
/// <summary>
/// Loads a set of law from a foreign library.
/// </summary>
[TestMethod]
public void LoadLawsFromAnotherAssembly()
{
JudgeDredd judge = new JudgeDredd();
judge.Load("../../../MegaCityOne.Tests.JusticeDepartment/bin/debug/MegaCityOne.Tests.JusticeDepartment.dll");
Assert.AreEqual(3, judge.Laws.Count);
}
}
}