예제 #1
0
        public void add_type()
        {
            var dependency = new ListDependency(typeof(ISomethingDoer[]));
            dependency.AddType(typeof (ASomethingDoer)).Type.ShouldEqual(typeof (ASomethingDoer));

            dependency.Items.Count.ShouldEqual(1);
        }
예제 #2
0
        void IDependencyVisitor.List(ListDependency dependency)
        {
            var elements = dependency.Items.Select(instanceFor).ToArray();
            var instance = new EnumerableInstance(elements);

            Dependencies.Add(dependency.DependencyType, instance);
        }
예제 #3
0
        void IDependencyVisitor.List(ListDependency dependency)
        {
            var elementType = dependency.ElementType;
            var elements = dependency.Items.Select(instanceFor).ToArray();

            ChildArray(dependency.DependencyType).Contains(elements);
        }
예제 #4
0
        public void accepting_the_visitor()
        {
            var visitor = MockRepository.GenerateMock<IDependencyVisitor>();
            var dependency = new ListDependency(typeof (IList<ISomethingDoer>));

            dependency.AcceptVisitor(visitor);

            visitor.AssertWasCalled(x => x.List(dependency));
        }
예제 #5
0
        void IDependencyVisitor.List(ListDependency dependency)
        {
            _components.AddRange(dependency
                                    .Items
                                    .Select(def => new WindsorDependencyVisitor(dependency.ElementType, def, true))
                                    .SelectMany(v => v.Registrations()));

            _registration.DependsOn(Dependency.OnComponentCollection(dependency.DependencyType,
                                                                     dependency.Items.Select(def => def.Name).ToArray()));
        }
예제 #6
0
        public void add_value()
        {
            var doer = new ASomethingDoer();

            var dependency = new ListDependency(typeof (ISomethingDoer[]));
            dependency.AddValue(doer);

            dependency.Items.Count.ShouldEqual(1);

            dependency.Items[0].Value.ShouldBeTheSameAs(doer);
        }
예제 #7
0
        private ListDependency findListDependency <T>(Type openType)
        {
            var dependencyType = openType.MakeGenericType(typeof(T));
            var dependency     = _dependencies.OfType <ListDependency>()
                                 .FirstOrDefault(x => x.DependencyType == typeof(IEnumerable <T>));

            if (dependency == null)
            {
                dependency = new ListDependency(dependencyType);
                _dependencies.Add(dependency);
            }

            return(dependency);
        }
예제 #8
0
        public void Should_satisfy_dependency()
        {
            var def = new ObjectDef(typeof(NeedListOfDoers));

            var doer1 = new ASomethingDoer();

            var doers = new ListDependency(typeof (IEnumerable<ISomethingDoer>));
            doers.AddValue(doer1);
            doers.AddType(typeof (BSomethingDoer));

            def.Dependency(doers);

            def.Dependencies.ShouldHaveCount(1);
        }