예제 #1
0
        public void clearing_a_container_disposes_all_its_registered_IDisposable_objects_and_remove_reentrancy_is_handled()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();
            DisposableThatReenterClearWhenDisposed disposableClass = new DisposableThatReenterClearWhenDisposed();

            disposableClass.ServiceContainer = container;
            container.Add(disposableClass, Util.ActionDispose);

            DisposableThatReenterClearWhenDisposed service = container.GetService <DisposableThatReenterClearWhenDisposed>();

            service.Should().NotBeNull();
            service.GetType().Should().Be(typeof(DisposableThatReenterClearWhenDisposed));

            container.Clear();

            container.GetService(typeof(DisposableThatReenterClearWhenDisposed)).Should().BeNull();
            container.GetService <DisposableThatReenterClearWhenDisposed>().Should().BeNull();
            container.Invoking(sut => sut.GetService <DisposableThatReenterClearWhenDisposed>(true)).Should().Throw <Exception>();
        }
예제 #2
0
        public void using_onRemove_action_reentrancy_of_remove_is_handled()
        {
            SimpleServiceContainer container = new SimpleServiceContainer();
            DisposableThatReenterClearWhenDisposed disposableClass = new DisposableThatReenterClearWhenDisposed();
            EmptyClass stupidObject = new EmptyClass();

            disposableClass.ServiceContainer = container;
            container.Add(disposableClass, Util.ActionDispose);
            container.Add(stupidObject, e => container.Clear());

            DisposableThatReenterClearWhenDisposed service = container.GetService <DisposableThatReenterClearWhenDisposed>();

            service.Should().BeOfType <DisposableThatReenterClearWhenDisposed>();

            container.Remove <EmptyClass>();

            container.GetService(typeof(DisposableThatReenterClearWhenDisposed)).Should().BeNull();
            container.GetService <DisposableThatReenterClearWhenDisposed>().Should().BeNull();
            container.Invoking(sut => sut.GetService <DisposableThatReenterClearWhenDisposed>(true)).Should().Throw <Exception>();
        }