Beispiel #1
0
        private void Execute_retries_until_succesful(Action<DbExecutionStrategy, Func<int>> execute)
        {
            var executionStrategy = new SqlAzureExecutionStrategy();
            var executionCount = 0;

            execute(
                executionStrategy, () =>
                                       {
                                           if (executionCount++ < 3)
                                           {
                                               throw new TimeoutException();
                                           }

                                           return executionCount;
                                       });

            Assert.Equal(4, executionCount);
        }
        private void Execute_retries_until_successful(Action <DbExecutionStrategy, Func <int> > execute)
        {
            var executionStrategy = new SqlAzureExecutionStrategy();
            var executionCount    = 0;

            execute(
                executionStrategy, () =>
            {
                if (executionCount++ < 3)
                {
                    throw new TimeoutException();
                }

                return(executionCount);
            });

            Assert.Equal(4, executionCount);
        }
Beispiel #3
0
        private void ExecuteAsync_retries_until_succesful(Func<DbExecutionStrategy, Func<Task<int>>, Task> executeAsync)
        {
            var executionStrategy = new SqlAzureExecutionStrategy();

            var executionCount = 0;

            executeAsync(
                executionStrategy, () =>
                                       {
                                           if (executionCount++ < 3)
                                           {
                                               throw new TimeoutException();
                                           }

                                           return Task.FromResult(executionCount);
                                       }).Wait();

            Assert.Equal(4, executionCount);
        }
        private void ExecuteAsync_retries_until_successful(Func <DbExecutionStrategy, Func <Task <int> >, Task> executeAsync)
        {
            var executionStrategy = new SqlAzureExecutionStrategy();

            var executionCount = 0;

            executeAsync(
                executionStrategy, () =>
            {
                if (executionCount++ < 3)
                {
                    throw new TimeoutException();
                }

                return(Task.FromResult(executionCount));
            }).Wait();

            Assert.Equal(4, executionCount);
        }
        public void CheckIfExplicityTransactionsWorks_ShouldNotRollback()
        {
            InitializeSchema();
            var executionStrategy = new SqlAzureExecutionStrategy();

            executionStrategy.Execute(() => {
                using (var context = new GenericDbContext(ConnectionString)) {
                    using (var transaction = context.Database.BeginTransaction()) {

                        context.Database.ExecuteSqlCommand(EmployeeInsert);
                        context.SaveChanges();
                        transaction.Commit();
                    }
                }
            });

            using (var context = new GenericDbContext(ConnectionString)) {
                Assert.IsTrue(context.Set<Employee>().Any());
            }
        }
        public SqlDbConfiguration(string strategyTypeName)
        {
            IDbExecutionStrategy strategyObj;

            if (strategyTypeName == SqlAzureExecutionStrategy)
            {
                strategyObj = new SqlAzureExecutionStrategy();
            }
            else
            {
                var strategyType = Type.GetType(strategyTypeName);
                strategyObj = (IDbExecutionStrategy)Activator.CreateInstance(strategyType);
            }

            SetExecutionStrategy("System.Data.SqlClient", 
                () => SuspendExecutionStrategy
                        ? (IDbExecutionStrategy)new DefaultExecutionStrategy()
                        : strategyObj);
        }