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); }
public void OnActionExecutedDoesNotThrowAnException() { MicroLiteReadOnlyController controller = new Mock <MicroLiteReadOnlyController>(_mockSession.Object).Object; var context = new ActionExecutedContext { Controller = controller }; var attribute = new AutoManageTransactionAttribute(); attribute.OnActionExecuted(context); }
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); }
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); }
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)); }