示例#1
0
        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();
                }
            }
        }
示例#2
0
        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();
                }
            }
        }
示例#3
0
        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();
                }
            }
        }
示例#4
0
        /// <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));
            }
        }
示例#5
0
        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);
        }
示例#6
0
        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();
                };
            }
        }
示例#7
0
 private void BeginTransaction()
 {
     UoW.BeginTransaction();
     juridicoUoW.BeginTransaction();
 }