test/Shared/FunctionalTests/ProductivityApi/ConcurrencyTests.cs
/// <summary>
///     Runs the two actions inside a transaction scope but with two different contexts and calling
///     SaveChanges such that storeChange will succeed and the store will reflect this change, and
///     then clientChange will result in a concurrency exception.
///     After the exception is caught the resolver action is called, after which SaveChanges is called
///     again.  Finally, a new context is created and the validator is called so that the state of
///     the database at the end of the process can be validated.
/// </summary>
Runs the two actions inside a transaction scope but with two different contexts and calling
SaveChanges such that storeChange will succeed and the store will reflect this change, and
then clientChange will result in a concurrency exception.
After the exception is caught the resolver action is called, after which SaveChanges is called
again.  Finally, a new context is created and the validator is called so that the state of
the database at the end of the process can be validated.
Runs the two actions inside a transaction scope but with two different contexts and calling SaveChanges such that storeChange will succeed and the store will reflect this change and then clientChange will result in a concurrency exception . After the exception is caught the resolver action is called after which SaveChanges is called again . Finally a new context is created and the validator is called so that the state of the database at the end of the process can be validated .
private void ConcurrencyTest(
            Action<F1Context> storeChange, Action<F1Context> clientChange,
            Action<F1Context, DbUpdateException> resolver, Action<F1Context> validator)
        {
            ExtendedSqlAzureExecutionStrategy.ExecuteNew(
                () =>
                {
                    using (new TransactionScope())
                    {
                        using (var context = new F1Context())
                        {
                            clientChange(context);
                            using (var innerContext = new F1Context())
                            {
                                storeChange(innerContext);
                                innerContext.SaveChanges();
                            }
                            try
                            {
                                context.SaveChanges();
                                Assert.True(false);
                            }
                            catch (DbUpdateException ex)
                            {
                                Assert.IsAssignableFrom<UpdateException>(ex.InnerException);
                                resolver(context, ex);
                                if (validator != null)
                                {
                                    context.SaveChanges();
                                    using (var validationContext = new F1Context())
                                    {
                                        validator(validationContext);
                                    }
                                }
                            }
                        }
                    }
                });
        }
private void ConcurrencyTest ( Action < F1Context > storeChange , Action < F1Context > clientChange , Action < F1Context , DbUpdateException > resolver , Action < F1Context > validator ) { ExtendedSqlAzureExecutionStrategy . ExecuteNew ( ( ) => { using ( new TransactionScope ( ) ) { using ( var context = new F1Context ( ) ) { clientChange ( context ) ; using ( var innerContext = new F1Context ( ) ) { storeChange ( innerContext ) ; innerContext . SaveChanges ( ) ; } try { context . SaveChanges ( ) ; Assert . True ( false ) ; } catch ( DbUpdateException ex ) { Assert . IsAssignableFrom < UpdateException > ( ex . InnerException ) ; resolver ( context , ex ) ; if ( validator != null ) { context . SaveChanges ( ) ; using ( var validationContext = new F1Context ( ) ) { validator ( validationContext ) ; } } } } } } ) ; }
Runs the two actions inside a transaction scope but with two different contexts and calling
SaveChanges such that storeChange will succeed and the store will reflect this change, and
then clientChange will result in a concurrency exception.
Runs the two actions inside a transaction scope but with two different contexts and calling SaveChanges such that storeChange will succeed and the store will reflect this change and then clientChange will result in a concurrency exception .
storeChange
Action<F1Context>
clientChange
Action<F1Context>
resolver
Action<F1Context, DbUpdateException>
validator
Action<F1Context>