public void ReturnsLifetimeManager()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            Assert.NotNull(lifetimeManager);
        }
        public async void Deactivate_WithoutRegistration_Returns()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            await lifetimeManagerSource.Deactivate();
        }
        public void ReturnsSameLifetimeManagerWithMultipleCalls()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();

            var lifetimeManager1 = lifetimeManagerSource.LifetimeManager;
            var lifetimeManager2 = lifetimeManagerSource.LifetimeManager;

            Assert.Equal(lifetimeManager1, lifetimeManager2);
        }
        public void UnregisterService_ThrowsException_IfServiceIsNull()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            var e = Assert.Throws <ArgumentNullException>(() => lifetimeManager.Unregister(null));

            Assert.Equal("service", e.ParamName);
        }
        public void RegisterService_ThrowsException_IfServiceIsRegisteredMultipleTimes()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            var service = new MockLifetimeAwareService();

            lifetimeManager.Register(service);
            var e = Assert.Throws <InvalidOperationException>(() => lifetimeManager.Register(service));

            Assert.Equal("You cannot register a service multiple times.", e.Message);
        }
        public void UnregisterService_ThrowsException_IfServiceIsNotRegistered()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            var service1 = new MockLifetimeAwareService();
            var service2 = new MockLifetimeAwareService();

            lifetimeManager.Register(service1);
            var e = Assert.Throws <InvalidOperationException>(() => lifetimeManager.Unregister(service2));

            Assert.Equal("Cannot unregister the service as it is not currently registered.", e.Message);
        }
        public async void Deactivate_WithSingleService_DeactivatesService()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            var service1 = new MockLifetimeAwareService();

            lifetimeManager.Register(service1);

            await lifetimeManagerSource.Deactivate();

            Assert.Equal(0, service1.ActivateCount);
            Assert.Equal(1, service1.DeactivateCount);
        }
        public async void Dectivate_UnregisteredService_DoesNotDectivate()
        {
            var lifetimeManagerSource = new LifetimeManagerSource();
            var lifetimeManager       = lifetimeManagerSource.LifetimeManager;

            var service1 = new MockLifetimeAwareService();

            lifetimeManager.Register(service1);
            lifetimeManager.Unregister(service1);

            await lifetimeManagerSource.Deactivate();

            Assert.Equal(0, service1.ActivateCount);
            Assert.Equal(0, service1.DeactivateCount);
        }