예제 #1
0
        public void CreateUserAndRead()
        {
            var options = new DbContextOptionsBuilder <BankingAppDbContext>()
                          .UseInMemoryDatabase(databaseName: "BankingAppTest")
                          .Options;

            using (var context = new BankingAppDbContext(options))
            {
                var service = new UsersService(context);
                service.CreateNewAccount("TestUsername", "TestEmail", "TestPassword");
                context.SaveChanges();
            }

            using (var context = new BankingAppDbContext(options))
            {
                Assert.AreEqual(1, context.Users.Count(ba => ba.Username == "TestUsername"));
            }
        }
예제 #2
0
 public UsersService(BankingAppDbContext context)
 {
     _context = context;
 }
 public BankAccountsService(BankingAppDbContext context)
 {
     _context = context;
 }
예제 #4
0
        public static void Initialize(BankingAppDbContext context)
        {
            context.Database.EnsureCreated();

            //If User table is empty then seed with some test data
            if (!context.Users.Any())
            {
                //Seed the table with some test values
                var salt = Utilities.BankingAppHash.GenerateSalt();
                context.Users.Add(new User
                {
                    Username = "******",
                    Email    = "*****@*****.**",
                    Password = Utilities.BankingAppHash.HashText("SuperPassword", salt),
                    Salt     = salt,
                    Role     = "Administrator"
                });

                salt = Utilities.BankingAppHash.GenerateSalt();
                context.Users.Add(new User
                {
                    Username = "******",
                    Email    = "*****@*****.**",
                    Password = Utilities.BankingAppHash.HashText("Password", salt),
                    Salt     = salt,
                    Role     = "User"
                });
                context.SaveChanges();
            }

            //If BankAccounts table is empty then seed with some test data
            if (!context.BankAccounts.Any())
            {
                context.BankAccounts.Add(new BankAccount
                {
                    AccountName = "Cash",
                    AccountType = "Standard",
                    Balance     = -130.44M,
                    UserId      = 2
                });
                context.BankAccounts.Add(new BankAccount
                {
                    AccountName = "Savings",
                    AccountType = "Savings Builder",
                    Balance     = 1422.02M,
                    UserId      = 2
                });
                context.BankAccounts.Add(new BankAccount
                {
                    AccountName = "Emergency Money",
                    AccountType = "Savings Builder",
                    Balance     = 0M,
                    UserId      = 2
                });
                context.SaveChanges();
            }

            //If BankTransferLog table table is empty then seed with some test data
            if (!context.BankTransferLogs.Any())
            {
                context.BankTransferLogs.Add(new BankTransferLog
                {
                    SenderId          = 1,
                    RecipientId       = 2,
                    TransferDate      = DateTime.Now,
                    AmountTransferred = 144.02M,
                    TransactionType   = "Transfer"
                });
                context.BankTransferLogs.Add(new BankTransferLog
                {
                    SenderId          = 2,
                    RecipientId       = 1,
                    TransferDate      = DateTime.Now,
                    AmountTransferred = 50.10M,
                    TransactionType   = "Transfer"
                });
                context.BankTransferLogs.Add(new BankTransferLog
                {
                    SenderId          = 3,
                    RecipientId       = 2,
                    TransferDate      = DateTime.Now,
                    AmountTransferred = 100.00M,
                    TransactionType   = "Transfer"
                });
                context.SaveChanges();
            }
        }