Exemple #1
0
        private void SeedDatabase(GeldAppContext db)
        {
            var cat1 = new Category("Ausgaben");
            var cat2 = new Category("Ausgaben");
            var cat3 = new Category("Ausgaben");

            cat1.Subcategories.Add(new Subcategory("Essen"));
            cat2.Subcategories.Add(new Subcategory("Trinken"));
            cat3.Subcategories.Add(new Subcategory("Naschen"));

            var sharedAccount = new Account("Shared", cat2);

            var hans = new User("Hans", "abc123")
            {
                RefreshToken = "refreshMe"
            };

            hans.AddAccount(new Account("Hans", cat1));
            hans.AddAccount(sharedAccount);
            db.Users.Add(hans);

            var petra = new User("Petra", "abc123");

            petra.AddAccount(new Account("Petra", cat3));
            petra.AddAccount(sharedAccount);
            db.Users.Add(petra);

            var admin = User.CreateAdmin("Admin", "abc123");

            db.Users.Add(admin);

            db.SaveChanges();
        }
Exemple #2
0
        private GeldAppContext GetTestDb()
        {
            DateTime D(int y, int m, int d) => new DateTime(y, m, d);

            var builder = new DbContextOptionsBuilder <GeldAppContext>();

            builder.UseInMemoryDatabase(Guid.NewGuid().ToString(), i => { });
            var db = new GeldAppContext(builder.Options);

            var account1 = new Account(1, "Ich");
            var account2 = new Account(2, "Helmut Kohl");

            db.Expenses.Add(new Database.Expense {
                Id = 1, Date = D(1, 1, 1), Account = account1, Amount = -1, Category = "Essen", Subcategory = "Pidser", Details = "Calzone"
            });
            db.Expenses.Add(new Database.Expense {
                Id = 2, Date = D(1, 1, 1), Account = account1, Amount = -2, Category = "Essen", Subcategory = "Coler", Details = "Coca Coler"
            });
            db.Expenses.Add(new Database.Expense {
                Id = 3, Date = D(1, 1, 2), Account = account1, Amount = -3, Category = "Auto", Subcategory = "Öl", Details = "Racing"
            });
            db.Expenses.Add(new Database.Expense {
                Id = 4, Date = D(2, 2, 1), Account = account1, Amount = -4, Category = "Auto", Subcategory = "Benzin", Details = "E10"
            });
            db.Expenses.Add(new Database.Expense {
                Id = 5, Date = D(2, 2, 1), Account = account1, Amount = 100, Category = "Gehalt", Subcategory = "Arbyte", Details = "", Type = ExpenseType.Revenue
            });
            db.Expenses.Add(new Database.Expense {
                Id = 6, Date = D(2, 1, 1), Account = account1, Amount = 1000.12M, Category = "Gehalt", Subcategory = "Schwarzgeld", Details = "", Type = ExpenseType.RegularRevenue
            });
            db.Expenses.Add(new Database.Expense {
                Id = 7, Date = D(3000, 1, 1), Account = account1, Amount = 1000000, Category = "Zocken", Subcategory = "Lotto", Details = "", Type = ExpenseType.Revenue
            });
            db.Expenses.Add(new Database.Expense {
                Id = 8, Date = D(1, 1, 1), Account = account2, Amount = -1, Category = "Essen", Subcategory = "Pidser", Details = "Calzone"
            });
            db.SaveChanges();

            return(db);
        }