public void TransferAmount(
            double initialAmount1,
            double initialAmount2,
            double transferAmount,
            double expectedAmount1,
            double expectedAmount2)
        {
            // arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create two bank accounts
            IBankAccount acc1 = new BankAccount(1, initialAmount1);
            IBankAccount acc2 = new BankAccount(2, initialAmount2);

            // and add them to the data store
            dataStore.Add(1, acc1);
            dataStore.Add(2, acc2);

            // act
            bam.TransferAmount(acc1.AccountNumber, acc2.AccountNumber, transferAmount);

            // assert
            dataStore.Should().HaveCount(2).And.ContainValues(acc1, acc2);
            dataStore[1].Should().Match <IBankAccount>((acc) => acc.Balance == expectedAmount1);
            dataStore[2].Should().Match <IBankAccount>((acc) => acc.Balance == expectedAmount2);
        }
        public void GetAllBankAccounts()
        {
            // arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create two bank accounts
            IBankAccount acc1 = new BankAccount(1);
            IBankAccount acc2 = new BankAccount(2);

            // add them both to the datastore
            dataStore.Add(1, acc1);
            dataStore.Add(2, acc2);

            // state of datastore before act
            dataStore.Should()
            .HaveCount(2)
            .And.ContainValues(acc1, acc2);

            // act
            List <IBankAccount> result = bam.GetAllBankAccounts();

            // assert
            result.Should().HaveCount(2).And.ContainInOrder(acc1, acc2);

            // datastore stays unchanged
            dataStore.Should()
            .HaveCount(2)
            .And.ContainValues(acc1, acc2);

            repoMock.Verify(repo => repo.GetAll(), Times.Once);
        }
        public void getBankAccountByIdNonExistingBankAccountExpectNull()
        {
            // arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create a bank account
            IBankAccount acc1 = new BankAccount(1);

            // and add it to the datastore
            dataStore.Add(1, acc1);

            // state before act
            dataStore.Should().HaveCount(1).And.Contain(new KeyValuePair <int, IBankAccount>(1, acc1));

            // act
            // look for non-existing account (accountNumber = 2)
            IBankAccount result = bam.GetBankAccountById(2);

            // assert
            result.Should().BeNull();

            // datastore stays unchanged
            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc1));

            repoMock.Verify(repo => repo.GetByID(It.Is <int>((id) => id == 2)), Times.Once);
        }
        public void RemoveBankAccountIsNullExpectArgumentException()
        {
            // Arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create a bank account
            IBankAccount acc1 = new BankAccount(1);

            // add acc1 to the datastore
            dataStore.Add(1, acc1);

            // state before act
            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc1));

            // act
            // try to remove null account
            Action ac = () => bam.RemoveBankAccount(null);

            // assert
            ac.Should().
            Throw <ArgumentException>()
            .WithMessage("No Bank account to remove (null)");

            // datastore must stay unchanged
            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc1));

            repoMock.Verify(repo => repo.Remove(It.IsAny <IBankAccount>()), Times.Never);
        }
        public void TransferAmountNegativeAmountExpectArgumentException()
        {
            // arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create two accounts
            IBankAccount acc1 = new BankAccount(1);
            IBankAccount acc2 = new BankAccount(2);

            // add to datastore
            dataStore.Add(1, acc1);
            dataStore.Add(2, acc2);

            // act
            Action ac = () => bam.TransferAmount(1, 2, -0.01);

            // assert

            /// throw ArgumentException
            ac.Should().Throw <ArgumentException>().WithMessage("Amount to transfer cannot be negative");

            // don't update the bankaccounts in the repo
            repoMock.Verify(repo => repo.Update(It.Is <IBankAccount>(acc => acc.AccountNumber == 1)), Times.Never);
            repoMock.Verify(repo => repo.Update(It.Is <IBankAccount>(acc => acc.AccountNumber == 2)), Times.Never);
        }
