Ejemplo n.º 1
0
        private SunsetLake GetSepLake(Dictionary <string, object> args)
        {
            SunsetLake s_lake = new SunsetLake();

            s_lake.RegisterSingleton <ILogger>(LoggerFactory.Auto(this.GetType().Name));
            s_lake.RegisterSingleton <ClassTextReader>(() =>
            {
                return(ClassTextReaderCache.Acquire(this.GetType()));
            });
            s_lake.RegisterSingleton <IExtensionInfo>(() =>
            {
                return(this.GetExtensionInfo());
            });
            s_lake.RegisterSingleton <ILeafUI>(() =>
            {
                ILeafUI leafUI     = this.lake !.Get <ILeafUI>();
                IExtensionInfo inf = this.GetExtensionInfo();
                leafUI.Title       = inf.Name();
                leafUI.Icon        = inf.Icon();
                return(leafUI);
            });
            s_lake.RegisterSingleton <Dictionary <string, object> >(() =>
            {
                return(args ?? new Dictionary <string, object>());
            });
            return(s_lake);
        }
Ejemplo n.º 2
0
        public void FieldTest()
        {
            SunsetLake lake = new SunsetLake();

            lake.RegisterSingleton(FieldInjectTarget.TEST_STR_ID, () => FieldInjectTarget.TEST_STR);
            lake.RegisterSingleton <FieldInjectTarget, FieldInjectTarget>();
            var target = lake.Get <FieldInjectTarget>();

            Assert.IsTrue(target.IsAllRight());
        }
Ejemplo n.º 3
0
        public void RegisterSingletonTest()
        {
            IRegisterableLake lake = new SunsetLake();

            lake.RegisterSingleton(typeof(int), () => 1);
            lake.RegisterSingleton <string>("test string");

            Assert.IsTrue(lake.Get <int>() == 1);
            Assert.IsTrue(lake.Get <string>() == "test string");
        }
Ejemplo n.º 4
0
        public void InjectingTest()
        {
            IRegisterableLake lake     = new SunsetLake();
            const int         TEST_SUM = 50;
            const string      TEST_STR = "test str";

            lake.RegisterSingleton("sum", () => TEST_SUM);
            lake.RegisterSingleton <string>(TEST_STR);
            lake.RegisterSingleton <InjectTestClass, InjectTestClass>();
            var testClass = lake.Get <InjectTestClass>();

            Assert.IsTrue(testClass.Sum == TEST_SUM);
            Assert.IsTrue(testClass.Str == TEST_STR);
        }
Ejemplo n.º 5
0
        public void ObjectBuildTest()
        {
            const int         sum  = 5;
            const string      str  = "test string";
            IRegisterableLake lake = new SunsetLake();

            lake.RegisterSingleton <int>(sum);
            lake.RegisterSingleton <string>(str);
            lake.RegisterSingleton <ITestInterface, TestClass>();

            ITestInterface testInterfaceImpl = lake.Get <ITestInterface>();

            Assert.IsTrue(testInterfaceImpl.Str == str);
            Assert.IsTrue(testInterfaceImpl.Sum == sum);
        }
Ejemplo n.º 6
0
        public void GetComponentsCompatibilitTest()
        {
            IRegisterableLake lake = new SunsetLake();

            lake.RegisterSingleton("t", "2401");
            Assert.AreEqual("2401", lake.GetComponents("t").FirstOrDefault());
        }
Ejemplo n.º 7
0
        public void ByTypeInject()
        {
            const string TEST_STR = "test string";
            SunsetLake   lake     = new SunsetLake();

            lake.RegisterSingleton <string>(TEST_STR);

            var instance = new InjectTarget();

            new DependenciesInjector(instance, lake).Inject();
            Assert.IsTrue(instance.Str == TEST_STR);
        }
Ejemplo n.º 8
0
        public void MixArgsTest()
        {
            const string TEST_STR = "test string";
            const int    SUM      = 3;
            SunsetLake   lake     = new SunsetLake();

            lake.RegisterSingleton <string>("f**k");

            SunsetLake lake2 = new SunsetLake();

            lake.RegisterSingleton <string>(TEST_STR);

            MethodProxy maxProxy = new MethodProxy(this, nameof(HashCodeAdd), lake + lake2);
            long        result   = (long)maxProxy.Invoke(new Dictionary <string, object>()
            {
                { "x", 3 }
            });
            long correctResult = HashCodeAdd(SUM, TEST_STR);

            Assert.IsTrue(correctResult == result);
        }
Ejemplo n.º 9
0
        private ILake GetSepLake()
        {
            SunsetLake s_lake = new SunsetLake();

            s_lake.RegisterSingleton <ILogger>(LoggerFactory.Auto(this.GetType().Name));
            s_lake.RegisterSingleton <ClassTextReader>(() =>
            {
                return(ClassTextReader.GetReader(this));
            });
            s_lake.RegisterSingleton <IExtensionInfo>(() =>
            {
                return(this.GetExtensionInfo());
            });
            s_lake.RegisterSingleton <ILeafUI>(() =>
            {
                ILeafUI leafUI     = this.lake !.Get <ILeafUI>();
                IExtensionInfo inf = this.GetExtensionInfo();
                leafUI.Title       = inf.Name();
                leafUI.Icon        = inf.Icon();
                return(leafUI);
            });
            return(s_lake);
        }