コード例 #1
0
        public void FailToComposeWithUnknownDependancy()
        {
            var container = new ComponentContainer();

            // throwOnUnknown defaults to true so this should fail.
            Assert.Throws <ArgumentException>(
                () => container.Compose <TestComponentWithADependancy>());

            Assert.Throws <ArgumentException>(
                () => container.Compose <TestComponentWithADependancy>(throwOnUnknown: true));
        }
コード例 #2
0
        public void Disposed()
        {
            var container = new ComponentContainer();

            container.Register <ITestComponent>().To <TestComponent>();

            container.Dispose();
            container.Dispose(); // Get that one extra return if you dispose twice...

            Assert.Throws <ObjectDisposedException>(() => container.Compose <ITestComponent>());
            Assert.Throws <ObjectDisposedException>(() => container.Compose(typeof(ITestComponent)));
            Assert.Throws <ObjectDisposedException>(() => container.Register <ITestComponent>().To <TestComponent>());
            Assert.Throws <ObjectDisposedException>(() => container.Unregister <ITestComponent>());
            Assert.Throws <ObjectDisposedException>(() => container.ReplaceRegisteredComponent <ITestComponent>(null));
            Assert.Throws <ObjectDisposedException>(() => container.GetRegisteredComponent <ITestComponent>());
        }
コード例 #3
0
        public void ComposeWithUnknownDependancy()
        {
            var container = new ComponentContainer();
            var component = container.Compose <TestComponentWithADependancy>(
                throwOnUnknown: false);

            Assert.IsType <TestComponentWithADependancy>(component);
        }