Example #6
0
            static bool Prefix(BankAccountManager __instance, Dictionary <string, BankAccount> ___personalAccounts, User user)
            {
                if (user == null || __instance.All.Any <BankAccount>(x => x.PersonalAccountName == user.Name))
                {
                    return(false);
                }

                if (___personalAccounts.ContainsKey(user.Name))
                {
                    return(false);
                }

                BankAccount bankAccount = __instance.BankAccounts.Add((INetObject)null) as BankAccount;

                bankAccount.Name = (string)__instance.PlayerAccountName(user.Name);
                bankAccount.PersonalAccountName = user.Name;
                bankAccount.SpecialAccount      = SpecialAccountType.Personal;
                bankAccount.DualPermissions.Managers.Add((Alias)user);
                Currency playerCurrency = Singleton <CurrencyManager> .Obj.GetPlayerCurrency(user.Name);

                bankAccount.CurrencyHoldings.Add(playerCurrency.Id, new CurrencyHolding()
                {
                    Currency = (CurrencyHandle)playerCurrency,
                    Val      = 0
                });

                ___personalAccounts[user.Name] = bankAccount;

                return(false); // prevent default method execution
            }
        public void RemoveExistingBankAccountWithPositiveBalanceExpectInvalidOperationException()
        {
            // Arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create bank account with positive balance
            IBankAccount acc = new BankAccount(1, 0.01);

            // and add it to the datastore
            dataStore.Add(acc.AccountNumber, acc);

            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc));

            // act
            Action ac = () => bam.RemoveBankAccount(acc);

            // assert
            ac.Should().
            Throw <InvalidOperationException>()
            .WithMessage("Bank account must be empty before removal");

            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc));

            repoMock.Verify(repo => repo.Remove(It.IsAny <IBankAccount>()), Times.Never);
        }
        public void RemoveNonExistingBankAccountExpectInvalidOperationException()
        {
            // Arrange
            BankAccountManager bam = new BankAccountManager(repoMock.Object);

            // create two bank accounts
            IBankAccount acc1 = new BankAccount(1);
            IBankAccount acc2 = new BankAccount(2);

            // add acc1 to the datastore
            dataStore.Add(1, acc1);

            // state before act
            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc1));

            // act
            // try to remove acc2
            Action ac = () => bam.RemoveBankAccount(acc2);

            // assert
            ac.Should().
            Throw <InvalidOperationException>()
            .WithMessage("Bank account does not exist");

            dataStore.Should()
            .HaveCount(1)
            .And.Contain(new KeyValuePair <int, IBankAccount>(1, acc1));

            repoMock.Verify(repo => repo.Remove(It.IsAny <IBankAccount>()), Times.Never);
        }
Example #9
0
        public ActionResult Edit(int id)
        {
            try
            {
                if (Session["UserName"] == null)
                {
                    return(RedirectToAction("Index", "Account"));
                }
                ViewBag.ReportTitle = "Edit Financial Account";

                var model = BankAccountManager.GetBankAccountByID(id);

                model.AllUser        = GetSelectListItems((short)Helpers.Helpers.ListType.allUser);
                model.AllAccountType = GetSelectListItems((short)Helpers.Helpers.ListType.allAccountType);
                model.AllCompany     = GetSelectListItems((short)Helpers.Helpers.ListType.company);
                model.AllStatus      = GetSelectListItems((short)Helpers.Helpers.ListType.allStatus);

                return(View(model));
            }
            catch (Exception ex)
            {
                LogException(ex.Message);
                return(View());
            }
        }
 // Test that repo is not null
 public void CreateInvalidBankAccountManagerExpectArgumentException()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         BankAccountManager bam = new BankAccountManager(null);
     });
 }
Example #11
0
        static void CreateBankAccount()
        {
            IBankDAO           bankDAO = new InMemoryBankDAO();
            BankAccountService service = new BankAccountService(bankDAO);
            BankAccountManager manager = new BankAccountManager(service);


            Console.Write("Enter UserId: ");
            var userId = Console.ReadLine();

            Console.Write("Enter Account Type: ");
            var accountType = int.Parse(Console.ReadLine());

            Console.Write("Enter balance: ");
            var balance = decimal.Parse(Console.ReadLine());

            var newBankAccount = new BankAccount()
            {
                AccountType = (BankAccountType)accountType,
                Owner       = new BankAppUser()
                {
                    EntityId = userId
                },
                Balance = balance
            };

            manager.CreateAccount(newBankAccount);
        }
