コード例 #1
0
        public void CheckAddIllegalInterceptor()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CheckAddIllegalInterceptor", (app, param) => "hello world", false);

            Assert.Throws <ArgumentNullException>(() =>
            {
                bindData.AddInterceptor(null);
            });
        }
コード例 #2
0
ファイル: BindDataTests.cs プロジェクト: blueberryWT/CatLib
        public void CheckIllegalResolving()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CanAddOnResolving", (app, param) => "hello world", false);

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                bindData.OnResolving(null);
            });
        }
コード例 #3
0
        public void CheckNeedsIsNotNull()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.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);
        }
コード例 #4
0
        public void CanAddOnResolving()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CanAddOnResolving", (app, param) => "hello world", false);

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

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

            Assert.AreEqual(null, data);
        }
コード例 #5
0
ファイル: BindDataTests.cs プロジェクト: blueberryWT/CatLib
        public void AddContextualRepeat()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "AddContextualRepeat", (app, param) => "hello world", false);

            bindData.AddContextual("service", "service given");
            ExceptionAssert.Throws <RuntimeException>(() =>
            {
                bindData.AddContextual("service", "service given");
            });
        }
コード例 #6
0
        public void CanGetContextual()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.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"));
        }
コード例 #7
0
        public void CanOnRelease()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.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");
        }
コード例 #8
0
        public void CheckIllegalAlias()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CheckIllegalAlias", (app, param) => "hello world", false);

            Assert.Throws <ArgumentNullException>(() =>
            {
                bindData.Alias(null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                bindData.Alias(string.Empty);
            });
        }
コード例 #9
0
        public void CanGiven()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CanGiven", (app, param) => "hello world", false);
            var givenData = new CatLib.Container.GivenData(bindData);

            givenData.Needs("needs1");
            givenData.Given("hello");
            Assert.AreEqual("hello", bindData.GetContextual("needs1"));

            givenData = new CatLib.Container.GivenData(bindData);
            givenData.Needs("needs2");
            givenData.Given <GivenDataTest>();
            Assert.AreEqual(typeof(GivenDataTest).ToString(), bindData.GetContextual("needs2"));
        }
コード例 #10
0
        public void CheckGivenIllegalValue()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CanGiven", (app, param) => "hello world", false);
            var givenData = new CatLib.Container.GivenData(bindData);

            givenData.Needs("needs");

            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                givenData.Given(null);
            });
            ExceptionAssert.Throws <ArgumentNullException>(() =>
            {
                givenData.Given(string.Empty);
            });
        }
コード例 #11
0
        public void CanAddInterceptor()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CanAddInterceptor", (app, param) => "hello world", false);

            var newInterceptorClass = new AddInterceptorClass();

            bindData.AddInterceptor <AddInterceptorClass>();
            bindData.AddInterceptor(newInterceptorClass);

            var interceptor = bindData.GetInterceptors();

            Assert.AreNotEqual(null, interceptor);
            Assert.AreEqual(2, interceptor.Length);
            Assert.AreSame(typeof(AddInterceptorClass), interceptor[0].GetType());
            Assert.AreSame(interceptor[1], newInterceptorClass);
            Assert.AreNotSame(interceptor[0], interceptor[1]);
        }
コード例 #12
0
        public void CheckIllegalRelease()
        {
            var container = new CatLib.Container.Container();
            var bindData  = new CatLib.Container.BindData(container, "CheckIllegalRelease", (app, param) => "hello world", false);

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

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