Esempio n. 1
0
        public void T020_DefineNestedOrder()
        {
            var entries = new List <int>();
            int x       = 0;

            Func <Action> FMakeAdder = () => { var a = x++; return(() => entries.Add(a)); }; // Fixes the X value at the moment of FMakeAdder call.

            bool flag = false;

            Lifetime.Using(lifetime =>
            {
                lifetime.OnTermination(FMakeAdder());
                lifetime.AddDispose(Disposable.CreateAction(FMakeAdder()));
                Lifetime.Define(lifetime, atomicAction: (lifeNested) => { lifeNested.OnTermination(FMakeAdder()); lifeNested.OnTermination(FMakeAdder()); lifeNested.OnTermination(FMakeAdder()); });
                lifetime.AddDispose(Disposable.CreateAction(FMakeAdder()));
                Lifetime.Define(lifetime, atomicAction: (lifeNested) => { lifeNested.OnTermination(FMakeAdder()); lifeNested.OnTermination(FMakeAdder()); lifeNested.OnTermination(FMakeAdder()); });
                lifetime.AddDispose(Disposable.CreateAction(FMakeAdder()));
                Lifetime.Define(lifetime, atomicAction: (lifeNested) => lifeNested.OnTermination(() => flag = true)).Terminate();
                Assert.IsTrue(flag, "Nested closing FAIL.");
                flag = false;
                lifetime.AddDispose(Disposable.CreateAction(FMakeAdder()));
            });

            Assert.IsFalse(flag, "Nested closed twice.");

            CollectionAssert.AreEqual(System.Linq.Enumerable.Range(0, entries.Count).Reverse().ToArray(), entries, "Order FAIL.");
        }
        public GenerateUnityEventFunctionsActionExecutionTest()
        {
            ExecuteBeforeTest = solution =>
            {
                var provider = Solution.GetComponent <TestGenerateUnityEventFunctionsProvider>();
                provider.SelectElement("Awake");
                provider.SelectElement("Update");
                provider.SelectElement("LateUpdate");

                return(Disposable.CreateAction(() => Solution.GetComponent <TestGenerateUnityEventFunctionsProvider>().Clear()));
            };
        }
Esempio n. 3
0
        public void T000_Items()
        {
            int count = 0;

            Lifetime.Using(lifetime =>
            {
                lifetime.OnTermination(() => count++);
                lifetime.AddDispose(Disposable.CreateAction(() => count++));
                lifetime.OnTermination(() => count++);
                lifetime.OnTermination(Disposable.CreateAction(() => count++));
            });

            Assert.AreEqual(4, count, "Mismatch.");
        }
Esempio n. 4
0
        public void T010_SimpleOrder()
        {
            var entries = new List <int>();
            int x       = 0;

            Lifetime.Using(lifetime =>
            {
                int a = x++;
                lifetime.OnTermination(() => entries.Add(a));
                int b = x++;
                lifetime.AddDispose(Disposable.CreateAction(() => entries.Add(b)));
                int c = x++;
                lifetime.OnTermination(Disposable.CreateAction(() => entries.Add(c)));
                int d = x++;
                lifetime.AddDispose(Disposable.CreateAction(() => entries.Add(d)));
            });

            CollectionAssert.AreEqual(Enumerable.Range(0, entries.Count).Reverse().ToArray(), entries, "Order FAIL.");
        }