Example #12
0
        public void NewVirementTest()
        {
            _stubIWasteBook.GetBalanceGuid = guid => 0;
            _bankAccountManager            = new BankAccountManager(_stubIBankAccounts, _stubIBankAccountDao, _stubIWasteBook, Guid.Empty);
            _bankAccountManager.NewVirement(Guid.NewGuid(), Guid.NewGuid(), 100, 2, "测试", "CS425154", Guid.NewGuid(), Guid.NewGuid(), "Lcr");

            var id = Guid.NewGuid();

            _stubIBankAccounts.GetBankAccountsGuid = guid => new BankAccountInfo();
            _bankAccountManager = new BankAccountManager(_stubIBankAccounts, _stubIBankAccountDao, _stubIWasteBook, Guid.Empty);
            _bankAccountManager.NewVirement(Guid.NewGuid(), Guid.NewGuid(), 100, 2, "测试", "CS425154", id, id, "Lcr");


            _stubIWasteBook.InsertWasteBookInfo = info =>
            {
                throw new Exception("测试");
            };
            _bankAccountManager = new BankAccountManager(_stubIBankAccounts, _stubIBankAccountDao, _stubIWasteBook, Guid.Empty);
            try
            {
                _bankAccountManager.NewVirement(Guid.NewGuid(), Guid.NewGuid(), 100, 2, "测试", "CS425154", id, id, "Lcr");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.Message == "转帐同步失败!");
            }
        }
 public void ObtenirSoldeFonctionne()
 {
     BankAccountManager manager = new BankAccountManager();
     double solde = manager.ObtenirSolde("BE68539007547034");
     //le solde de départ est défini dans le script de création de la base de données.
     Assert.AreEqual(54.75, solde);
 }
        public void LaisseBaseDeDonneesDansEtatCoherentSiErreurDeTransfert()
        {
            BankAccountManager manager = new BankAccountManager();

            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    manager.TransfererArgent("BE68539007547034", "CetIBANNexistePas", 123);
                    transaction.Complete();
                }
            }
            catch (BankAccountNotFoundException e)
            {
                using (StreamWriter outputFile = new StreamWriter(@"F:\Mes documents\ECOLE\BDD\BDD-Labo\Labo2\BankDAL.Tests\errLogs.txt"))
                {
                    outputFile.WriteLine(e.Message);
                }
            }
            double soldeApresOperation = manager.ObtenirSolde("BE68539007547034");

            //le solde après opération doit être celui de départ, car l'opération de transfert n'a pas pu se produire
            //étant donné que le compte de destination n'existe pas.
            //le solde de départ est défini dans le script de création de la base de données.
            Assert.AreEqual(54.75, soldeApresOperation);
        }
        // Test Creation of BankAccountManager with an empty repository
        public void CreateValidBankAccountManager()
        {
            IRepository <int, IBankAccount> repo = mockRepo.Object;
            BankAccountManager bam = new BankAccountManager(repo);

            Assert.Equal(0, repo.Count);
        }
Example #16
0
        public void ObtenirSoldeFonctionne()
        {
            BankAccountManager manager = new BankAccountManager();
            double             solde   = manager.ObtenirSolde(COMPTE_EXISTANT_1);

            //le solde de départ est défini dans le script de création de la base de données.
            Assert.AreEqual(54.75, solde);
        }
Example #17
0
        public void AvantChaqueTest()
        {
            BankAccountManager manager = new BankAccountManager();

            manager.SupprimerComptes();
            manager.CreerCompte(COMPTE_EXISTANT_1, 54.75);
            manager.CreerCompte(COMPTE_EXISTANT_2, 60.75);
        }
Example #18
0
        public void TransfertFonctionne()
        {
            BankAccountManager manager = new BankAccountManager();

            manager.TransfererArgent(COMPTE_EXISTANT_1, COMPTE_EXISTANT_2, 12);
            Assert.AreEqual(42.75, manager.ObtenirSolde(COMPTE_EXISTANT_1));
            Assert.AreEqual(72.75, manager.ObtenirSolde(COMPTE_EXISTANT_2));
        }
Example #19
0
 public static void ReinitialiserBaseDeDonnees()
 {
     using (SqlConnection conn = BankAccountManager.GetDatabaseConnection())
     {
         conn.Open();
         SqlCommand resetTableContentCommand = new SqlCommand(Resources.resettable, conn);
         resetTableContentCommand.ExecuteNonQuery();
         conn.Close();
     }
 }
Example #20
0
 private void OnTriggerStay2D(Collider2D otherCollider)
 {
     if (otherCollider.CompareTag("Player") && Input.GetKeyDown(KeyCode.E) && !inStore)
     {
         EnterStore();
         playerCol = otherCollider.GetComponent <PlayerController>();
         account   = otherCollider.GetComponent <BankAccountManager>();
         playerCol.DeactivatePlayerControls();
     }
 }
        public void CreateBankAccountManagerMissingRepositoryExpectArgumentException()
        {
            BankAccountManager bam = null;

            // act
            Action ac = () => bam = new BankAccountManager(null);

            // assert
            ac.Should().Throw <ArgumentException>().WithMessage("Missing BankAccount Repository");
            bam.Should().BeNull();
        }
Example #22
0
        public ActionResult Edit(BankAccount model)
        {
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }
            ViewBag.ReportTitle = "Edit Financial Account Record";

            BankAccountManager.Edit(model, model.CompanyID);
            return(RedirectToAction("Index"));
        }
        public void CreateBankAccountManager()
        {
            // arrange
            IRepository <int, IBankAccount> repo = repoMock.Object;

            // act
            BankAccountManager bam = new BankAccountManager(repo);

            // assert
            dataStore.Should().BeEmpty();
        }
