コード例 #1
0
        public void Should_register_supplies_with_scope()
        {
            var dependencyFactory = SetupMock <IDataDependencyFactory>();

            IDataDependency actionDependency = null;
            Action <IRenderContext, IDataContext, IDataDependency> action =
                (rc, dc, dd) => actionDependency = dd;

            var registeredDependency = dependencyFactory.Create(typeof(int), "test-scope");

            _dataSupplier.Add(registeredDependency, action);

            Assert.IsTrue(_dataSupplier.IsSupplierOf(registeredDependency));
            Assert.IsTrue(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(int), "test-scope")));
            Assert.IsTrue(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(int))));

            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(long))));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(int), "other-scope")));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(long), "test-scope")));
            Assert.IsFalse(_dataSupplier.IsSupplierOf(dependencyFactory.Create(typeof(long), "other-scope")));

            var dataSupply = _dataSupplier.GetSupply(dependencyFactory.Create(typeof(int)));

            Assert.IsNotNull(dataSupply);

            dataSupply.Supply(null, null);

            Assert.AreEqual(registeredDependency, actionDependency);
        }
コード例 #2
0
        private void Configure(AttributeSet attributes, IDataSupplier dataSupplier)
        {
            if (dataSupplier == null)
            {
                return;
            }

            if (attributes.SuppliesDatas != null)
            {
                foreach (var data in attributes.SuppliesDatas)
                {
                    var dependency = _dataDependencyFactory.Create(
                        data.DataType,
                        data.Scope);

                    // TODO: Is there a way to specify the action via attributes?
                    dataSupplier.Add(dependency, (rc, dc, dep) => { });
                }
            }
        }
コード例 #3
0
        public void Add <T>(string scopeName = null)
        {
            var suppliedDependency = Dependencies.DataDependencyFactory.Create <T>(scopeName);

            DataSupplier.Add(suppliedDependency, Supply);
        }