コード例 #1
0
        public void ReplaceServiceListTest()
        {
            // Open a window with a control that has services attached.
            var window = new Window();
            var button = new Button();

            window.Content = button;

            UIServiceCollection serviceCollection = new UIServiceCollection();
            var serviceA = new TestServiceA();

            serviceCollection.Add(new ServiceFactoryMock(serviceA));
            UIServiceProvider.SetServiceList(button, serviceCollection);

            // Replace the assigned, yet unattached services.
            serviceCollection = new UIServiceCollection();
            var serviceA2 = new TestServiceA();

            serviceCollection.Add(new ServiceFactoryMock(serviceA2));
            UIServiceProvider.SetServiceList(button, serviceCollection);

            // Verify the old service was disposed.
            Assert.IsTrue(serviceA.IsDisposed);

            // Verify the old service does not become attached to the element.
            using (TestUtils.AutoCloseWindow(window))
            {
                Assert.IsFalse(serviceA.IsAttached);
                Assert.IsTrue(serviceA2.IsAttached);
            }

            Assert.IsTrue(serviceA2.IsDisposed);
        }
コード例 #2
0
        public static IDisposable Show(IList dataList, UIServiceCollection dgServiceList, out DataGrid dataGrid)
        {
            var w = new TestWindow();

            if (dgServiceList != null)
            {
                UIServiceProvider.SetServiceList(w.MainDataGrid, dgServiceList);
            }

            w.DataContext = new ListCollectionView(dataList);

            var result = TestUtils.AutoCloseWindow(w);

            dataGrid = w.MainDataGrid;
            return(result);
        }
コード例 #3
0
        public void SetServiceProviderTest()
        {
            // Open a window with a control without any service.
            Window window = new Window();
            Button button = new Button();

            window.Content = button;
            using (TestUtils.AutoCloseWindow(window))
            {
                var serviceList = UIServiceProvider_Accessor.GetServiceList(button);
                Assert.IsNotNull(serviceList);
                List <IUIServiceFactory> serviceListWrapper = new List <IUIServiceFactory>(serviceList);
                Assert.AreEqual(0, serviceListWrapper.Count);
                Assert.IsNull(UIServiceProvider_Accessor.GetServiceProvider(button));
                var service = UIServiceProvider.GetService(button, typeof(TestServiceBase));
                Assert.IsNull(service);
            }

            // Open a window with a control that has services attached.
            window         = new Window();
            button         = new Button();
            window.Content = button;

            UIServiceCollection serviceCollection = new UIServiceCollection();
            var serviceA = new TestServiceA();

            serviceCollection.Add(new ServiceFactoryMock(serviceA));
            UIServiceProvider.SetServiceList(button, serviceCollection);

            using (TestUtils.AutoCloseWindow(window))
            {
                Assert.IsNotNull(UIServiceProvider_Accessor.GetServiceList(button));
                Assert.IsNotNull(UIServiceProvider_Accessor.GetServiceProvider(button));
                var service = UIServiceProvider.GetService(button, typeof(TestServiceBase));
                Assert.IsInstanceOfType(service, typeof(TestServiceA));
                Assert.IsFalse(serviceA.IsDisposed);
            }

            Assert.IsTrue(serviceA.IsDisposed);
        }