Exemple #1
0
        public void WhenCurrentRequestEnds_OutsideTheContextOfAHttpRequest_ThrowsExpectedException()
        {
            // Act
            Action action = () => WebRequestLifestyle.WhenCurrentRequestEnds(new Container(), () => { });

            // Assert
            AssertThat.ThrowsWithExceptionMessageContains <InvalidOperationException>(
                "This method can only be called within the context of an active Web Request.", action);
        }
Exemple #2
0
        public void WhenCurrentRequestEnds_WithValidArgumentsInHttpContext_Succeeds()
        {
            // Arrange
            var    validContainer = new Container();
            Action validAction    = () => { };

            using (new HttpContextScope())
            {
                // Act
                WebRequestLifestyle.WhenCurrentRequestEnds(validContainer, validAction);
            }
        }
Exemple #3
0
        public void WhenCurrentRequestEnds_WithNullAction_ThrowsExpectedException()
        {
            // Arrange
            Action invalidAction = null;

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

                // Assert
                AssertThat.ThrowsWithParamName <ArgumentNullException>("action", action);
            }
        }
Exemple #4
0
        public void WhenCurrentRequestEnds_WithNullContainer_ThrowsExpectedException()
        {
            // Arrange
            Container invalidContainer = null;

            using (new HttpContextScope())
            {
                // Act
                Action action = () => WebRequestLifestyle.WhenCurrentRequestEnds(invalidContainer, () => { });

                // Assert
                AssertThat.ThrowsWithParamName <ArgumentNullException>("container", action);
            }
        }
Exemple #5
0
        public void Verify_WhenCurrentRequestEndsCalledDuringVerificationOutsideAnHttpContext_Succeeds()
        {
            // Arrange
            bool initializerCalled = false;

            var container = new Container();

            container.Register <DisposableCommand>();

            container.RegisterInitializer <DisposableCommand>(command =>
            {
                WebRequestLifestyle.WhenCurrentRequestEnds(container, () => command.Dispose());
                initializerCalled = true;
            });

            // Act
            container.Verify(VerificationOption.VerifyOnly);

            // Arrange
            Assert.IsTrue(initializerCalled);
        }