Example #24
0
        public ActionResult Index()
        {
            // Enable security to redirect to login page if user is not logged in or we are not running in the VS IDE
            if (Session["UserName"] == null)
            {
                return(RedirectToAction("Index", "Account"));
            }

            List <BankAccount> att = BankAccountManager.GetAllBankAccounts(Helpers.Helpers.GetUserManagedCompanyString(Session["UserID"].ToString()));

            return(View(att));
        }
Example #25
0
 public void TestGetPermissionList()
 {
     try
     {
         _bankAccountManager = new BankAccountManager(_stubIBankAccounts, _stubIBankAccountDao, _stubIWasteBook, Guid.Empty);
         _bankAccountManager.GetPermissionList(Guid.Empty);
     }
     catch (Exception ex)
     {
         Assert.IsTrue(!string.IsNullOrEmpty(ex.Message));
     }
 }
        public void AvantChaqueTest()
        {
            BankAccountManager manager = new BankAccountManager();

            manager.SupprimerComptes();
            manager.CreerCompte("BE68539007547034", 54.75);
            manager.CreerCompte("BE987654321", 655);
            manager.CreerCompte("BE666555777888", 776);
            if (File.Exists("Log"))
            {
                File.Delete("Log");
            }
        }
 public void LaisseBaseDeDonneesDansEtatCoherentSiErreurDeTransfert()
 {
     BankAccountManager manager = new BankAccountManager();
     try
     {
         manager.TransfererArgent("BE68539007547034", "CetIBANNexistePas", 123);
     }
     catch { }
     double soldeApresOperation = manager.ObtenirSolde("BE68539007547034");
     //le solde après opération doit être celui de départ, car l'opération de transfert n'a pas pu se produire
     //étant donné que le compte de destination n'existe pas.
     //le solde de départ est défini dans le script de création de la base de données.
     Assert.AreEqual(54.75, soldeApresOperation);
 }
        // Test adding a null value to the repository.
        public void AddInvalidBankAccountExpectArgumentException()
        {
            IRepository <int, IBankAccount> repo = mockRepo.Object;

            IBankAccount       acc = null;
            BankAccountManager bam = new BankAccountManager(repo);

            Assert.Throws <ArgumentException>(() =>
            {
                bam.AddBankAccount(acc);
            });

            Assert.Equal(0, repo.Count);
        }
Example #29
0
    public void ExitStore()
    {
        inStore = false;
        HideMenu();
        if (playerCol != null)
        {
            playerCol.ActivatePlayerControls();
            playerCol = null;
        }

        if (account != null)
        {
            account = null;
        }
    }
        public void AddBankAccountIsNullExpectArgumentException()
        {
            IRepository <int, IBankAccount> repo = repoMock.Object;
            BankAccountManager bam = new BankAccountManager(repo);

            dataStore.Should().BeEmpty();

            // act
            Action ac = () => bam.AddBankAccount(null);

            // assert
            ac.Should().Throw <ArgumentException>().WithMessage("Bank account cannot be null");
            dataStore.Should().BeEmpty();
            repoMock.Verify(repo => repo.Add(It.IsAny <IBankAccount>()), Times.Never);
        }
Example #31
0
        public IActionResult CreateBankAccount(BankAccount bankAccount)
        {
            BankAccountService service = new BankAccountService(_bankDAO);
            BankAccountManager manager = new BankAccountManager(service);


            var createResult = manager.CreateAccount(bankAccount);

            if (createResult)
            {
                return(Ok());
            }

            return(new StatusCodeResult(StatusCodes.Status500InternalServerError));
        }
        // Test get a non-existing bank account by id.
        // A null value should be returned.
        public void GetBankAccountByIdNonExistingBankAccountExpectNull()
        {
            IRepository <int, IBankAccount> repo = mockRepo.Object;

            IBankAccount acc1 = new BankAccount(1);
            IBankAccount acc2 = new BankAccount(2);

            BankAccountManager bam = new BankAccountManager(repo);

            bam.AddBankAccount(acc1);

            IBankAccount result = bam.GetBankAccountById(acc2.AccountNumber);

            Assert.Null(result);
        }
 public void LeveExceptionSiCompteEnBanqueDestinationInexistant()
 {
     BankAccountManager manager = new BankAccountManager();
     manager.TransfererArgent("BE68539007547034", "CetIBANNexistePas", 123);
 }