main
1using Castle.DynamicProxy;
2using gorilla.utility;
3using Machine.Specifications;
4using solidware.financials.infrastructure;
5
6namespace specs.unit.infrastructure
7{
8 public class ProxyFactorySpecs
9 {
10 public class concern
11 {
12 Establish context = () =>
13 {
14 sut = new CastleProxyFactory();
15 };
16
17 static protected IProxyFactory sut;
18 }
19
20 public class when_creating_a_proxy_to_intercept_calls_to_a_class : concern
21 {
22 It should_intercept_calls_made_to_that_class = () =>
23 {
24 interceptor.Intercepted.ShouldBeTrue();
25 };
26
27 It should_make_the_call_on_the_original_class = () =>
28 {
29 command.result.ShouldEqual("mo");
30 };
31
32 Establish context = () =>
33 {
34 command = new TestCommand("blah");
35 };
36
37 Because of = () =>
38 {
39 interceptor = new TestInterceptor();
40 var proxy = sut.CreateProxyFor<Command<string>>(command, interceptor);
41 proxy.run("mo");
42 };
43
44 static TestCommand command;
45 static TestInterceptor interceptor;
46 }
47
48 public class TestCommand : Command<string>
49 {
50 readonly string needAConstructor;
51
52 public TestCommand(string needAConstructor)
53 {
54 this.needAConstructor = needAConstructor;
55 }
56
57 public virtual void run(string item)
58 {
59 result = item;
60 }
61
62 public string result { get; set; }
63 }
64
65 public class TestInterceptor : IInterceptor
66 {
67 public void Intercept(IInvocation invocation)
68 {
69 Intercepted = true;
70 invocation.Proceed();
71 }
72
73 public bool Intercepted { get; set; }
74 }
75 }
76}