public void TestPushStackTwice()
        {
            TestScreen testScreen = null;

            AddStep("public push", () => stack.Push(testScreen = new TestScreen()));
            AddStep("ensure succeeds", () => Assert.IsTrue(stack.CurrentScreen == testScreen));
            AddStep("ensure internal throws", () => Assert.Throws <InvalidOperationException>(() => stack.Push(null, new TestScreen())));
        }
            public TestScreen PushNext()
            {
                TestScreen screen = CreateNextScreen();

                Push(screen);

                return(screen);
            }
        public void Initialize_WhenCompileTimeTypeOfSubjectIsInterface_CallsInitializeOverloadOfRuntimeType()
        {
            var subject = new DerivedSubject();
            var screen  = new TestScreen <BaseSubject>(Aggregator);

            Initialize(screen, (ISubject)subject);
            Assert.AreEqual(subject, screen.LastSubject);
        }
Exemplo n.º 4
0
 public void SetupTest() => Schedule(() =>
 {
     Clear();
     Add(stack = new ScreenStack(baseScreen = new TestScreen())
     {
         RelativeSizeAxes = Axes.Both
     });
 });
        public void Initialize_WithSubjectOfDerivedType_CallsInitialize()
        {
            var subject = new DerivedSubject();
            var screen  = new TestScreen <BaseSubject>(Aggregator);

            Initialize(screen, subject);
            Assert.AreEqual(subject, screen.LastSubject);
        }
        public void TestMakeCurrentOnSameScreen()
        {
            TestScreen screen1 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen());
            AddStep("Make current the same screen", () => screen1.MakeCurrent());
            AddAssert("Screen 1 is current", () => screen1.IsCurrentScreen());
        }
Exemplo n.º 7
0
        private void PerformDependsOnChildrenTest()
        {
            // This control has children which have widths that depend on the parent, so they have dependent units on the X axis, not Y axis. The stack panel should still
            // auto-size itself based on the heights of the children.
            var stackPanel = TestScreen.GetGraphicalUiElementByName("StackWithChildrenWidthDependsOnParent");

            stackPanel.GetAbsoluteHeight().ShouldNotBe(0, "because the height of the container should be set even though the the width of the contained nine slice depends on its parent.");
        }
Exemplo n.º 8
0
        public void TestAsyncPush()
        {
            TestScreen screen1 = null;

            AddStep("push slow", () => baseScreen.Push(screen1 = new TestScreenSlow()));
            AddAssert("ensure current", () => !screen1.IsCurrentScreen());
            AddWaitStep(1);
            AddUntilStep(() => screen1.IsCurrentScreen(), "ensure current");
        }
Exemplo n.º 9
0
        public void AddScreen_CallsInitialize()
        {
            Object     subject = new Object();
            TestScreen s       = Collection.AddScreen(
                ScreenFactory.WithSubject(subject).For <TestScreen>(Locator)
                );

            Assert.AreEqual(subject, s.Subject);
        }
Exemplo n.º 10
0
        public void TestPushAlreadyLoadedScreenFails()
        {
            TestScreen screen1 = null;

            AddStep("push once", () => stack.Push(screen1 = new TestScreen()));
            AddStep("exit", () => screen1.Exit());
            AddStep("push again fails", () => Assert.Throws <InvalidOperationException>(() => stack.Push(screen1)));
            AddAssert("stack in valid state", () => stack.CurrentScreen == baseScreen);
        }
Exemplo n.º 11
0
        public void Do_not_update()
        {
            var screen   = new TestScreen();
            var behavior = new SearchBehavior(screen);

            behavior.SearchText.Value = "test";
            behavior.Search();
            Assert.AreEqual("", behavior.SearchText.Value);
            Assert.AreEqual("test", behavior.ActiveSearchTerm.Value);
        }
Exemplo n.º 12
0
        public void TestReturnBindsBeforeResume()
        {
            TestScreen screen1 = null, screen2 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen());
            pushAndEnsureCurrent(() => screen2 = new TestScreen(true), () => screen1);
            AddStep("Exit screen", () => screen2.Exit());
            AddUntilStep("Wait until base is current", () => screen1.IsCurrentScreen());
            AddAssert("Bindables have been returned by new screen", () => !screen2.DummyBindable.Disabled && !screen2.LeasedCopy.Disabled);
        }
