public async Task GetTransactionByUnit()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            var results = await(pending.Get(unit: "test")).ToArrayAsync();

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual("Note 1", results[0].Note);
            Assert.AreEqual("Note 2", results[1].Note);
        }
        public async Task DenyNotExistsTransaction()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            Assert.AreEqual(DenyResult.IdNotFound, await pending.DenyPending(d + 10));

            var notConfirmed = await(pending.Get(state: PendingState.Pending)).ToArrayAsync();

            Assert.AreEqual(4, notConfirmed.Length);
        }
        public async Task GetTransactionByAfter()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            var results = await(pending.Get(after: now + TimeSpan.FromMinutes(2.5))).ToArrayAsync();

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual("test2", results[0].Unit);
            Assert.AreEqual("test3", results[1].Unit);
        }
예제 #4
0
        public async Task GetTransactionByToId()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            var results = await(await pending.Get(toId: 1)).ToArray();

            Assert.AreEqual(2, results.Length);
            Assert.AreEqual("test", results[0].Unit);
            Assert.AreEqual("test2", results[1].Unit);
        }
        public async Task ConfirmAlreadyDeniedTransaction()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            Assert.AreEqual(DenyResult.Denied, await pending.DenyPending(a));
            Assert.AreEqual(ConfirmResult.AlreadyDenied, await pending.ConfirmPending(a));

            var notConfirmed = await(pending.Get(state: PendingState.Pending)).ToArrayAsync();

            Assert.AreEqual(3, notConfirmed.Length);
        }
        public async Task GetTransactionByPending()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            var results = await(pending.Get(state: PendingState.Pending)).ToArrayAsync();

            Assert.AreEqual(4, results.Length);
            Assert.AreEqual(a, results[0].Id);
            Assert.AreEqual(c, results[1].Id);
            Assert.AreEqual(b, results[2].Id);
            Assert.AreEqual(d, results[3].Id);
        }
        public async Task GetTransactionByDebtId()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            var results = await pending.Get(debtId : a).ToArrayAsync();

            Assert.AreEqual(1, results.Length);
            Assert.AreEqual("test", results[0].Unit);
            Assert.AreEqual("Note 1", results[0].Note);
            Assert.AreEqual((uint)0, results[0].FromId);
            Assert.AreEqual((uint)1, results[0].ToId);
            Assert.IsTrue(results[0].State == PendingState.Pending);
            Assert.AreEqual(a, results[0].Id);
        }
        public async Task DenyPendingTransaction()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;

            var(a, b, c, d) = await CreateTestTransactions(now, pending);

            var transactionsBefore = await(tsx.GetTransactions(0, 1, "TEST")).ToArrayAsync();

            Assert.AreEqual(0, transactionsBefore.Length);

            Assert.AreEqual(DenyResult.Denied, await pending.DenyPending(a));

            var notConfirmed = await(pending.Get(state: PendingState.Pending)).ToArrayAsync();

            Assert.AreEqual(3, notConfirmed.Length);

            var transactionsAfter = await(tsx.GetTransactions(0, 1, "TEST")).ToArrayAsync();

            Assert.AreEqual(0, transactionsAfter.Length);
        }