master
 1using Castle.Windsor;
 2using MbUnit.Framework;
 3using Notepad.Test.Extensions;
 4using Rhino.Mocks;
 5
 6namespace Notepad.Infrastructure.Container.Windsor {
 7    public class WindsorDependencyResolverSpecs {}
 8
 9
10    [TestFixture]
11    public class when_registering_a_singleton_component_with_the_windsor_container_ {
12        private WindsorDependencyRegistry sut;
13
14        [SetUp]
15        public void SetUp() {
16            sut = CreateSUT();
17        }
18
19        [Test]
20        public void should_return_the_same_instance_each_time_its_resolved() {
21            sut
22                .FindAnImplementationOf<IBird>()
23                .ShouldBeSameInstanceAs(sut.FindAnImplementationOf<IBird>());
24        }
25
26        [Test]
27        public void should_not_return_null() {
28            sut.FindAnImplementationOf<IBird>().ShouldNotBeNull();
29        }
30
31        private WindsorDependencyRegistry CreateSUT() {
32            return new WindsorDependencyRegistry();
33        }
34    }
35
36    [TestFixture]
37    public class when_creating_the_windsor_resolver_ {
38        private MockRepository mockery;
39        private IWindsorContainerFactory factory;
40
41        [SetUp]
42        public void SetUp() {
43            mockery = new MockRepository();
44            factory = mockery.DynamicMock<IWindsorContainerFactory>();
45        }
46
47        [Test]
48        public void should_leverage_the_factory_to_create_the_underlying_container() {
49            var container = new WindsorContainer();
50            using (mockery.Record()) {
51                Expect
52                    .Call(factory.Create())
53                    .Return(container)
54                    .Repeat
55                    .AtLeastOnce();
56            }
57
58            using (mockery.Playback()) {
59                CreateSUT();
60            }
61        }
62
63        private IDependencyRegistry CreateSUT() {
64            return new WindsorDependencyRegistry(factory);
65        }
66    }
67
68    public class BlueBird : IBird {
69        public void Initialize() {}
70    }
71
72    public interface IBird {}
73}