3 using Castle
.Igloo
.Scopes
;
4 using Castle
.Igloo
.Test
.ScopeTest
.Components
;
8 namespace Castle
.Igloo
.Test
.ScopeTest
12 /// Summary description for LifestyleManagerTestCase.
15 public class ProxyScopeTest
17 private IWindsorContainer _container
= null;
20 public void CreateContainer()
22 _container
= new WindsorContainer();
23 _container
.AddFacility("Igloo.Facility", new IglooFacility());
27 public void DisposeContainer()
33 public void TestScopedObjectOnProxyScope()
35 _container
.AddComponent("Simple.Component", typeof(IComponent
), typeof(SimpleComponent
));
37 IComponent service1
= _container
.Resolve
<IComponent
>("Simple.Component");
39 Assert
.IsNotNull(service1
);
40 Assert
.IsTrue(typeof(IScopedObject
).IsAssignableFrom(service1
.GetType()));
44 public void TestProxyScope()
46 _container
.AddComponent("Simple.Component", typeof(IComponent
), typeof(SimpleComponent
));
48 IComponent service1
= _container
.Resolve
<IComponent
>("Simple.Component");
50 int result
= service1
.ID
;
51 Assert
.AreEqual(99, result
);
53 IComponent service2
= _container
.Resolve
<IComponent
>("Simple.Component");
55 Assert
.IsTrue(service1
.Equals(service2
));
58 Assert
.AreEqual(99, result
);
62 public void TestGraphOfScopeComponent()
64 _container
.AddComponent("Thread.Scope.Proxy.Component", typeof(IComponent
), typeof(SimpleComponent
));
65 _container
.AddComponent("Singleton.Component", typeof(IComponent0
), typeof(SimpleComponent0
));
66 _container
.AddComponent("Thread.Scope.Proxy.Component1", typeof(IComponent1
), typeof(SimpleComponent1
));
67 _container
.AddComponent("Thread.Scope.Proxy.Component2", typeof(IComponent2
), typeof(SimpleComponent2
));
69 IComponent0 service00
= _container
.Resolve
<IComponent0
>();
70 IComponent0 service01
= _container
.Resolve
<IComponent0
>();
72 Assert
.IsNotNull(service00
);
73 Assert
.IsNotNull(service01
);
75 Assert
.IsTrue(service00
.Equals(service01
));
76 Assert
.IsTrue(service01
.ID
== service00
.ID
);
78 Assert
.IsTrue(typeof(IScopedObject
).IsAssignableFrom(service00
.SimpleComponent1
.GetType()));
79 Assert
.IsTrue(typeof(IScopedObject
).IsAssignableFrom(service01
.SimpleComponent1
.GetType()));
80 Assert
.IsTrue(service00
.SimpleComponent1
.Equals(service01
.SimpleComponent1
));
82 IComponent1 service1
= service00
.SimpleComponent1
;
84 Type
[] interfaces
= service1
.SimpleComponent2
.GetType().GetInterfaces();
86 Assert
.IsTrue(typeof(IScopedObject
).IsAssignableFrom( service1
.SimpleComponent2
.GetType()));
87 Assert
.AreEqual(101, service1
.ID
);
89 IComponent2 service2
= service1
.SimpleComponent2
;
91 interfaces
= service2
.SimpleComponent
.GetType().GetInterfaces();
93 Assert
.IsTrue(typeof(IScopedObject
).IsAssignableFrom(service2
.SimpleComponent
.GetType()));
94 Assert
.AreEqual("SimpleComponent2", service2
.Name
);
96 IComponent service
= service2
.SimpleComponent
;
98 Assert
.AreEqual(99, service
.ID
);