Exemplo n.º 13
0
        public void Remove_ClearsParent()
        {
            TestScreen s = new TestScreen(Aggregator);

            Collection.Attach(s);
            Assert.AreEqual(Parent, s.Parent);

            Collection.Remove(s);
            Assert.IsNull(s.Parent);
        }
Exemplo n.º 14
0
        public void TestScreensUnboundAndDisposedOnStackDisposal()
        {
            const int screen_count = 5;
            const int exit_count   = 2;

            List <TestScreen> screens = null;
            int disposedScreens       = 0;

            AddStep("Setup screens", () =>
            {
                screens         = new List <TestScreen>();
                disposedScreens = 0;

                for (int i = 0; i < screen_count; i++)
                {
                    var screen = new TestScreen(id: i);

                    screen.OnDispose += () => disposedScreens++;

                    screen.OnUnbindAllBindables += () =>
                    {
                        if (screens.Last() != screen)
                        {
                            throw new InvalidOperationException("Unbind order was wrong");
                        }

                        screens.Remove(screen);
                    };

                    screens.Add(screen);
                }
            });

            for (int i = 0; i < screen_count; i++)
            {
                var local = i; // needed to store the correct value for our delegate
                pushAndEnsureCurrent(() => screens[local], () => local > 0 ? screens[local - 1] : null);
            }

            AddStep("remove and dispose stack", () =>
            {
                // We must exit a few screens just before the stack is disposed, otherwise the stack will update for one more frame and dispose screens itself
                for (int i = 0; i < exit_count; i++)
                {
                    stack.Exit();
                }

                Remove(stack);
                stack.Dispose();
            });

            AddUntilStep("All screens unbound in correct order", () => screens.Count == 0);
            AddAssert("All screens disposed", () => disposedScreens == screen_count);
        }
Exemplo n.º 15
0
        protected override void LoadContent()
        {
            // TODO: use this.Content to load your game content here
            TestScreen Test = new TestScreen(this);
            Test.BlocksUpdate = false;
            Test.BlocksDraw = false;

            screenManager.pushScreen(Test);

            base.LoadContent();
        }
        public void Initialize_WhenScreenDoesNotImplementInterface_CallsInitializeOnChildren()
        {
            var subject = new DerivedSubject();
            var parent  = new ParentScreenWithoutHandler(Aggregator);
            var child   = new TestScreen <BaseSubject>(Aggregator);

            parent.Children.Attach(child);

            Initialize(parent, subject);
            Assert.AreEqual(subject, child.LastSubject, "Initialize was not called on child.");
        }
        public void Initialize_WithSubjectOfDerivedType_CallsInitializeOnScreenAndItsChildren()
        {
            var subject = new DerivedSubject();
            var parent  = new ParentScreenWithHandler <DerivedSubject>(Aggregator);
            var child   = new TestScreen <BaseSubject>(Aggregator);

            parent.Children.Attach(child);

            Initialize(parent, subject);
            Assert.AreEqual(subject, parent.LastSubject, "Initialize was not called on parent.");
            Assert.AreEqual(subject, child.LastSubject, "Initialize was not called on child.");
        }
Exemplo n.º 18
0
        public void TestScreenPushedAfterExiting()
        {
            TestScreen screen1 = null;

            AddStep("push", () => stack.Push(screen1 = new TestScreen()));

            AddUntilStep("wait for current", () => screen1.IsCurrentScreen());
            AddStep("exit screen1", () => screen1.Exit());
            AddUntilStep("ensure exited", () => !screen1.IsCurrentScreen());

            AddStep("push again", () => Assert.Throws <InvalidOperationException>(() => stack.Push(screen1)));
        }
Exemplo n.º 19
0
        public void TestPushFocusLost()
        {
            TestScreen screen1 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen {
                EagerFocus = true
            });
            AddUntilStep("wait for focus grab", () => GetContainingInputManager().FocusedDrawable == screen1);

            pushAndEnsureCurrent(() => new TestScreen(), () => screen1);

            AddUntilStep("focus lost", () => GetContainingInputManager().FocusedDrawable != screen1);
        }
Exemplo n.º 20
0
        public void TestExitBeforePush()
        {
            TestScreen screen1 = null;
            TestScreen screen2 = null;

            AddStep("push slow", () => baseScreen.Push(screen1 = new TestScreenSlow()));
            AddStep("exit slow", () => screen1.Exit());
            AddUntilStep(() => screen1.LoadState >= LoadState.Ready, "wait for screen to load");
            AddAssert("ensure not current", () => !screen1.IsCurrentScreen());
            AddAssert("ensure base still current", () => baseScreen.IsCurrentScreen());
            AddStep("push fast", () => baseScreen.Push(screen2 = new TestScreen()));
            AddUntilStep(() => screen2.IsCurrentScreen(), "ensure new current");
        }
Exemplo n.º 21
0
        public void TestCaseExitBeforePush()
        {
            TestScreen screen1 = null;
            TestScreen screen2 = null;

            AddStep("push slow", () => baseScreen.Push(screen1 = new TestScreenSlow()));
            AddStep("exit slow", () => screen1.Exit());
            AddAssert("ensure not current", () => !screen1.IsCurrentScreen);
            AddWaitStep(5);
            AddAssert("ensure not current", () => !screen1.IsCurrentScreen);
            AddAssert("ensure base still current", () => baseScreen.IsCurrentScreen);
            AddStep("push fast", () => baseScreen.Push(screen2 = new TestScreen()));
            AddAssert("ensure new current", () => screen2.IsCurrentScreen);
        }
Exemplo n.º 22
0
        public void TestServiceLocatorIsUsed()
        {
            var locatorMock = new Mock <IServiceLocator>();

            locatorMock
            .Setup(x => x.GetInstance <TestScreen>())
            .Returns(new TestScreen("Test"));

            TestScreen screen = ScreenFactory
                                .For <TestScreen>(locatorMock.Object)
                                .Create(Aggregator);

            Assert.AreEqual("Test", screen.Dependency);
        }
        public void TestGetChildScreenAndGetParentScreenReturnNullWhenNotInStack()
        {
            TestScreen screen1 = null;
            TestScreen screen2 = null;
            TestScreen screen3 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen(id: 1));
            pushAndEnsureCurrent(() => screen2 = new TestScreen(id: 2), () => screen1);
            pushAndEnsureCurrent(() => screen3 = new TestScreen(id: 3), () => screen2);

            AddStep("exit from screen 3", () => screen3.Exit());
            AddAssert("screen 3 parent is null", () => screen3.GetParentScreen() == null);
            AddAssert("screen 3 child is null", () => screen3.GetChildScreen() == null);
        }
Exemplo n.º 24
0
        public void TestComeVisibleFromHidden()
        {
            TestScreen screen1 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen {
                Alpha = 0
            });

            AddUntilStep("screen1 is visible", () => screen1.Alpha > 0);

            pushAndEnsureCurrent(() => new TestScreen {
                Alpha = 0
            }, () => screen1);
        }
Exemplo n.º 25
0
        public void TestPushFocusTransferred()
        {
            TestScreen screen1 = null, screen2 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen {
                EagerFocus = true
            });
            AddUntilStep("wait for focus grab", () => GetContainingInputManager().FocusedDrawable == screen1);

            pushAndEnsureCurrent(() => screen2 = new TestScreen {
                EagerFocus = true
            }, () => screen1);

            AddUntilStep("focus transferred", () => GetContainingInputManager().FocusedDrawable == screen2);
        }
Exemplo n.º 26
0
        public void TestPushInstantExitScreenEmpty()
        {
            AddStep("fresh stack with non-valid screen", () =>
            {
                Clear();
                Add(stack = new ScreenStack(baseScreen = new TestScreen {
                    ValidForPush = false
                })
                {
                    RelativeSizeAxes = Axes.Both
                });
            });

            AddAssert("stack is empty", () => stack.InternalChildren.Count == 0);
        }
Exemplo n.º 27
0
        public void TestMakeCurrentDuringLoad()
        {
            TestScreen     screen1 = null;
            TestScreenSlow screen2 = null;

            pushAndEnsureCurrent(() => screen1 = new TestScreen());
            AddStep("push slow", () => screen1.Push(screen2 = new TestScreenSlow()));

            AddStep("make screen1 current", () => screen1.MakeCurrent());
            AddStep("allow load of screen2", () => screen2.AllowLoad.Set());
            AddUntilStep("wait for screen2 to load", () => screen2.LoadState == LoadState.Ready);

            AddAssert("screen1 is current screen", () => screen1.IsCurrentScreen());
            AddAssert("screen2 did not receive OnEntering", () => screen2.EnteredFrom == null);
            AddAssert("screen2 did not receive OnExiting", () => screen2.ExitedTo == null);
        }
Exemplo n.º 28
0
        public void ParallaxAssignmentTest()
        {
            NoParallaxTestScreen noParallaxScreen = null;
            TestScreen           parallaxScreen   = null;

            AddStep("Push no parallax", () => stack.Push(noParallaxScreen = new NoParallaxTestScreen("NO PARALLAX")));
            AddUntilStep("Wait for current", () => noParallaxScreen.IsLoaded);
            AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);

            AddStep("Push parallax", () => noParallaxScreen.Push(parallaxScreen = new TestScreen("PARALLAX")));
            AddUntilStep("Wait for current", () => parallaxScreen.IsLoaded);
            AddAssert("Parallax is on", () => stack.ParallaxAmount > 0);

            AddStep("Exit from new screen", () => { noParallaxScreen.MakeCurrent(); });
            AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
        }
Exemplo n.º 29
0
        public void TestEventsNotFiredBeforeScreenLoad()
        {
            Screen screen1   = null;
            bool   wasLoaded = true;

            pushAndEnsureCurrent(() => screen1 = new TestScreen
            {
                // ReSharper disable once AccessToModifiedClosure
                Entered = () => wasLoaded &= screen1?.IsLoaded == true,
                // ReSharper disable once AccessToModifiedClosure
                Suspended = () => wasLoaded &= screen1?.IsLoaded == true,
            });

            pushAndEnsureCurrent(() => new TestScreen(), () => screen1);

            AddAssert("was loaded before events", () => wasLoaded);
        }
Exemplo n.º 30
0
        public void VariousOperations_WhenHandlerThrowsException_RaiseLifecycleExceptionOccuredEventAndThrowLifecycleException()
        {
            ParameterizedTest
            .TestCase <Action <ScreenLifecycleOperations>, IEvent>(x => x.Initialize(), ScreenEvents.Initialize())
            .TestCase(x => x.Initialize(new Subject()), ScreenEvents.Initialize <Subject>())
            .TestCase(x => x.Activate(), ScreenEvents.Activate)
            .TestCase(x => x.Deactivate(), ScreenEvents.Deactivate)
            .TestCase(x => x.RequestClose(), ScreenEvents.RequestClose)
            .TestCase(x => x.Close(), ScreenEvents.Close)
            .Run((lifecycleAction, expectedEvent) => {
                List <IEvent> actualEvents    = new List <IEvent>();
                TestScreen screen             = new TestScreen();
                ScreenLifecycleOperations ops = new ScreenLifecycleOperations(Aggregator, screen);

                InvalidOperationException sourceException = new InvalidOperationException();

                AddEventHandlerForAllEvents(
                    screen,
                    handlerAction: e => {
                    actualEvents.Add(e);
                    throw sourceException;
                },
                    includeExceptionOccured: false
                    );

                AddEventHandlerFor(
                    ScreenEvents.LifecycleExceptionOccured,
                    screen,
                    handlerAction: (ev, _) => actualEvents.Add(ev)
                    );

                var exceptionExpr = AssertHelper.Throws <ScreenLifecycleException>(() =>
                                                                                   lifecycleAction(ops)
                                                                                   );

                CollectionAssert.AreEquivalent(
                    new IEvent[] {
                    expectedEvent,
                    ScreenEvents.LifecycleExceptionOccured
                },
                    actualEvents
                    );

                Assert.AreEqual(sourceException, exceptionExpr.Exception.InnerException);
            });
        }
        public void matches_on_test()
        {
            var theTest = new Test("test1");
            var otherTest = new Test("test2");

            var subject = new ScreenLocator<Test>(theTest);

            var testView = MockRepository.GenerateMock<ITestView>();

            var modes = new TestMode[] {new PreviewMode(null, null, null)};
            var presenterThatDoesNotMatch = new TestScreen(null, null, otherTest, new TestStateManager(new TestConverter(), otherTest), null, null, null);
            var presenterThatShouldMatch = new TestScreen(null, null, theTest, new TestStateManager(new TestConverter(), theTest), null, null, null);
            var differentTypeOfPresenter = MockRepository.GenerateMock<IScreen>();

            subject.Matches(presenterThatDoesNotMatch).ShouldBeFalse();
            subject.Matches(presenterThatShouldMatch).ShouldBeTrue();
            subject.Matches(differentTypeOfPresenter).ShouldBeFalse();
        }
Exemplo n.º 32
0
        public void NotificationsArentLostOnPositionerUpdateTest()
        {
            var testScreen = new TestScreen {
                bounds = new Rect(0, 0, 1000, 500)
            };
            var notifier1  = new CustomNotifier(testScreen);
            var notifier2  = new CustomNotifier(testScreen);
            var positioner = CustomNotifier.positioner;

            notifier1.UpdatePositioner(NotificationPosition.BottomRight, 5);
            var toasts1 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier1)).ToList();
            var toasts2 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier2)).ToList();
            var tasks1  = toasts1.Select(toast => notifier1.ShowAsync(toast, 1)).ToList();
            var tasks2  = toasts2.Select(toast => notifier2.ShowAsync(toast, 1)).ToList();

            tasks1.Union(tasks2).ToList().ForEach(WaitWithDispatcher);
            tasks1.Union(tasks2).ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result));
        }
        public void ResolutionChangingTest() {
            var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 1000, 500) };
            var notifier = new CustomNotifier(testScreen);
            notifier.UpdatePositioner(NotificationPosition.BottomRight, 2);
            var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList();
            var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList();

            Assert.AreEqual(2, CustomNotifier.positioner.Items.Count(i => i != null));

            testScreen.bounds = new System.Drawing.Rectangle(0, 0, 800, 600);
            testScreen.Changed();

            Assert.AreEqual(2, CustomNotifier.positioner.Items.Count(i => i != null));

            tasks.ToList().ForEach(WaitWithDispatcher);
        }
        public void UpdatePositionerTest() {
            var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 800, 600) };
            var notifier = new CustomNotifier(testScreen);
            var pos = CustomNotifier.positioner;

            var toast = new CustomNotification(null, notifier);
            var task = notifier.ShowAsync(toast, 1);
            var p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]);
            Assert.AreEqual(415, p1.X);
            Assert.AreEqual(20, p1.Y);

            notifier.UpdatePositioner(NotificationPosition.BottomRight, 3);
            p1 = CustomNotifier.positioner.GetItemPosition(CustomNotifier.positioner.Items[0]);
            Assert.AreEqual(415, p1.X);
            Assert.AreEqual(490, p1.Y);

            WaitWithDispatcher(task);
        }
 public void NotificationsArentLostOnPositionerUpdateTest() {
     var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 1000, 500) };
     var notifier1 = new CustomNotifier(testScreen);
     var notifier2 = new CustomNotifier(testScreen);
     var positioner = CustomNotifier.positioner;
     notifier1.UpdatePositioner(NotificationPosition.BottomRight, 5);
     var toasts1 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier1)).ToList();
     var toasts2 = Enumerable.Range(0, 1).Select(_ => new CustomNotification(null, notifier2)).ToList();
     var tasks1 = toasts1.Select(toast => notifier1.ShowAsync(toast, 1)).ToList();
     var tasks2 = toasts2.Select(toast => notifier2.ShowAsync(toast, 1)).ToList();
     tasks1.Union(tasks2).ToList().ForEach(WaitWithDispatcher);
     tasks1.Union(tasks2).ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result));
 }
        public void BasicResolutionChangedHandlingTest() {
            var testScreen = new TestScreen { bounds = new System.Drawing.Rectangle(0, 0, 1000, 500) };
            var notifier = new CustomNotifier(testScreen);
            notifier.UpdatePositioner(NotificationPosition.BottomRight, 2);
            var toasts = Enumerable.Range(0, 3).Select(_ => new CustomNotification(null, notifier)).ToList();
            var tasks = toasts.Select(toast => notifier.ShowAsync(toast, 1)).ToList();

            var pos = CustomNotifier.positioner;
            var ps = pos.Items.Select(i => pos.GetItemPosition(i)).ToList();
            Assert.AreEqual(new Point(615, 390), ps[0]);
            Assert.AreEqual(new Point(615, 290), ps[1]);

            testScreen.bounds = new System.Drawing.Rectangle(0, 0, 800, 600);
            testScreen.Changed();
            pos = CustomNotifier.positioner;
            ps = pos.Items.Select(i => pos.GetItemPosition(i)).ToList();
            Assert.AreEqual(new Point(415, 490), ps[0]);
            Assert.AreEqual(new Point(415, 390), ps[1]);

            tasks.ToList().ForEach(WaitWithDispatcher);
            tasks.ToList().ForEach(t => Assert.AreEqual(NotificationResult.TimedOut, t.Result));
        }