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);
        }
        public void GetAndAssignUnitOfWorkSuccessfully_WhenDependencyResolverSetupIsCorrect()
        {
            //Arrange
            var filterContextMock = new Mock <ActionExecutingContext>();
            var unitOfWorkMock    = new Mock <IEfUnitOfWork>();
            var filter            = new TransactionAttributeMock();

            var dependencyResolverMock = new Mock <IDependencyResolver>();

            dependencyResolverMock.Setup(dR => dR.GetService(typeof(IEfUnitOfWork))).Returns(unitOfWorkMock.Object);
            DependencyResolver.SetResolver(dependencyResolverMock.Object);

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

            //Assert
            dependencyResolverMock.Verify(dR => dR.GetService(typeof(IEfUnitOfWork)), Times.Once);
            Assert.AreSame(unitOfWorkMock.Object, filter.UnitOfWork);
        }