main
 1using System.Security.Principal;
 2using System.Threading;
 3using Castle.Core.Interceptor;
 4using developwithpassion.bdd.contexts;
 5using Gorilla.Commons.Testing;
 6using gorilla.commons.utility;
 7
 8namespace MoMoney.boot.container.registration.proxy_configuration
 9{
10    public class SecuringProxySpecs {}
11
12    public class when_attempting_to_perform_an_action_that_requires_authentication :
13        concerns_for<SecuringProxy>
14    {
15        context c = () =>
16        {
17            filter = the_dependency<Specification<IPrincipal>>();
18        };
19
20        static protected Specification<IPrincipal> filter;
21    }
22
23    public class when_logged_in_as_a_user_that_belongs_to_the_proper_role :
24        when_attempting_to_perform_an_action_that_requires_authentication
25    {
26        context c = () =>
27        {
28            invocation = an<IInvocation>();
29            when_the(filter)
30                .is_told_to(x => x.is_satisfied_by(Thread.CurrentPrincipal))
31                .it_will_return(true);
32        };
33
34        because b = () => sut.Intercept(invocation);
35
36        it should_proceed_with_request = () => invocation.was_told_to(x => x.Proceed());
37
38        static IInvocation invocation;
39    }
40
41    public class when_not_logged_in_as_a_user_that_belongs_to_the_proper_role :
42        when_attempting_to_perform_an_action_that_requires_authentication
43    {
44        context c = () =>
45        {
46            invocation = an<IInvocation>();
47            when_the(filter)
48                .is_told_to(x => x.is_satisfied_by(Thread.CurrentPrincipal))
49                .it_will_return(false);
50        };
51
52        because b = () => sut.Intercept(invocation);
53
54        it should_not_proceed_with_request = () => invocation.was_not_told_to(x => x.Proceed());
55
56        static IInvocation invocation;
57    }
58}