Пример #1
0
        public async Task UsersShouldNotHaveAccessToForeignAccountsTest()
        {
            using (var fixture = new GeldAppFixture())
            {
                await fixture.Login("Hans");

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

                // Create.
                var cmd = new Expense(-100, "Ausgabe", "Essen", "Pizza").AsCommand("Hans");
                (await fixture.Client.PostAsync("/api/account/Hans/expenses", cmd.AsContent())).ShouldBeOk();
                var exp = (await fixture.GetExpensesAsync("Hans")).Single();

                // Switch user.
                fixture.Logout();
                await fixture.Login("Petra");

                // Check foreign user actions.
                (await fixture.GetExpensesAsync("Petra")).Should().HaveCount(0);
                (await fixture.Client.GetAsync("/api/account/Hans/expenses")).StatusCode.Should().Be(HttpStatusCode.Unauthorized);
                (await fixture.Client.GetAsync($"/api/account/Hans/expense/{exp.Id}")).IsUnauthorized();
                (await fixture.Client.PostAsync($"/api/account/Hans/expenses", exp.AsContent())).IsUnauthorized();
                (await fixture.Client.PutAsync($"/api/account/Hans/expense/{exp.Id}", exp.AsContent())).IsUnauthorized();
                (await fixture.Client.DeleteAsync($"/api/account/Hans/expense/{exp.Id}")).IsUnauthorized();
            }
        }
Пример #2
0
        public async Task CreateUpdateDeleteExpenseTest()
        {
            using (var fixture = new GeldAppFixture())
            {
                await fixture.Login("Hans");

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

                // Create.
                var cmd = new Expense(-100, "Ausgabe", "Essen", "Pizza").AsCommand("Hans");
                (await fixture.Client.PostAsync("/api/account/Hans/expenses", cmd.AsContent())).ShouldBeOk();
                var exp = (await fixture.GetExpensesAsync("Hans")).Single();
                exp.Amount.Should().Be(-100);

                // Edit.
                exp.Amount = -200;
                (await fixture.Client.PutAsync($"/api/account/Hans/expense/{exp.Id}", exp.AsContent())).ShouldBeOk();
                exp = (await fixture.GetExpensesAsync("Hans")).Single();
                exp.Amount.Should().Be(-200);
                exp.Details.Should().Be("pidser", "PipelineBehaviors should be enabled :)");

                // Get Single.
                exp = await fixture.GetExpenseAsync("Hans", exp.Id);

                exp.Amount.Should().Be(-200);

                // Delete.
                (await fixture.Client.DeleteAsync($"/api/account/Hans/expense/{exp.Id}")).ShouldBeOk();
                (await fixture.GetExpensesAsync("Hans")).Should().HaveCount(0);
            }
        }
Пример #3
0
        public async Task HandleByCreatingExpenseTest()
        {
            using (var fixture = new GeldAppFixture())
            {
                await fixture.Login("Hans");

                // 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.
                var imported = await fixture.GetAsync <ImportedExpense[]>("/api/account/Hans/imports/unhandled");

                var importedExpense = imported.Single();

                // No expenses yet.
                (await fixture.GetExpensesAsync("Hans")).Should().HaveCount(0);

                // Handle expense by creating new expense.
                await fixture.AddExpenseAsync("Hans", 10, "Cat", "Sub", modCmd : cmd => cmd.HandlesImportedExpenseId = importedExpense.Id);

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

                // No more unhandled imported expenses expected.
                imported = await fixture.GetAsync <ImportedExpense[]>("/api/account/Hans/imports/unhandled");

                imported.Should().HaveCount(0);
            }
        }
Пример #4
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);
            }
        }