Ejemplo n.º 1
0
        public void TransientServiceIsNotDisposedWithContainer(
            [ValueSource(nameof(ServiceRegistrationTypes))] TestRegistrationType registration)
        {
            var container = new Container(r => registration.Invoke(r));
            var _         = container.Resolve <IService>(out var disposableSpy);

            container.Dispose();

            Assert.That(disposableSpy, Has.Property(nameof(DisposableSpy.IsDisposed)).False);
        }
Ejemplo n.º 2
0
        public void TransientServiceIsDisposedOnlyOnce(
            [ValueSource(nameof(ServiceRegistrationTypes))] TestRegistrationType registration)
        {
            var container          = new Container(r => registration.Invoke(r));
            var transientLifeScope = container.Resolve <IService>(out var disposableSpy);

            transientLifeScope.Dispose();
            transientLifeScope.Dispose();

            Assert.That(disposableSpy, Has.Property(nameof(DisposableSpy.DisposeCount)).EqualTo(1));
        }
Ejemplo n.º 3
0
        public void SingletonServiceIsNotDisposedWithTransientLifeScope(
            [ValueSource(nameof(ServiceRegistrationTypes))] TestRegistrationType registration)
        {
            var container          = new Container(r => registration.Invoke(r).AsSingleton());
            var transientLifeScope = container.Resolve <IService>(out _);

            transientLifeScope.Dispose();

            container.Resolve <IService>(out var disposableSpy);

            Assert.That(disposableSpy, Has.Property(nameof(DisposableSpy.IsDisposed)).False);
        }
Ejemplo n.º 4
0
        public void TransientDependencyIsDisposedWithTransientLifeScope(
            [ValueSource(nameof(DependentServiceRegistrationTypes))] TestRegistrationType dependentServiceRegistration,
            [ValueSource(nameof(DependencyRegistrationTypes))] TestRegistrationType dependencyRegistration)
        {
            var container = new Container(r =>
            {
                dependencyRegistration.Invoke(r);
                dependentServiceRegistration.Invoke(r);
            });
            var transientLifeScope = container.Resolve <IDependencySpyService>(out var dependencySpy);
            var disposableSpy      = dependencySpy.ActualDependency;

            transientLifeScope.Dispose();

            Assert.That(disposableSpy, Has.Property(nameof(DisposableSpy.IsDisposed)).True);
        }
Ejemplo n.º 5
0
        public void SingletonDependencyIsDisposedAfterItsConsumer(
            [ValueSource(nameof(SingletonRegistrationTypes))] TestDependencyLifeStyleRegistration singletonRegistration,
            [ValueSource(nameof(DisposableConsumerRegistrationTypes))] TestRegistrationType consumerRegistration,
            [ValueSource(nameof(DependencyRegistrationTypes))] TestRegistrationType dependencyRegistration)
        {
            var container = new Container(r => singletonRegistration.Invoke(
                                              () => dependencyRegistration.Invoke(r),
                                              () => consumerRegistration.Invoke(r)));
            var transientLifeScope = container.Resolve <IDependencySpyService>(out var disposalOrderSpy);

            _ = disposalOrderSpy.ActualDependency;

            transientLifeScope.Dispose();
            container.Dispose();

            Assert.That(disposalOrderSpy, Has.Property(nameof(DisposalOrderSpy.WasDependencyDisposedBeforeThis)).False);
        }
Ejemplo n.º 6
0
        public void SingletonDependencyIsNotDisposedWithTransientLifeScope(
            [ValueSource(nameof(SingletonRegistrationTypes))] TestDependencyLifeStyleRegistration singletonRegistration,
            [ValueSource(nameof(DependentServiceRegistrationTypes))] TestRegistrationType dependentServiceRegistration,
            [ValueSource(nameof(DependencyRegistrationTypes))] TestRegistrationType dependencyRegistration)
        {
            var container = new Container(r => singletonRegistration.Invoke(
                                              () => dependencyRegistration.Invoke(r),
                                              () => dependentServiceRegistration.Invoke(r)));
            var transientLifeScope = container.Resolve <IDependencySpyService>(out _);

            transientLifeScope.Dispose();

            container.Resolve <IDependencySpyService>(out var dependencySpy);
            var disposableSpy = dependencySpy.ActualDependency;

            Assert.That(disposableSpy, Has.Property(nameof(DisposableSpy.IsDisposed)).False);
        }