[Fact] // See http://caliburnmicro.codeplex.com/discussions/430917
        public void TryCloseStressTest()
        {
            var conductor = new Conductor <IScreen> .Collection.OneActive();

            var conducted = Enumerable.Range(0, 10000)
                            .Select(i => new Screen {
                DisplayName = i.ToString(CultureInfo.InvariantCulture)
            });

            conductor.Items.AddRange(conducted);

            var defered1 = new DeferredCloseScreen {
                DisplayName = "d1", IsClosable = true
            };
            var defered2 = new DeferredCloseScreen {
                DisplayName = "d2", IsClosable = true
            };

            conductor.Items.Insert(0, defered1);
            conductor.Items.Insert(500, defered2);

            var finished = false;

            conductor.CanClose(canClose => {
                finished = true;
                Assert.True(canClose);
            });
            Assert.False(finished);

            defered1.TryClose();
            defered2.TryClose();
            Assert.True(finished);
        }
        [Fact] // See http://caliburnmicro.codeplex.com/discussions/430917
        public async Task TryCloseStressTest()
        {
            var conductor = new Conductor <IScreen> .Collection.OneActive();

            var conducted = Enumerable.Range(0, 10000)
                            .Select(i => new Screen {
                DisplayName = i.ToString(CultureInfo.InvariantCulture)
            });

            conductor.Items.AddRange(conducted);

            var defered1 = new DeferredCloseScreen {
                DisplayName = "d1", IsClosable = true
            };
            var defered2 = new DeferredCloseScreen {
                DisplayName = "d2", IsClosable = true
            };

            conductor.Items.Insert(0, defered1);
            conductor.Items.Insert(500, defered2);

            var actualCanClose = await conductor.CanClose();

            Assert.True(actualCanClose);

            await defered1.TryClose();

            await defered2.TryClose();
        }
 public void CanCloseIsTrueWhenItemsAreNotClosableAndCloseStrategyCloses() {
     var conductor = new Conductor<IScreen>.Collection.OneActive { CloseStrategy = new DefaultCloseStrategy<IScreen>(true) };
     var conducted = new StateScreen { IsClosable = true };
     conductor.Items.Add(conducted);
     ((IActivate)conductor).Activate();
     conductor.CanClose(Assert.True);
     Assert.True(conducted.IsClosed);
 }
 public void CanCloseIsTrueWhenItemsAreClosable() {
     var conductor = new Conductor<IScreen>.Collection.OneActive();
     var conducted = new StateScreen { IsClosable = true };
     conductor.Items.Add(conducted);
     ((IActivate)conductor).Activate();
     conductor.CanClose(Assert.True);
     Assert.False(conducted.IsClosed);
 }
        public void CanCloseIsTrueWhenItemsAreClosable()
        {
            var conductor = new Conductor <IScreen> .Collection.OneActive();

            var conducted = new StateScreen {
                IsClosable = true
            };

            conductor.Items.Add(conducted);
            ((IActivate)conductor).Activate();
            conductor.CanClose(Assert.True);
            Assert.False(conducted.IsClosed);
        }
        public void CanCloseIsTrueWhenItemsAreNotClosableAndCloseStrategyCloses()
        {
            var conductor = new Conductor <IScreen> .Collection.OneActive {
                CloseStrategy = new DefaultCloseStrategy <IScreen>(true)
            };
            var conducted = new StateScreen {
                IsClosable = true
            };

            conductor.Items.Add(conducted);
            ((IActivate)conductor).Activate();
            conductor.CanClose(Assert.True);
            Assert.True(conducted.IsClosed);
        }
        [Fact] // See http://caliburnmicro.codeplex.com/discussions/430917
        public void TryCloseStressTest()
        {
            var conductor = new Conductor<IScreen>.Collection.OneActive();
            var conducted = Enumerable.Range(0, 10000)
                .Select(i => new Screen {DisplayName = i.ToString(CultureInfo.InvariantCulture)});
            conductor.Items.AddRange(conducted);

            var defered1 = new DeferredCloseScreen {DisplayName = "d1", IsClosable = true};
            var defered2 = new DeferredCloseScreen {DisplayName = "d2", IsClosable = true};
            conductor.Items.Insert(0, defered1);
            conductor.Items.Insert(500, defered2);

            var finished = false;
            conductor.CanClose(canClose => {
                finished = true;
                Assert.True(canClose);
            });
            Assert.False(finished);

            defered1.TryClose();
            defered2.TryClose();
            Assert.True(finished);
        }
 public void can_shutdown_if_current_item_is_null()
 {
     ScreenConductor.CanClose(x => x.ShouldBeTrue());
 }