Exemplo n.º 1
0
        public async Task ConcurrencyException()
        {
            var db = new EasyDb();

            db.SetConnectionStringSettings(@"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=MyDb;Integrated Security=True", DbConstants.SqlProviderName);

            db.AddInterceptor(new ConcurrencyInterceptor());

            db.SetTable <UserWithRowVersion>("User")
            .SetPrimaryKeyColumn("Id", p => p.Id)
            .SetColumn("Version", p => p.Version, true);

            var model = await db.SelectOneAsync <UserWithRowVersion>(Check.Op("Id", 2));

            model.UserName  += " updated";
            model.Version[4] = 2;

            bool failed = false;

            try
            {
                int result = await db.UpdateAsync <UserWithRowVersion>(model, Check.Op("Id", model.Id).And(Check.Op("Version", model.Version)));
            }
            catch (OptimisticConcurrencyException ex)
            {
                failed = true;
            }

            Assert.IsTrue(failed);
        }