Ejemplo n.º 1
0
        public UserBankAccount UseNewUserBankAccount(
            Guid dataBaseName,
            Guid userId,
            Guid bankAccountId,
            bool isOwner    = false,
            bool isReadOnly = false)
        {
            var userBankAccount = new UserBankAccount()
            {
                CreationDate     = DateTime.Now,
                Id               = Guid.NewGuid(),
                ModificationDate = DateTime.Now,
                BankAccountId    = bankAccountId,
                IsOwner          = isOwner,
                IsReadOnly       = isReadOnly,
                UserId           = userId
            };

            var dbContextOptions = new DbContextOptionsBuilder <DaGetContext>()
                                   .UseInMemoryDatabase(databaseName: dataBaseName.ToString())
                                   .Options;

            using (var context = new DaGetContext(dbContextOptions))
            {
                context.UserBankAccounts.Add(userBankAccount);

                context.Commit();
            }

            return(userBankAccount);
        }
Ejemplo n.º 2
0
        private static User AddUser(Guid dataBaseName, User user)
        {
            var dbContextOptions = new DbContextOptionsBuilder <DaGetContext>()
                                   .UseInMemoryDatabase(databaseName: dataBaseName.ToString())
                                   .Options;

            using (var context = new DaGetContext(dbContextOptions))
            {
                context.Users.Add(user);

                context.Commit();
            }

            return(user);
        }
Ejemplo n.º 3
0
        public BankAccount UseNewBankAccount(Guid databaseName, Guid userId, Guid bankAccountTypeId)
        {
            var bankAccountAmount = GenerateNewAmount();

            var bankAccount = new BankAccount()
            {
                Balance           = bankAccountAmount,
                BankAccountTypeId = bankAccountTypeId,
                CreationDate      = DateTime.Now,
                Id = Guid.NewGuid(),
                ModificationDate = DateTime.Now,
                OpeningBalance   = bankAccountAmount,
                ActualBalance    = bankAccountAmount,
                Wording          = "Test bank account"
            };

            var userBankAccount = new UserBankAccount()
            {
                BankAccountId    = bankAccount.Id,
                CreationDate     = DateTime.Now,
                Id               = Guid.NewGuid(),
                IsOwner          = true,
                IsReadOnly       = false,
                ModificationDate = DateTime.Now,
                UserId           = userId
            };

            var dbContextOptions = new DbContextOptionsBuilder <DaGetContext>()
                                   .UseInMemoryDatabase(databaseName: databaseName.ToString())
                                   .Options;

            using (var context = new DaGetContext(dbContextOptions))
            {
                context.BankAccounts.Add(bankAccount);
                context.UserBankAccounts.Add(userBankAccount);

                context.Commit();
            }

            return(bankAccount);
        }
Ejemplo n.º 4
0
        private static Operation AddOperation(Guid databaseName, Operation operation)
        {
            var dbContextOptions = new DbContextOptionsBuilder <DaGetContext>()
                                   .UseInMemoryDatabase(databaseName: databaseName.ToString())
                                   .Options;

            using (var context = new DaGetContext(dbContextOptions))
            {
                context.Operations.Add(operation);

                var bankAccount = context.BankAccounts.Single(ba => ba.Id.Equals(operation.BankAccountId));
                bankAccount.Balance += operation.Amount;
                if (operation.IsClosed)
                {
                    bankAccount.ActualBalance += operation.Amount;
                }
                context.BankAccounts.Update(bankAccount);

                context.Commit();
            }

            return(operation);
        }
Ejemplo n.º 5
0
        public BankAccountType UseNewBankAccountType(Guid databaseName)
        {
            var bankAccountType = new BankAccountType()
            {
                CreationDate     = DateTime.Now,
                Id               = Guid.NewGuid(),
                ModificationDate = DateTime.Now,
                Wording          = "Test bank account type"
            };

            var dbContextOptions = new DbContextOptionsBuilder <DaGetContext>()
                                   .UseInMemoryDatabase(databaseName: databaseName.ToString())
                                   .Options;

            using (var context = new DaGetContext(dbContextOptions))
            {
                context.BankAccountTypes.Add(bankAccountType);

                context.Commit();
            }

            return(bankAccountType);
        }
Ejemplo n.º 6
0
        public OperationType UseNewOperationType(Guid databaseName, Guid bankAccountId)
        {
            var operationType = new OperationType()
            {
                BankAccountId    = bankAccountId,
                CreationDate     = DateTime.Now,
                Id               = Guid.NewGuid(),
                ModificationDate = DateTime.Now,
                Wording          = Guid.NewGuid().ToString()
            };

            var dbContextOptions = new DbContextOptionsBuilder <DaGetContext>()
                                   .UseInMemoryDatabase(databaseName: databaseName.ToString())
                                   .Options;

            using (var context = new DaGetContext(dbContextOptions))
            {
                context.OperationTypes.Add(operationType);

                context.Commit();
            }

            return(operationType);
        }