コード例 #1
0
        public void CannotDeleteAnUsedFlag()
        {
            var sqlException = new SqlExceptionBuilder().WithErrorNumber(SqlExceptions.SqlForeignKeyViolation).WithErrorMessage("Foreign key violation").Build();

            var mockRepo = new Mock <IFlagGateway>();

            mockRepo.Setup(s => s.Delete(1)).Throws(sqlException);

            var controller = new FeatureFlagController(mockRepo.Object);

            var result = (ObjectResult)controller.Delete(1);

            result.StatusCode.ShouldBeEquivalentTo(400);
        }
コード例 #2
0
        public void PreventDuplicates()
        {
            var sqlException = new SqlExceptionBuilder().WithErrorNumber(SqlExceptions.SqlDuplicateExceptionNumber).WithErrorMessage("Duplicates key").Build();

            var mockRepo = new Mock <IFlagGateway>();

            mockRepo.Setup(s => s.Save("test")).Throws(sqlException);

            var controller = new FeatureFlagController(mockRepo.Object);

            var result = (ObjectResult)controller.Post("test");

            result.StatusCode.ShouldBeEquivalentTo(400);
        }
コード例 #3
0
        public async void DeadLock_Async_Exception_Should_Be_Retried_Three()
        {
            int          counter = 0;
            SqlException ex      = new SqlExceptionBuilder().WithErrorNumber(BaseRepository.DEADLOCK_ERROR_NBR)
                                   .WithErrorMessage("Fake Deadlock")
                                   .Build();

            _asyncUnitOfWork.Setup(uow => uow.ExecuteAsync("deadlock", null, null)).Returns(async() =>
            {
                if (counter < 3)
                {
                    counter++;
                    throw ex;
                }

                return(counter);
            });

            int result = await _repo.ExecuteAsync("deadlock");

            result.Should().Be(3);
        }
コード例 #4
0
        public void Non_DeadLock_Sql_Error_Exception_Should_Not_Retry()
        {
            int          counter = 0;
            SqlException ex      = new SqlExceptionBuilder().WithErrorNumber(8675309)
                                   .WithErrorMessage("Fake Deadlock")
                                   .Build();

            _unitOfWork.Setup(uow => uow.Execute("deadlock", null)).Returns(() =>
            {
                // should fail before this, but preventing infinate loop
                if (counter < 10)
                {
                    counter++;
                    throw ex;
                }

                return(counter);
            });

            Assert.Throws <SqlException>(() => _repo.Execute("deadlock")).Number.Should().Be(8675309);
            counter.Should().Be(1);
        }
コード例 #5
0
        public void DeadLock_Exception_Should_Be_Stop_After_Three()
        {
            int          counter = 0;
            SqlException ex      = new SqlExceptionBuilder().WithErrorNumber(BaseRepository.DEADLOCK_ERROR_NBR)
                                   .WithErrorMessage("Fake Deadlock")
                                   .Build();

            _unitOfWork.Setup(uow => uow.Execute("deadlock", null)).Returns(() =>
            {
                // should fail before this, but preventing infinate loop
                if (counter < 10)
                {
                    counter++;
                    throw ex;
                }

                return(counter);
            });

            Assert.Throws <SqlException>(() => _repo.Execute("deadlock")).Number.Should().Be(BaseRepository.DEADLOCK_ERROR_NBR);
            counter.Should().Be(4);
        }
コード例 #6
0
        public void DeadLock_Exception_Should_Be_Retried_Once()
        {
            int          counter = 0;
            SqlException ex      = new SqlExceptionBuilder().WithErrorNumber(BaseRepository.DEADLOCK_ERROR_NBR)
                                   .WithErrorMessage("Fake Deadlock")
                                   .Build();

            _unitOfWork.Setup(uow => uow.Execute("deadlock", null)).Returns(() =>
            {
                if (counter == 0)
                {
                    counter++;
                    throw ex;
                }

                return(counter);
            });

            int result = _repo.Execute("deadlock");

            result.Should().Be(1);
        }