コード例 #1
0
        public async Task CreateTransactionDoesNotThrow()
        {
            var db      = new SqliteInMemoryDatabase();
            var tsx     = new DatabaseTransactions(db);
            var pending = new DatabasePendingTransactions(db, tsx);

            var now = DateTime.UtcNow;
            await pending.CreatePending(0, 1, 10, "GBP", "Note", now);
        }
コード例 #2
0
        private (IDatabaseService, ISoundEffectLibrary) Create()
        {
            var db = new SqliteInMemoryDatabase();
            var sx = new DatabaseSoundEffectLibrary(new Moe.Configuration {
                SoundEffects = new Moe.SoundEffectConfig {
                    SfxFolder = "/",
                },
            }, db, new MockFileSystem());

            return(db, sx);
        }
コード例 #3
0
        public async Task GetByChannel()
        {
            var db = new SqliteInMemoryDatabase();
            var rm = new DatabaseReminders(db);

            var t = DateTime.UtcNow + TimeSpan.FromMinutes(1);
            var r = await rm.Create(t, "pre", "msg", 17, 28);

            var rs = await rm.Get(channel : 17).ToArrayAsync();

            Assert.AreEqual(r, rs.Single());
        }
コード例 #4
0
        public async Task GetByMaxTime()
        {
            var db = new SqliteInMemoryDatabase();
            var rm = new DatabaseReminders(db);

            var t  = DateTime.UtcNow;
            var r1 = await rm.Create(t, "pre", "msg2", 17, 28);

            var r2 = await rm.Create(t + TimeSpan.FromHours(1), "pre", "msg2", 17, 28);

            var rs = await rm.Get(before : t + TimeSpan.FromHours(0.5f)).ToArrayAsync();

            Assert.AreEqual(r1, rs.Single());
        }
コード例 #5
0
        public async Task CreateReminderDoesNotThrow()
        {
            var db = new SqliteInMemoryDatabase();
            var rm = new DatabaseReminders(db);

            var t = DateTime.UtcNow + TimeSpan.FromMinutes(1);
            var r = await rm.Create(t, "pre", "msg", 17, 28);

            Assert.AreEqual(t, r.TriggerTime);
            Assert.AreEqual("pre", r.Prelude);
            Assert.AreEqual("msg", r.Message);
            Assert.AreEqual(17u, r.ChannelId);
            Assert.AreEqual(28u, r.UserId);
        }
コード例 #6
0
        public async Task Delete()
        {
            var db = new SqliteInMemoryDatabase();
            var rm = new DatabaseReminders(db);

            var t = DateTime.UtcNow + TimeSpan.FromMinutes(1);
            var r = await rm.Create(t, "pre", "msg", 17, 28);

            Assert.IsTrue(await rm.Delete(28, r.ID));

            var rs = await rm.Get(channel : 17).ToArrayAsync();

            Assert.AreEqual(0, rs.Length);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        public async Task GetWithLimit()
        {
            var db = new SqliteInMemoryDatabase();
            var rm = new DatabaseReminders(db);

            var t = DateTime.UtcNow;

            for (var i = 0; i < 10; i++)
            {
                await rm.Create(t + TimeSpan.FromMinutes(i), "pre", "msg " + i, 17, 28);
            }

            var rs = await rm.Get(channel : 17, count : 3).ToArrayAsync();

            Assert.AreEqual(3, rs.Length);
            Assert.AreEqual((t + TimeSpan.FromMinutes(0)).UnixTimestamp(), rs[0].TriggerTime.UnixTimestamp());
            Assert.AreEqual((t + TimeSpan.FromMinutes(1)).UnixTimestamp(), rs[1].TriggerTime.UnixTimestamp());
            Assert.AreEqual((t + TimeSpan.FromMinutes(2)).UnixTimestamp(), rs[2].TriggerTime.UnixTimestamp());
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }