예제 #1
0
 private void OpenScreen(ScreenConductor conductor, IScreenBase screen)
 {
     try {
         conductor.OpenScreen(ScreenFactory.For(screen));
     } catch (ScreenLifecycleException) {
     }
 }
예제 #2
0
        public void OpenScreenUseScreenLocation_WhenNoMatchingScreenIsOpen_CreatesNewScreen()
        {
            var conductor    = CreateConductor();
            var firstSubject = new BaseSubject {
                Value = "First Subject"
            };
            var differentSubject = new BaseSubject {
                Value = "Different Subject"
            };

            conductor.OpenScreen(
                ScreenFactory
                .For <MultipleInstancesScreen>(Locator)
                );

            conductor.OpenScreen(
                ScreenFactory
                .WithSubject(firstSubject)
                .For <LocatableScreen>(Locator)
                );

            conductor.OpenScreen(
                ScreenFactory
                .WithSubject(differentSubject)
                .For <LocatableScreen>(Locator)
                );

            CollectionAssert.AreEqual(
                new[] { firstSubject, differentSubject },
                GetSubjectsOfOpenScreens(conductor)
                );
        }
예제 #3
0
        public void DefaultCreationBehavior()
        {
            ScreenConductor c = CreateConductor();

            c.OpenScreen(ScreenFactory.For <DefaultCreationBehaviorScreen>(Locator));
            c.OpenScreen(ScreenFactory.For <DefaultCreationBehaviorScreen>(Locator));
            Assert.AreEqual(2, c.Screens.Count());
        }
예제 #4
0
        public void SingleInstance()
        {
            ScreenConductor c = CreateConductor();

            c.OpenScreen(ScreenFactory.For <SingleInstanceScreen>(Locator));
            c.OpenScreen(ScreenFactory.For <SingleInstanceScreen>(Locator));
            Assert.AreEqual(1, c.Screens.Count());
        }
예제 #5
0
        public void MultipleInstances()
        {
            ScreenConductor c = CreateConductor();

            c.OpenScreen(ScreenFactory.For <MultipleInstancesScreen>(Locator));
            c.OpenScreen(ScreenFactory.For <MultipleInstancesScreen>(Locator));
            Assert.AreEqual(2, c.Screens.Count());
        }
예제 #6
0
        public void TestCreateWithDefaultServiceLocator()
        {
            TestScreen screen = ScreenFactory
                                .For <TestScreen>()
                                .Create(Aggregator);

            Assert.IsNotNull(screen);
        }
예제 #7
0
        public void ScreenFactoriesForConcreteScree_CanBeAssignedToScreenBaseFactoryVariable()
        {
            IScreenFactory <TestScreen>  concreteFactory = ScreenFactory.For <TestScreen>();
            IScreenFactory <IScreenBase> factory         = concreteFactory;

            IScreenBase screen = factory.Create(Aggregator);

            Assert.IsInstanceOfType(screen, typeof(TestScreen));
        }
예제 #8
0
        public void ShowDialogWithCertainScreenInstance_ScreenLifecycleDoesntContainDialogLifecycleAfterShowDialog()
        {
            WindowService.ShowRealWindow = false;

            var screen = new ScreenMock(Aggregator);

            DialogSerivce.ShowDialog(ScreenFactory.For(screen));
            Assert.IsFalse(screen.Children.OfType <DialogLifecycle>().Any());
        }
예제 #9
0
        public void Create_ScreenFactoryForInstance_ReturnsThisInstance()
        {
            var expected = new InitializableScreen(Aggregator);

            IScreenFactory <InitializableScreen> factory = ScreenFactory.For(expected);

            var actual = factory.Create(Aggregator);

            Assert.AreEqual(expected, actual);
        }
예제 #10
0
        public void Create_ScreenFactoryForInstance_CallsInitialize()
        {
            var expected = new InitializableScreen(Aggregator);

            IScreenFactory <InitializableScreen> factory = ScreenFactory.For <InitializableScreen>(Locator);

            var actual = factory.Create(Aggregator);

            Assert.IsTrue(actual.InitializeWasCalled);
        }
예제 #11
0
        private ScreenConductor CreateScreenConductor()
        {
            ScreenConductor conductor = ScreenFactory
                                        .For(new ScreenConductor(Aggregator))
                                        .Create(Aggregator);

            new ScreenLifecycleOperations(Aggregator, conductor)
            .Activate();

            return(conductor);
        }
예제 #12
0
        public void OpenScreen_WithBaseClassScreenFactory_DoesNotOpenScreenIfActualTypesMatch()
        {
            ScreenConductor c = CreateConductor();

            c.OpenScreen(ScreenFactory.For <SingleInstanceScreen>(Locator));

            IScreenFactory <IScreenBase> baseFactory = ScreenFactory
                                                       .For <SingleInstanceScreen>(Locator);

            c.OpenScreen(baseFactory);

            Assert.AreEqual(1, c.Screens.Count());
        }
예제 #13
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);
        }
예제 #14
0
        public void OpenScreen_WhenScreenIsNotAlreadyOpen_PublishesScreenOpenedEvent()
        {
            var conductor = CreateScreenConductor();
            var newScreen = new SingleInstanceScreen();

            var eventArgs = ExpectScreenOpenedEvent(() => {
                conductor.OpenScreen(ScreenFactory.For(newScreen));
            });

            Assert.IsNotNull(eventArgs);
            Assert.AreEqual(conductor, eventArgs.Conductor);
            Assert.AreEqual(newScreen, eventArgs.Screen);
            Assert.IsFalse(eventArgs.WasAlreadyOpen);
        }
예제 #15
0
        public void GetAssociatedWindow_ReturnsWindow()
        {
            WindowService.ShowRealWindow = false;

            WindowView window = new WindowView(false);
            ScreenMock screen = new ScreenMock(Aggregator);

            DialogSerivce.Show(
                window,
                ScreenFactory.For(screen),
                modal: false
                );

            Assert.AreEqual(window, DialogSerivce.GetAssociatedWindow(screen));
        }
예제 #16
0
        public void Show_AttachesAppropriateChildren()
        {
            WindowService.ShowRealWindow = false;

            var screen = new ScreenMock(Aggregator);

            DialogSerivce.Show(
                new WindowView(false),
                ScreenFactory.For(screen),
                modal: false
                );

            Assert.IsTrue(screen.Children.OfType <WindowLifecycle>().Any());
            Assert.IsTrue(screen.Children.OfType <ScreenCloseHandler>().Any());
            Assert.IsFalse(screen.Children.OfType <DialogLifecycle>().Any());
        }
예제 #17
0
        public void OpenScreen_WhenScrenIsAlreadyOpen_DoesNotAddScreenCloseHandler()
        {
            var conductor           = CreateScreenConductor();
            var alreadyOpenedScreen = new SingleInstanceScreen();

            conductor.OpenScreen(ScreenFactory.For(alreadyOpenedScreen));

            conductor.OpenScreen(ScreenFactory.For(alreadyOpenedScreen));

            Assert.AreEqual(
                1,
                alreadyOpenedScreen
                .Children
                .OfType <ScreenCloseHandler>()
                .Count()
                );
        }
예제 #18
0
        public void CloseView_CallsRequestClose()
        {
            bool isCloseAllowed = false;

            TestScreen screen = new TestScreen(Aggregator);

            screen.Lifecycle.RegisterHandler(
                ScreenEvents.RequestClose,
                args => args.IsCloseAllowed = isCloseAllowed
                );

            Conductor.OpenScreen(ScreenFactory.For(screen));

            object view = Adapter
                          .Views
                          .Cast <Object>()
                          .Single();

            Assert.IsFalse(Adapter.CloseView(view));

            isCloseAllowed = true;

            Assert.IsTrue(Adapter.CloseView(view));
        }
예제 #19
0
 private void ShowDialog(IScreenBase screen)
 {
     DialogSerivce.ShowDialog(ScreenFactory.For(screen));
 }
예제 #20
0
        public void AddScreen_SetsParent()
        {
            TestScreen s = Collection.AddScreen(ScreenFactory.For <TestScreen>(Locator));

            Assert.AreEqual(Parent, s.Parent);
        }
예제 #21
0
 public ShellScreen(EventAggregator aggregator)
     : base(aggregator)
 {
     WorkScreens = Children.AddScreen(ScreenFactory.For <ScreenConductor>());
 }