Example #1
0
        public void Test1()
        {
            // In-memory database only exists while the connection is open
            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();
            try
            {
                var options = new DbContextOptionsBuilder <WebWalletApiContext>()
                              .UseSqlite(connection)
                              .Options;

                // Create the schema in the database
                using (var context = new WebWalletApiContext(options))
                {
                    context.Database.EnsureCreated();
                }
                using (var context = new WebWalletApiContext(options))
                {
                    var bankId        = Guid.NewGuid();
                    var transactionId = Guid.NewGuid();
                    var bankAccount   = new BankAccount()
                    {
                        Id = bankId, Comment = "Kapitalkonto", Balance = "100", CreationTime = "", InterestRate = "", OwnerId = Guid.NewGuid(), Transactions = new List <Transaction>()
                    };
                    var transaction = new Transaction {
                        Id = transactionId, BankAccountId = bankId, Comment = "Insättning", Deposit = "100", CreationTime = "", Withdraw = ""
                    };
                    context.BankAccount.Add(bankAccount);
                    context.Transaction.Add(transaction);
                    context.SaveChanges();
                }

                using (var context = new WebWalletApiContext(options))
                {
                    var bc     = new BankAccountController(context);
                    var result = bc.GetBankAccounts();
                    Assert.NotNull(result);
                    Assert.Equal(result.Count(), 1);
                }
                using (var context = new WebWalletApiContext(options))
                {
                    var tc     = new TransactionController(context);
                    var result = tc.Get();
                    Assert.NotNull(result);
                    Assert.Equal(result.Count(), 1);
                }
            }
            finally
            {
                connection.Close();
            }
        }
 public BankAccountController(WebWalletApiContext context)
 {
     _unitOfWork = new UnitOfWork(context);
 }
Example #3
0
 public TransactionController(WebWalletApiContext context)
 {
     _unitOfWork = new UnitOfWork(context);
 }