Пример #1
0
        public void CheckIllegalResolving()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "CanAddOnResolving", (app, param) => "hello world", false);

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                bindData.OnResolving(null);
            });
        }
Пример #2
0
        public void CheckNeedsIsNotNull()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "NeedsIsNotNull", (app, param) => "hello world", false);

            var needs         = bindData.Needs("TestService");
            var needsWithType = bindData.Needs <BindDataTest>();

            Assert.AreNotEqual(null, needs);
            Assert.AreNotEqual(null, needsWithType);
        }
Пример #3
0
        public void AddContextualRepeat()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "AddContextualRepeat", (app, param) => "hello world", false);

            bindData.AddContextual("service", "service given");
            ExceptionAssert.Throws <RuntimeException>(() =>
            {
                bindData.AddContextual("service", "service given");
            });
        }
Пример #4
0
        public void CanAddOnResolving()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "CanAddOnResolving", (app, param) => "hello world", false);

            bindData.OnResolving((bind, obj) => null);

            var data = bindData.ExecResolvingDecorator(new CatLib.Stl.Container());

            Assert.AreEqual(null, data);
        }
Пример #5
0
        public void CanGetContextual()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "NeedsIsNotNull", (app, param) => "hello world", false);

            bindData.Needs("need1").Given("abc");
            bindData.Needs("need2").Given <BindDataTest>();

            Assert.AreEqual("abc", bindData.GetContextual("need1"));
            Assert.AreEqual(typeof(BindDataTest).ToString(), bindData.GetContextual("need2"));
            Assert.AreEqual("empty", bindData.GetContextual("empty"));
        }
Пример #6
0
        public void CanOnRelease()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "CanAddOnRelease", (app, param) => "hello world", true);

            bindData.OnRelease((bind, obj) =>
            {
                Assert.AreEqual("Test", obj);
                Assert.AreSame(bindData, bind);
            });

            container.Instance("CanAddOnRelease", "Test");
            container.Release("CanAddOnRelease");
        }
Пример #7
0
        public void CheckIllegalAlias()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "CheckIllegalAlias", (app, param) => "hello world", false);

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                bindData.Alias(null);
            });
            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                bindData.Alias(string.Empty);
            });
        }
Пример #8
0
        public void CheckIllegalRelease()
        {
            var container = new CatLib.Stl.Container();
            var bindData  = new CatLib.Stl.BindData(container, "CheckIllegalRelease", (app, param) => "hello world", false);

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                bindData.OnRelease(null);
            });

            ExceptionAssert.Throws <RuntimeException>(() =>
            {
                bindData.OnRelease((bind, obj) =>
                {
                    Assert.Fail();
                });
                container.Instance("CheckIllegalRelease", "Test");
                container.Release("CheckIllegalRelease");
            });
        }