Example #1
0
        private CompositionContainer CreateContainerAndShowView(bool registerUnitTesting)
        {
            var catalog = new AggregateCatalog();

            if (registerUnitTesting)
            {
                catalog.Catalogs.Add(new AssemblyCatalog(typeof(MockDialogView <>).Assembly));
            }
            catalog.Catalogs.Add(new TypeCatalog(typeof(TestMockDialogView)));

            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);

            container.Compose(new CompositionBatch());

            TestMockDialogView shownView = null;

            TestMockDialogView.ShowDialogAction = view =>
            {
                shownView = view;
            };

            var dialogView = container.GetExportedValue <TestMockDialogView>();

            Assert.IsNull(shownView);
            dialogView.ShowDialog(null);
            Assert.AreEqual(dialogView, shownView);

            return(container);
        }
Example #2
0
        public void AutomaticCleanupTestWithoutMef()
        {
            TestMockDialogView shownView = null;

            TestMockDialogView.ShowDialogAction = view =>
            {
                shownView = view;
            };

            var dialogView = new TestMockDialogView();

            Assert.IsNull(shownView);
            dialogView.ShowDialog(null);
            Assert.AreEqual(dialogView, shownView);

            Assert.IsNotNull(TestMockDialogView.ShowDialogAction);
            TestMockDialogView.ShowDialogAction = null;
        }
Example #3
0
        public void ShowAndCloseDialogView()
        {
            var owner          = new object();
            var mockDialogView = new TestMockDialogView();

            // Call ShowDialog without the ShowDialogAction
            mockDialogView.ShowDialog(owner);

            var showDialogCalled = false;

            TestMockDialogView.ShowDialogAction = view =>
            {
                Assert.AreEqual(owner, view.Owner);
                Assert.IsTrue(view.IsVisible);
                view.Close();
                showDialogCalled = true;
            };

            Assert.IsFalse(mockDialogView.IsVisible);
            mockDialogView.ShowDialog(owner);
            Assert.IsTrue(showDialogCalled);
            Assert.IsFalse(mockDialogView.IsVisible);
        }