Пример #1
0
        public void DoSomething()
        {
            var repository  = new BankAccountRepository();
            var bankService = new BankAccountService(repository);

            var account1 = CreateAccount();
            var account2 = CreateAccount();
            var account3 = CreateAccount();
            var account4 = CreateAccount();

            account1.Deposite(1700);
            account2.Deposite(1700);
            account3.Deposite(1700);
            account4.Deposite(1700);

            bankService.Add(account1);
            bankService.Add(account2);
            bankService.Add(account3);
            bankService.Add(account4);
            Console.WriteLine(bankService);

            account1.Withdraw(150);
            account2.Status = Status.Close;
            bankService.Remove(account3);

            Console.WriteLine(bankService);
        }
        public void AddBankAccountAlreadyExistsExpectArgumentException()
        {
            IRepository <int, IBankAccount> repo = repoMock.Object;
            IBankAccountService             bankAccountService = new BankAccountService(repo);
            IBankAccount acc = new BankAccount {
                BankAccountId = 1
            };

            // act + assert
            bankAccountService.Add(acc);
            var ex = Assert.Throws <ArgumentException>(() => bankAccountService.Add(acc));

            Assert.Equal("This Bank account already exist in the repo", ex.Message);
        }
        public void AddTest()
        {
            IBankAccountRepository repo = new BankAccountRepository();

            BankAccountService newServi = new BankAccountService(repo);

            var getNewData = new BankAccount()
            {
                AccountNumber = "1233-22",
                BankCode      = 237,
                ClientName    = "Jão Teste",
                Cpf_Cnpj      = "105.369.147-10",
                AgencyNumber  = "1458-8",
                OpeningDate   = Convert.ToDateTime("02-02-2020"),
                Status        = "ativo"
            };

            newServi.Add(getNewData);
            //_bankRepository.SaveChanges();

            if (getNewData.Id == 0)
            {
                Assert.Fail("Não foi possivel inserir no banco de dados");
            }
            else
            {
                Assert.IsTrue(getNewData.Id != 0, "Inserido no banco!");
            }
        }
        public void AddBankAccountIsNullExpectArgumentException()
        {
            IRepository <int, IBankAccount> repo = repoMock.Object;
            IBankAccountService             bankAccountService = new BankAccountService(repo);

            // act + assert
            var ex = Assert.Throws <ArgumentException>(() => bankAccountService.Add(null));

            Assert.Equal("Bank account cannot be null", ex.Message);
        }
        public void GetAllTest()
        {
            IBankAccount acc = new BankAccount {
                BankAccountId = 1, Balance = 100
            };
            IBankAccount acc2 = new BankAccount {
                BankAccountId = 2, Balance = 110
            };

            IRepository <int, IBankAccount> repo = repoMock.Object;
            IBankAccountService             bankAccountService = new BankAccountService(repo);

            // act
            List <IBankAccount> excpectedList = new List <IBankAccount>();

            excpectedList.Add(acc);
            excpectedList.Add(acc2);
            bankAccountService.Add(acc);
            bankAccountService.Add(acc2);

            Assert.True(dataStore.Count == 2);
            Assert.Equal(excpectedList, bankAccountService.GetAll());
        }
        public void AddNonExistingBankAccount()
        {
            IBankAccount acc = new BankAccount {
                BankAccountId = 1
            };

            IRepository <int, IBankAccount> repo = repoMock.Object;
            IBankAccountService             bankAccountService = new BankAccountService(repo);

            // act
            bankAccountService.Add(acc);

            Assert.True(dataStore.Count == 1);
            Assert.Equal(acc, dataStore[1]);
        }
        public void GetByIdTest()
        {
            IBankAccount acc2 = new BankAccount {
                BankAccountId = 2, Balance = 110
            };

            IRepository <int, IBankAccount> repo = repoMock.Object;
            IBankAccountService             bankAccountService = new BankAccountService(repo);

            // act
            bankAccountService.Add(acc2);

            Assert.True(dataStore.Count == 2);
            Assert.Equal(acc2, bankAccountService.GetById(2));
        }
        public Result Add(BankAccountDetail BankAccountDetail)
        {
            var result = new Result();

            try
            {
                BankAccountService BankAccountDetailService = new BankAccountService();
                BankAccountDetailService.Add(BankAccountDetail);
                result.IsSuccess = true;
            }
            catch (Exception exception)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = exception;
            }
            return(result);
        }
