Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public void TestBuilder_WithContainer_ObjectIsCreatedUsingBuilderProperties()
        {
            var container   = new SimpleContainer();
            var testService = new TestServiceA();

            container.Add <ITestServiceA>(testService);

            var builder = new Implementation.BuilderWithOneInterfaceProperty(container);

            var testObject = builder.Build();

            //Assert the builder properties
            Assert.Same(testService, builder.TestService); //use the object from container
            Assert.Equal(2, builder.Id);

            //Assert the object properties
            Assert.Equal(0, testObject.Number);
            Assert.Equal(DateTime.MinValue, testObject.Date);
            Assert.Same(builder.TestService, testObject.TestServiceA); //use the same object from container
            Assert.NotNull(testObject.TestObjectB);                    //create a new object
        }
Exemplo n.º 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);
        }