Пример #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);
        }
Пример #2
0
        public ComponentFactoryTest()
        {
            lake = new SunsetLake();
            var reader = new ComponentFactoryReader(lake, typeof(TestFactory));

            reader.Read();
        }
Пример #3
0
#pragma warning restore CS8618 // 不可为 null 的字段未初始化。请考虑声明为可以为 null。

        /// <summary>
        /// 构造应用
        /// </summary>
        public App() : base()
        {
            Current = this;
            Thread.CurrentThread.Name = "Application Main Thread";
            AppLoader = new GeneralAppLoader();
            Lake      = new SunsetLake();
        }
        public void MainTest()
        {
            IRegisterableLake lake = new SunsetLake();

            new ClassComponentsLoader("AutumnBox.Tests.OpenFX.Leafx", lake).Do();
            Assert.IsTrue(lake.Get <F**k>().Yes());
        }
Пример #5
0
        public void GetComponentsCompatibilitTest()
        {
            IRegisterableLake lake = new SunsetLake();

            lake.RegisterSingleton("t", "2401");
            Assert.AreEqual("2401", lake.GetComponents("t").FirstOrDefault());
        }
Пример #6
0
        public void RegisterTest()
        {
            IRegisterableLake lake = new SunsetLake();
            int time = 0;

            lake.Register <int>(() => time++);

            Assert.IsTrue((lake.Get <int>() - lake.Get <int>()) == -1);
        }
Пример #7
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");
        }
Пример #8
0
        private static IRegisterableLake BuildLake()
        {
            SunsetLake lake = new SunsetLake();

            new ClassComponentsLoader(
                "AutumnBox.GUI.Services.Impl",
                lake)
            .Do();
            return(lake);
        }
Пример #9
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());
        }
Пример #10
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);
        }
Пример #11
0
        public void IntelliInject()
        {
            SunsetLake lake = new SunsetLake();

            lake.Register <DateTime>(() => DateTime.Now);

            var instance         = new InjectTarget();
            var originalDateTime = instance.CreateDateTime;

            new DependenciesInjector(instance, lake).Inject();
            Assert.IsTrue(instance.CreateDateTime != originalDateTime);
        }
Пример #12
0
        public void CheckTest()
        {
            Assert.ThrowsException <NotSupportedException>(() =>
            {
                ILake lake = new SunsetLake();
                lake.GetComponents("t");
            });

            ILake lake = new TestLake();

            Assert.IsTrue(lake.GetComponents("t").Count() == 0);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
        public void FindEntryPoint()
        {
            IRegisterableLake lake = new SunsetLake();

            {
                var leaf   = lake.CreateInstance <EEntryPointFindingTest1>();
                var result = leaf.Main(new Dictionary <string, object>());
                Assert.AreEqual(result, EEntryPointFindingTest1.TEST_RESULT);
            }
            {
                var leaf   = lake.CreateInstance <EEntryPointFindingTest2>();
                var result = leaf.Main(new Dictionary <string, object>());
                Assert.AreEqual(result, EEntryPointFindingTest2.TEST_RESULT);
            }
            {
                var leaf   = lake.CreateInstance <EEntryPointFindingTest3>();
                var result = leaf.Main(new Dictionary <string, object>());
                Assert.AreEqual(result, EEntryPointFindingTest3.TEST_RESULT);
            }
        }
Пример #16
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);
        }
Пример #17
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);
        }