Ejemplo n.º 1
0
            public WhenCallingOnActionExecuted_WithAMicroLiteApiController_AndAutoManageTransactionIsFalse()
            {
                _mockTransaction.Setup(x => x.IsActive).Returns(true);
                _mockSession.Setup(x => x.CurrentTransaction).Returns(_mockTransaction.Object);

                MicroLiteApiController controller = new Mock <MicroLiteApiController>(_mockSession.Object).Object;

                var context = new HttpActionExecutedContext
                {
                    ActionContext = new HttpActionContext
                    {
                        ControllerContext = new HttpControllerContext
                        {
                            Controller = controller
                        }
                    }
                };

                var attribute = new AutoManageTransactionAttribute
                {
                    AutoManageTransaction = false
                };

                attribute.OnActionExecuted(context);
            }
Ejemplo n.º 2
0
            public WhenCallingOnActionExecuting_WithAMicroLiteReadOnlyController()
            {
                MicroLiteReadOnlyController controller = new Mock <MicroLiteReadOnlyController>(_mockSession.Object).Object;

                var context = new ActionExecutingContext
                {
                    Controller = controller
                };

                var attribute = new AutoManageTransactionAttribute();

                attribute.OnActionExecuting(context);
            }
Ejemplo n.º 3
0
            public void OnActionExecutedDoesNotThrowAnException()
            {
                MicroLiteReadOnlyController controller = new Mock <MicroLiteReadOnlyController>(_mockSession.Object).Object;

                var context = new ActionExecutedContext
                {
                    Controller = controller
                };

                var attribute = new AutoManageTransactionAttribute();

                attribute.OnActionExecuted(context);
            }
Ejemplo n.º 4
0
            public WhenCallingOnActionExecuting_WithAMicroLiteController_AndAutoManageTransactionIsFalse()
            {
                MicroLiteController controller = new Mock <MicroLiteController>(_mockSession.Object).Object;

                var context = new ActionExecutingContext
                {
                    Controller = controller
                };

                var attribute = new AutoManageTransactionAttribute
                {
                    AutoManageTransaction = false
                };

                attribute.OnActionExecuting(context);
            }
Ejemplo n.º 5
0
            public WhenCallingOnActionExecuted_WithAMicroLiteReadOnlyController_AndNoActiveTransaction()
            {
                _mockTransaction.Setup(x => x.IsActive).Returns(false);
                _mockSession.Setup(x => x.CurrentTransaction).Returns(_mockTransaction.Object);

                MicroLiteReadOnlyController controller = new Mock <MicroLiteReadOnlyController>(_mockSession.Object).Object;

                var context = new ActionExecutedContext
                {
                    Controller = controller
                };

                var attribute = new AutoManageTransactionAttribute();

                attribute.OnActionExecuted(context);
            }
Ejemplo n.º 6
0
            public WhenCallingOnActionExecuted_WithAMicroLiteReadOnlyController_AndTheContextContainsAnException_AndTheTransactionHasNotBeenRolledBack()
            {
                _mockTransaction.Setup(x => x.IsActive).Returns(true);
                _mockSession.Setup(x => x.CurrentTransaction).Returns(_mockTransaction.Object);

                MicroLiteReadOnlyController controller = new Mock <MicroLiteReadOnlyController>(_mockSession.Object).Object;

                var context = new ActionExecutedContext
                {
                    Controller = controller,
                    Exception  = new Exception()
                };

                var attribute = new AutoManageTransactionAttribute();

                attribute.OnActionExecuted(context);
            }
Ejemplo n.º 7
0
            public WhenCallingOnActionExecuted_WithAMicroLiteReadOnlyController_AndCommittingAnActiveTransactionThrowsAnException()
            {
                _mockTransaction.Setup(x => x.IsActive).Returns(true);
                _mockTransaction.Setup(x => x.Commit()).Throws <InvalidOperationException>();
                _mockSession.Setup(x => x.CurrentTransaction).Returns(_mockTransaction.Object);

                MicroLiteReadOnlyController controller = new Mock <MicroLiteReadOnlyController>(_mockSession.Object).Object;

                var context = new ActionExecutedContext
                {
                    Controller = controller
                };

                var attribute = new AutoManageTransactionAttribute();

                Assert.Throws <InvalidOperationException>(() => attribute.OnActionExecuted(context));
            }