Exemple #1
0
        public void CallUnitOfWorkSaveChangesOnce_WhenNoExceptionInContext()
        {
            //Arrange
            var filterContextMock = new Mock <ActionExecutedContext>();
            var unitOfWorkMock    = new Mock <IEfUnitOfWork>();
            var filter            = new TransactionAttributeMock();

            filter.UnitOfWork = unitOfWorkMock.Object;

            //Act
            filter.OnActionExecuted(filterContextMock.Object);

            //Assert
            unitOfWorkMock.Verify(u => u.SaveChanges(), Times.Once);
        }
Exemple #2
0
        public void NotCallUnitOfWorkSaveChanges_WhenExceptionInContext()
        {
            //Arrange
            var filterContextMock = new Mock <ActionExecutedContext>();

            filterContextMock.Setup(f => f.Exception).Returns(new Exception());
            var unitOfWorkMock = new Mock <IEfUnitOfWork>();
            var filter         = new TransactionAttributeMock();

            filter.UnitOfWork = unitOfWorkMock.Object;

            //Act
            filter.OnActionExecuted(filterContextMock.Object);

            //Assert
            unitOfWorkMock.Verify(u => u.SaveChanges(), Times.Never);
        }