예제 #1
0
        public async Task FullTest()
        {
            using (var fixture = new GeldAppFixture())
            {
                await fixture.Login("Hans");

                // Verify db is empty.
                var imported = await fixture.GetAsync <ImportedExpense[]>("/api/account/Hans/imports/unhandled");

                imported.Length.Should().Be(0);

                // Import.
                var csv = File.ReadAllBytes("Import/dkb-import-test.csv");
                await fixture.PostFileAsync("/api/account/Hans/import/csv", "csvFile", "file.csv", csv);

                // Check imported stuff.
                imported = await fixture.GetAsync <ImportedExpense[]>("/api/account/Hans/imports/unhandled");

                var importedExpense = imported.Single();
                importedExpense.Amount.Should().Be(-12.34M);
                importedExpense.BookingDay.Should().Be(DateTime.Parse("2019-10-25"));

                // Add some expenses.
                await fixture.AddExpenseAsync("Hans", -12.34M, "Wrong", "Subcategory", ex => ex.Date = importedExpense.BookingDay.AddDays(-100).Date);

                await fixture.AddExpenseAsync("Hans", -12.34M, "Wrong", "Subcategory", ex => ex.Date = importedExpense.BookingDay.AddDays(+100).Date);

                await fixture.AddExpenseAsync("Hans", -12, "Wrong", "Subcategory", ex => ex.Date = importedExpense.BookingDay.AddDays(-2).Date);

                await fixture.AddExpenseAsync("Hans", -12.34M, "Correct", "Subcategory", ex => ex.Date = importedExpense.BookingDay.AddDays(-2).Date);

                (await fixture.GetExpensesAsync("Hans")).Should().HaveCount(4);

                // Get related expenses.
                var relatedExpenses = await fixture.GetAsync <ExpenseViewModel[]>("/api/account/Hans/expenses?relatedToImportedExpense=" + importedExpense.Id);

                relatedExpenses.Should().HaveCount(1);
                var relatedExpense = relatedExpenses.Single();
                relatedExpense.CategoryName.Should().Be("Correct");

                // Handle expense by linking it.
                await fixture.ExpectPostAsync($"/api/account/Hans/import/link?importedExpenseId={importedExpense.Id}&relatedExpenseId={relatedExpense.Id}", HttpStatusCode.OK);

                (await fixture.GetExpensesAsync("Hans")).Should().HaveCount(4);
                imported = await fixture.GetAsync <ImportedExpense[]>("/api/account/Hans/imports/unhandled");

                imported.Should().HaveCount(0);

                // Check link.
                var modifiedImportedExpense = fixture.QueryDb(db => db.ImportedExpenses.Include(ex => ex.Expense).Where(ex => ex.Expense != null).Single());
                modifiedImportedExpense.Expense.Id.Should().Be(relatedExpense.Id);
            }
        }