main
1using System.Security.Principal;
2using developwithpassion.bdd.contexts;
3using Gorilla.Commons.Testing;
4using gorilla.commons.utility;
5
6namespace MoMoney.Service.Infrastructure.Security
7{
8 public class IsInRoleSpecs
9 {
10 public class when_checking_if_a_principal_belongs_to_a_role :
11 concerns_for<Specification<IPrincipal>, IsInRole>
12 {
13 static protected readonly Role administrator_role = new Role("administrators");
14
15 public override Specification<IPrincipal> create_sut()
16 {
17 return new IsInRole(administrator_role);
18 }
19 }
20
21 public class when_not_in_one_of_the_roles : when_checking_if_a_principal_belongs_to_a_role
22 {
23 context c = () =>
24 {
25 principal = the_dependency<IPrincipal>();
26 when_the(principal)
27 .is_told_to(x => x.IsInRole(administrator_role))
28 .it_will_return(false);
29 };
30
31 because b = () =>
32 {
33 result = sut.is_satisfied_by(principal);
34 };
35
36 it should_return_false = () => result.should_be_false();
37
38 static bool result;
39 static IPrincipal principal;
40 }
41
42 public class when_in_one_of_the_roles : when_checking_if_a_principal_belongs_to_a_role
43 {
44 context c = () =>
45 {
46 principal = the_dependency<IPrincipal>();
47 when_the(principal)
48 .is_told_to(x => x.IsInRole(administrator_role))
49 .it_will_return(true);
50 };
51
52 because b = () =>
53 {
54 result = sut.is_satisfied_by(principal);
55 };
56
57 it should_return_true = () => result.should_be_true();
58
59 static bool result;
60 static IPrincipal principal;
61 }
62 }
63}