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 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.");
        }