public void WhenWebRequestEnds_BothAScopeEndsActionAndDisposableIntanceRegistered_InstancesGetDisposedLast()
        {
            // Arrange
            string expectedOrder = "[scope ending] [instance disposed]";

            string actualOrder = string.Empty;

            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            var container = new Container();

            var scope = new HttpContextScope();

            try
            {
                lifestyle.RegisterForDisposal(container,
                                              new DisposableAction(() => actualOrder += "[instance disposed]"));

                lifestyle.WhenScopeEnds(container, () => actualOrder += "[scope ending] ");
            }
            finally
            {
                // Act
                scope.Dispose();
            }

            // Assert
            Assert.AreEqual(expectedOrder, actualOrder,
                            "Instances should get disposed after all 'scope ends' actions are executed, since those " +
                            "delegates might still need to access those instances.");
        }
Ejemplo n.º 2
0
        public void WhenScopeEnds_OutsideTheContextOfAHttpRequest_ThrowsExpectedException()
        {
            // Arrange
            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            // Act
            Action action = () => lifestyle.WhenScopeEnds(new Container(), () => { });

            // Assert
            AssertThat.ThrowsWithExceptionMessageContains <InvalidOperationException>(
                "This method can only be called within the context of an active Web Request.", action);
        }
Ejemplo n.º 3
0
        public void WhenScopeEnds_WithValidArgumentsInHttpContext_Succeeds()
        {
            // Arrange
            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            var    validContainer = new Container();
            Action validAction    = () => { };

            using (new HttpContextScope())
            {
                // Act
                lifestyle.WhenScopeEnds(validContainer, validAction);
            }
        }
Ejemplo n.º 4
0
        public void WhenScopeEnds_WithNullAction_ThrowsExpectedException()
        {
            // Arrange
            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            Action invalidAction = null;

            using (new HttpContextScope())
            {
                // Act
                Action action = () => lifestyle.WhenScopeEnds(new Container(), invalidAction);

                // Assert
                AssertThat.ThrowsWithParamName <ArgumentNullException>("action", action);
            }
        }
        public void WhenWebRequestEnds_BothAScopeEndsActionAndDisposableIntanceRegistered_InstancesGetDisposedLast()
        {
            // Arrange
            string expectedOrder = "[scope ending] [instance disposed]";

            string actualOrder = string.Empty;

            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            var container = new Container();

            var scope = new HttpContextScope();

            try
            {
                lifestyle.RegisterForDisposal(container,
                    new DisposableAction(() => actualOrder += "[instance disposed]"));

                lifestyle.WhenScopeEnds(container, () => actualOrder += "[scope ending] ");
            }
            finally
            {
                // Act
                scope.Dispose();
            }

            // Assert
            Assert.AreEqual(expectedOrder, actualOrder,
                "Instances should get disposed after all 'scope ends' actions are executed, since those " +
                "delegates might still need to access those instances.");
        }
        public void WhenScopeEnds_OutsideTheContextOfAHttpRequest_ThrowsExpectedException()
        {
            // Arrange
            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            // Act
            Action action = () => lifestyle.WhenScopeEnds(new Container(), () => { });

            // Assert
            AssertThat.ThrowsWithExceptionMessageContains<InvalidOperationException>(
                "This method can only be called within the context of an active Web Request.", action);
        }
        public void WhenScopeEnds_WithNullAction_ThrowsExpectedException()
        {
            // Arrange
            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            Action invalidAction = null;
            
            using (new HttpContextScope())
            {
                // Act
                Action action = () => lifestyle.WhenScopeEnds(new Container(), invalidAction);

                // Assert
                AssertThat.ThrowsWithParamName<ArgumentNullException>("action", action);
            }
        }
        public void WhenScopeEnds_WithValidArgumentsInHttpContext_Succeeds()
        {
            // Arrange
            ScopedLifestyle lifestyle = new WebRequestLifestyle();

            var validContainer = new Container();
            Action validAction = () => { };

            using (new HttpContextScope())
            {
                // Act
                lifestyle.WhenScopeEnds(validContainer, validAction);
            }
        }