public async Task not_commiting_and_aborting_update_transaction_doesnt_modify_docs() { var guid = Guid.NewGuid().ToString(); var author1 = new Author { Name = "uwtrcd1", Surname = guid }; await author1.SaveAsync(); var author2 = new Author { Name = "uwtrcd2", Surname = guid }; await author2.SaveAsync(); var author3 = new Author { Name = "uwtrcd3", Surname = guid }; await author3.SaveAsync(); using (var TN = new Transaction()) { await TN.Update <Author>() .Match(a => a.Surname == guid) .Modify(a => a.Name, guid) .Modify(a => a.Surname, author1.Name) .ExecuteAsync(); await TN.AbortAsync(); //TN.CommitAsync(); } var res = await DB.Find <Author>().OneAsync(author1.ID); Assert.AreEqual(author1.Name, res.Name); }
/// <summary> /// Creates a replicator transaction and retries transient errors. /// </summary> /// <returns></returns> public static async Task SafeTerminateReplicatorTransactionAsync(Transaction replicatorTransaction, bool commit) { // Commit replicator transaction. while (true) { bool doneCompleteTx = false; try { if (commit) { await replicatorTransaction.CommitAsync(); } else { await replicatorTransaction.AbortAsync(); } doneCompleteTx = true; } catch (FabricTransientException) { // Retry. } catch (Exception e) { // Be done. throw e; } if (!doneCompleteTx) { // Sleep for a while. await Task.Delay(1000); } else { break; } } }
public async Task <(Role, User)> SeedDatabase() { using (var transaction = new Transaction()) { try { var username = "******"; var rolename = "Super Admin"; var role = await _roleService.GetByExpression(role => role.Name == rolename); var user = await _userService.GetByExpression(user => user.Username == username); if (role.IsEmpty() && user.IsEmpty()) { role = await _roleService.Add(new Role { Name = rolename, Description = "A superadmin user with all previledge" }); var newUser = new User { FullName = "Ariful Islam", Username = username, RoleRef = new One <Role> { ID = role.ID }, Password = "******", Email = "*****@*****.**", Remarks = "A superadmin user", Addresses = new List <UserAddress> { new UserAddress { Description = "Charshapmari, Shapmari", District = "Sherpur", Thana = "Sherpur", PostCode = "2100" } }, PhoneNumbers = new List <UserPhoneNumber> { new UserPhoneNumber { PhoneNo = "01793574440" } } }; user = await _userService.AddUser(newUser); await transaction.CommitAsync(); return(role, user); } else { await transaction.AbortAsync(); return(role, user); } } catch (Exception exception) { await transaction.AbortAsync(); throw exception; } } }