예제 #1
0
        public void CanEnumerateNames()
        {
            var p = new BSharpGenericClassProvider();

            p.Set(CreateCls <A>());
            p.Set(CreateCls <B>());
            Assert.AreEqual(2, p.GetClassNames().Count());
            Assert.AreEqual(1, p.GetClassNames("*.A").Count());
            Assert.AreEqual(1, p.GetClassNames("*.B").Count());
            Assert.AreEqual(2, p.GetClassNames("my.*").Count());
            Assert.AreEqual(1, p.GetClassNames("my.?.B").Count());
            Assert.AreEqual(1, p.GetClassNames("my.*.B").Count());
            Assert.AreEqual(1, p.GetClassNames("?.*.B").Count());
            Assert.AreEqual(0, p.GetClassNames("?.B").Count());
            Assert.AreEqual(1, p.GetClassNames("*.B").Count());
            Assert.AreEqual(2, p.GetClassNames("?.?.?").Count());
        }
예제 #2
0
        public void CanInstantiate()
        {
            var a = new BSharpRuntimeActivatorService();
            var p = new BSharpGenericClassProvider();

            p.Set(CreateCls <A>());
            p.Set(CreateCls <B>());
            var rs = new BSharpRuntimeService();

            rs.Activators = new[] { a };
            rs.Providers  = new[] { p };

            Assert.NotNull(rs.Activate <A>("my.test.A"));
            Assert.NotNull(rs.Activate <A>(rs.GetClassNames("*.A").First()));
            Assert.NotNull(rs.Activate <B>(rs.GetClassNames("*.B").First()));
            Assert.NotNull(rs.Activate <B>("my.test.A"));
            Assert.NotNull(rs.Activate <I>("my.test.A"));
            Assert.NotNull(rs.Activate <B>("my.test.A", BSharpActivationType.Client));
        }
예제 #3
0
        public void WorksWithIoc()
        {
            var c = new Container();
            var p = new BSharpGenericClassProvider();

            p.Set(CreateCls <A>());
            p.Set(CreateCls <B>());
            c.Register(
                new ComponentDefinition <
                    IBSharpRuntimeProvider, BSharpGenericClassProvider>(
                    Lifestyle.Extension, "sample.bs.p", implementation: p
                    ));
            c.Register(new ComponentDefinition <IBSharpRuntimeService, BSharpRuntimeService>());
            c.Register(new ComponentDefinition <IBSharpRuntimeActivatorService, BSharpRuntimeActivatorService>());
            c.RegisterSubResolver(new IoC.BSharp.BSharpTypeResolver(c));

            Assert.NotNull(c.Get <A>("bsharp://my.test.A"));
            Assert.NotNull(c.Get <B>("bsharp://my.test.B"));
            Assert.NotNull(c.Get <I>("bsharp://my.test.A"));
            Assert.NotNull(c.Get <I>("bsharp://my.test.B"));
            Assert.NotNull(c.Get <B>("bsharp://my.test.B"));
        }
예제 #4
0
        public void CanResolveClass(string n, string ns, string en)
        {
            var p = new BSharpGenericClassProvider();

            string[] nss       = new[] { "A", "B", "C" };
            string[] css       = new[] { "a", "b", "c" };
            var      currentns = "";

            for (var i = 0; i < 3; i++)
            {
                p.Set(new BSharpRuntimeClass {
                    Name = css[i], Namespace = ""
                });
            }
            for (var i = 0; i < 3; i++)
            {
                if (currentns != "")
                {
                    currentns += ".";
                }
                currentns += nss[i];
                for (var j = 0; j <= i; j++)
                {
                    var cn = css[j];
                    p.Set(new BSharpRuntimeClass {
                        Name = cn, Namespace = currentns
                    });
                    p.Set(new BSharpRuntimeClass {
                        Name = nss[i].ToLower() + cn, Namespace = currentns
                    });
                }
            }


            Assert.AreEqual(en, p.Resolve(n, ns));
        }
예제 #5
0
        private IBSharpRuntimeProvider GetPrecompileClsProvider()
        {
            var provider = new BSharpGenericClassProvider();

            foreach (var cls in _context.PreparedContext.Get(BSharpContextDataType.Working))
            {
                var rcls = new BSharpRuntimeClass {
                    Name          = cls.Name,
                    Namespace     = cls.Namespace,
                    PrototypeCode = cls.Prototype,
                    Loaded        = true,
                    Definition    = cls.Compiled
                };
                provider.Set(rcls);
            }
            return(provider);
        }