Beispiel #1
0
        public async Task All_LimitSpecification()
        {
            var depts   = new Departments(ProviderName);
            var allRows = await(await depts.AllAsync(limit: 10)).ToListAsync();

            Assert.AreEqual(10, allRows.Count);
        }
Beispiel #2
0
        public async Task Save_MultipleRows()
        {
            var depts = new Departments(ProviderName);

            object[] toSave = new object[]
            {
                new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando(),
                new { DNAME = "Massive Dep", LOC = "DownTown" }.ToExpando()
            };
            var result = await depts.SaveAsync(toSave);

            Assert.AreEqual(2, result);
            foreach (dynamic o in toSave)
            {
                Assert.IsTrue(o.DEPTNO > 0);
            }

            // read them back, update them, save them again,
            var savedDeps = await(await depts.AllAsync(where : "WHERE DEPTNO=:0 OR DEPTNO=:1", args: new object[] { ((dynamic)toSave[0]).DEPTNO, ((dynamic)toSave[1]).DEPTNO })).ToListAsync();

            Assert.AreEqual(2, savedDeps.Count);
            savedDeps[0].LOC += "C";
            savedDeps[1].LOC += "C";
            result            = await depts.SaveAsync(toSave);

            Assert.AreEqual(2, result);
            Assert.AreEqual(1, await depts.DeleteAsync(savedDeps[0].DEPTNO));
            Assert.AreEqual(1, await depts.DeleteAsync(savedDeps[1].DEPTNO));
        }
Beispiel #3
0
        public async Task UpdateUsing_SingleRow()
        {
            var     depts = new Departments(ProviderName);
            dynamic toSave = new { DNAME = "Massive Dep", LOC = "Beach" }.ToExpando();
            var     saveResult = await depts.SaveAsync(toSave);

            Assert.AreEqual(1, saveResult);
            Assert.IsTrue(toSave.DEPTNO > 0);
            var mightyDep = new { DNAME = "Mighty Dep" };

            Assert.AreEqual(0, (await(await depts.AllAsync(mightyDep)).ToListAsync()).Count);
            Assert.AreEqual(1, await depts.UpdateUsingAsync(mightyDep, toSave.DEPTNO));
            Assert.AreEqual(1, (await(await depts.AllAsync(mightyDep)).ToListAsync()).Count);
            Assert.AreEqual(1, await depts.DeleteAsync(toSave.DEPTNO));
            Assert.AreEqual(0, (await(await depts.AllAsync(mightyDep)).ToListAsync()).Count);
        }
Beispiel #4
0
        public async Task NormalWhereCall()
        {
            // Check that things are up and running normally before trying the new stuff
            var db   = new Departments(ProviderName);
            var rows = await db.AllAsync(where : "LOC = :0", args : "Nowhere");

            Assert.AreEqual(9, (await rows.ToListAsync()).Count);
        }
Beispiel #5
0
        public async Task All_NoParameters()
        {
            var depts   = new Departments(ProviderName);
            var allRows = await(await depts.AllAsync()).ToListAsync();

            Assert.AreEqual(60, allRows.Count);
            foreach (var d in allRows)
            {
                Console.WriteLine("{0} {1} {2}", d.DEPTNO, d.DNAME, d.LOC);
            }
        }
Beispiel #6
0
        public async Task All_WhereSpecification_OrderBySpecification()
        {
            var depts   = new Departments(ProviderName);
            var allRows = await(await depts.AllAsync(orderBy: "DEPTNO DESC", where : "WHERE LOC=:0", args: "Nowhere")).ToListAsync();

            Assert.AreEqual(9, allRows.Count);
            int previous = int.MaxValue;

            foreach (var r in allRows)
            {
                int current = r.DEPTNO;
                Assert.IsTrue(current <= previous);
                previous = current;
            }
        }
Beispiel #7
0
        public async Task All_NoParameters_RespondsToCancellation()
        {
            using (CancellationTokenSource cts = new CancellationTokenSource())
            {
                var depts   = new Departments(ProviderName);
                var allRows = await depts.AllAsync(cts.Token);

                int count = 0;
                Assert.ThrowsAsync <TaskCanceledException>(async() => {
                    await allRows.ForEachAsync(d => {
                        Console.WriteLine("{0} {1} {2}", d.DEPTNO, d.DNAME, d.LOC);
                        count++;
                        if (count == 14)
                        {
                            cts.Cancel();
                        }
                    });
                });
                Assert.AreEqual(14, count);
            }
        }