Beispiel #1
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            var configuration = builder.Build();

            using (var db = new BDD_Demo_Lib.Data.BDD_Demo_Context(configuration.GetConnectionString("MyDb")))
            {
                //Todo use db
                var bankAccount = db.BankAccounts.FirstOrDefault();
                Console.WriteLine($"BankAccountId:{bankAccount.Id}, Balance:{bankAccount.Balance}, Name:{bankAccount.Name}");

                var logic = new BDD_Demo_Lib.BankAccountLogic(db);
                logic.Deposit(1, 80);

                Console.WriteLine($"Deposit 80 into Id 1");

                Console.WriteLine($"BankAccountId:{bankAccount.Id}, Balance:{bankAccount.Balance}, Name:{bankAccount.Name}");

                Console.WriteLine($"Withdraw 70 from Id 1");

                logic.Withdraw(1, 70);

                Console.WriteLine($"BankAccountId:{bankAccount.Id}, Balance:{bankAccount.Balance}, Name:{bankAccount.Name}");
            }
        }
        public void DepositShouldReturn100GivenId2And50Deposit()
        {
            // Arrange
            var logic = new BDD_Demo_Lib.BankAccountLogic(_context);

            // Act
            decimal balance = logic.Deposit(2, 50);

            // Assert
            balance.Should().Be(100);
        }
        public void WithdrawShouldReturnExceptionWhenBankAccountIdNotFound()
        {
            // Arrange
            var logic = new BDD_Demo_Lib.BankAccountLogic(_context);

            // Act
            Action act = () => logic.Withdraw(4, 100);

            // Assert
            act.Should().Throw <System.NullReferenceException>();
        }
        public void BalanceShouldReturn100WhenBankAccountIdIs1()
        {
            // Arrange
            var logic = new BDD_Demo_Lib.BankAccountLogic(_context);

            // Act
            decimal balance = logic.GetBalance(1);

            // Assert
            balance.Should().Be(100);
        }
        public void WithdrawShouldReturn20GivenId3And50Withdrawn()
        {
            // Arrange
            var logic = new BDD_Demo_Lib.BankAccountLogic(_context);

            // Act
            decimal balance = logic.Withdraw(3, 50);

            // Assert
            balance.Should().Be(20);
        }