Пример #9
0
        public void Should_Add()
        {
            var mockDependency = new Mock <IRepositoryBankAccount>();

            mockDependency.Setup(x => x.Add(It.IsAny <BankAccount>()))
            .Returns(1);

            var bankAccountService = new BankAccountService(mockDependency.Object,
                                                            new BankAccountValidate(mockDependency.Object));
            var bankAccount = bankAccountService.Add(
                new BankAccountBuilder().WithAgencyNumber("35552")
                .WithAgencyDigit("4")
                .WithAccountNumber("38852")
                .WithAccountDigit("1")
                .Builder());

            Assert.AreEqual(bankAccount.Id, 1);
        }
Пример #10
0
        public ActionResult Create(BankAccountViewModel bankAccountViewModel)
        {
            if (ModelState.IsValid)
            {
                var bankAccount = new BankAccount();
                bankAccount.Name           = bankAccountViewModel.Name;
                bankAccount.OpeningBalance = bankAccountViewModel.OpeningBalance.Value;
                bankAccount.ContextId      = GetCurrentContextId();
                bankAccount.CreationDate   = DateTime.Now;

                _bankAccountService.Add(bankAccount);

                return(RedirectToAction("Index"));
            }
            else
            {
                SendModelStateErrors();
                return(View(bankAccountViewModel));
            }
        }
Пример #11
0
        public void Dont_Should_Add_With_AgencyNumber_Empty()
        {
            var mockDependency = new Mock <IRepositoryBankAccount>();

            mockDependency.Setup(x => x.Add(It.IsAny <BankAccount>()))
            .Returns(1);

            var bankAccountService = new BankAccountService(mockDependency.Object,
                                                            new BankAccountValidate(mockDependency.Object));

            try
            {
                var bankAccount = bankAccountService.Add(
                    new BankAccountBuilder().WithAgencyDigit("4")
                    .WithAccountNumber("38852")
                    .WithAccountDigit("1")
                    .Builder());
                Assert.Fail();
            }catch (Exception ex)
            {
                Assert.AreEqual(ex.Message, "Número da agência é obrigátorio.");
            }
        }
Пример #12
0
        public void BankAccountServiceTest_Add_BankAccount_Succed(int id, string name, decimal balance, int bonusPoints, TypeBankAccount type)
        {
            Mock <ICalculatorBonusPoints> mockBonusPointsToWithfraw = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToWithfraw
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsWithdraw);

            Mock <ICalculatorBonusPoints> mockBonusPointsToDeposit = new Mock <ICalculatorBonusPoints>();

            mockBonusPointsToDeposit
            .Setup(m => m.GetBonusPoints(It.IsAny <BankAccount>(), It.IsAny <Decimal>()))
            .Returns <BankAccount, decimal>((bankAccount, amount) => bankAccount.BonusPointsDeposit);

            Mock <IBankAccountFactory> mockBankAccountFactory = new Mock <IBankAccountFactory>();

            mockBankAccountFactory
            .Setup(m => m.GetInstance(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <int>(), It.IsAny <TypeBankAccount>()))
            .Returns <int, string, decimal, int, TypeBankAccount>((idF, nameF, balanceF, bonus, typeF) => GetInstance(idF, nameF, balanceF, bonus, typeF, mockBonusPointsToWithfraw.Object, mockBonusPointsToDeposit.Object));

            BankAccountMapper          mapper = new BankAccountMapper(mockBankAccountFactory.Object);
            Mock <IBankAccountStorage> mockBankAccountStorage = new Mock <IBankAccountStorage>();

            mockBankAccountStorage
            .Setup(m => m.Load())
            .Returns(() =>
            {
                return(new List <AccountDTO>());
            });
            mockBankAccountStorage
            .Setup(m => m.Save(It.IsAny <IEnumerable <AccountDTO> >()));

            IBankAccountService service = new BankAccountService(mockBankAccountStorage.Object, mapper);

            service.Add(new BaseAccount(1, name, balance, bonusPoints));
            Assert.AreEqual(1, service.Count());
        }