Esempio n. 1
0
 public void TestAsyncLoadComplete()
 {
     AddStep("add box", () => Child = box = new AsyncPerformingBox(true));
     AddAssert("not spun", () => box.Rotation == 0);
     AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock());
     AddUntilStep("has spun", () => box.Rotation == 180);
 }
Esempio n. 2
0
        public void TestAsyncInsideUpdate()
        {
            int updateCount = 0;

            AddStep("add box", () =>
            {
                updateCount = 0;
                Child       = box = new AsyncPerformingBox(false);
            });

            AddUntilStep("has spun", () => box.Rotation == 180);

            AddStep("update with async", () =>
            {
#pragma warning disable 4014
                box.OnUpdate += _ => asyncAction();
#pragma warning restore 4014

                async Task asyncAction()
                {
                    updateCount++;
                    await box.PerformAsyncWait().ConfigureAwait(true);
                    box.RotateTo(0, 500);
                }
            });

            AddUntilStep("is running updates", () => updateCount > 5);
            AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock());
            AddUntilStep("has spun", () => box.Rotation == 0);
        }
Esempio n. 3
0
        public void TestAsyncUsesScheduler()
        {
            int initialTasksRun = 0;

            AddStep("get initial run count", () => initialTasksRun = syncContext.TotalTasksRun);
            AddStep("add box", () => Child = box = new AsyncPerformingBox(true));
            AddAssert("no tasks run", () => syncContext.TotalTasksRun == initialTasksRun);
            AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock());
            AddUntilStep("one new task run", () => syncContext.TotalTasksRun == initialTasksRun + 1);
        }
Esempio n. 4
0
        public void TestNoAsyncDoesntUseScheduler()
        {
            int initialTasksRun = 0;

            AddStep("get initial run count", () => initialTasksRun = syncContext.TotalTasksRun);
            AddStep("add box", () => Child = box = new AsyncPerformingBox(false));
            AddAssert("no tasks run", () => syncContext.TotalTasksRun == initialTasksRun);
            AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock());
            AddAssert("no tasks run", () => syncContext.TotalTasksRun == initialTasksRun);
        }
Esempio n. 5
0
        public void TestExecutionMode()
        {
            AddStep("add box", () => Child = box = new AsyncPerformingBox(true));
            AddAssert("not spun", () => box.Rotation == 0);

            AddStep("toggle execution mode", () => toggleExecutionMode());

            AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock());
            AddUntilStep("has spun", () => box.Rotation == 180);

            AddStep("revert execution mode", () => toggleExecutionMode());

            void toggleExecutionMode()
            {
                var executionMode = config.GetBindable <ExecutionMode>(FrameworkSetting.ExecutionMode);

                executionMode.Value = executionMode.Value == ExecutionMode.MultiThreaded
                    ? ExecutionMode.SingleThread
                    : ExecutionMode.MultiThreaded;
            }
        }
Esempio n. 6
0
        public void TestAsyncInsideSchedule()
        {
            AddStep("add box", () => Child = box = new AsyncPerformingBox(false));
            AddUntilStep("has spun", () => box.Rotation == 180);

            AddStep("schedule with async", () =>
            {
#pragma warning disable 4014
                // We may want to give `Schedule` a `Task` accepting overload in the future.
                box.Schedule(() => asyncScheduledAction());
#pragma warning restore 4014

                async Task asyncScheduledAction()
                {
                    await box.PerformAsyncWait().ConfigureAwait(true);
                    box.RotateTo(0, 500);
                }
            });

            AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock());
            AddUntilStep("has spun", () => box.Rotation == 0);
        }