public void GivenNewAccount_WhenInsert_ThenReturnNotNull() { var uow = new UoW(_chatContext); using (var dbContextTransaction = uow.BeginTransaction()) { try { //ARRANGE Account account = new Account(); account.UserName = "******"; account.Password = "******"; _sendEmailStub.Stub(se => se.Send("", "", "")).IgnoreArguments().Return(true); //ACT var newaccount = _sut.AddAccount(account, null); //ASSERT var insertedAccount = _accountRepository.Get(account.AccountID); Assert.NotNull(insertedAccount); Assert.Equal(insertedAccount.Password, newaccount.Password); } finally { dbContextTransaction.Rollback(); } } }
public void GivenAccount_WhenUpdate_ThenReturnUpdated() { var uow = new UoW(_chatContext); using (var dbContextTransaction = uow.BeginTransaction()) { try { //ARRANGE string newPassword = "******"; Account account = AccountMother.NewAccount(); _accountRepository.Add(account); uow.SaveChanges(); //ACT var attachedAccount = _accountRepository.Get(account.AccountID); attachedAccount.Password = newPassword; uow.SaveChanges(); //ASSERT var updatedAccount = _accountRepository.Get(account.AccountID); Assert.NotNull(updatedAccount); Assert.Equal(updatedAccount.Password, newPassword); } finally { dbContextTransaction.Rollback(); } } }
public void GivenNewAccount_WhenInsert_ThenReturnNotNull() { var uow = new UoW(_chatContext); using (var dbContextTransaction = uow.BeginTransaction()) { try { //ARRANGE Account account = AccountMother.NewAccount(); _accountRepository.Add(account); //ACT uow.SaveChanges(); //ASSERT var insertedAccount = _accountRepository.Get(account.AccountID); Assert.NotNull(insertedAccount); Assert.Equal(insertedAccount.Password, account.Password); } finally { dbContextTransaction.Rollback(); } } }
/// <summary> /// Handles the Click event of the Delete Button control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event /// data.</param> protected void DeleteBtn_Click(object sender, System.EventArgs e) { try { UoW.BeginTransaction(); TopicBo.Delete(this.CurrentTopic); UoW.CommitTransaction(); Response.Redirect(this.HomeURL, false); } catch (System.Exception exc) { UoW.RollbackTransaction(); Exceptions.LogException(exc); this.Messages.ShowError(Localization.GetString("ErrorDeletingTopic", this.LocalResourceFile)); } }
public Account AddAccount(Account account, string email) { //todo Add businnes logic for new account var uow = new UoW(_chatContext); using (var dbContextTransaction = uow.BeginTransaction()) { try { _accountRepository.Add(account); uow.SaveChanges(); _sendEmail.Send("from", email, "message"); _logData.LogThis(DateTime.Now + " insert " + account.AccountID); dbContextTransaction.Commit(); } catch (Exception ex) { //todo some logs dbContextTransaction.Rollback(); throw; } } return(account); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.AddProduto); EditText txtDescricao = FindViewById <EditText>(Resource.Id.txtDescricaoProduto); Button btnSalvar = FindViewById <Button>(Resource.Id.btnSalvar); btnSalvar.Click += delegate { if (!string.IsNullOrEmpty(txtDescricao.Text)) { _uow.BeginTransaction(); try { Produto produto = new Produto { Descricao = txtDescricao.Text }; if (ProdutoSelecionado == null) { _uow.ProdutoRepository.Add(produto); } else { ProdutoSelecionado.Descricao = txtDescricao.Text; _uow.ProdutoRepository.Update(ProdutoSelecionado); } _uow.CommitTransaction(); Finish(); } catch (Exception ex) { _uow.RollBackTransaction(); } } }; if (Intent.GetStringExtra("PRODUTO_EDIT") != null) { ProdutoSelecionado = JsonConvert.DeserializeObject <Produto>(Intent.GetStringExtra("PRODUTO_EDIT")); txtDescricao.Text = ProdutoSelecionado.Descricao; Button btnRemover = FindViewById <Button>(Resource.Id.btnRemover); btnRemover.Visibility = ViewStates.Visible; btnRemover.Click += delegate { _uow.BeginTransaction(); _uow.ProdutoRepository.RemoveByPredicate(x => x.Id == ProdutoSelecionado.Id); _uow.CommitTransaction(); Finish(); }; } }
private void BeginTransaction() { UoW.BeginTransaction(); juridicoUoW.BeginTransaction(); }