Example #1
0
        public void Batch_SimpleSql()
        {
            var runner = RunnerFactory.Create();
            var batch  = runner.CreateBatch();
            var result = batch.Add <string>("SELECT 'TEST';");

            runner.Execute(batch);

            var list = result.GetValue();

            list.Count.Should().Be(1);
            list[0].Should().Be("TEST");
        }
Example #2
0
        public async Task CommandAndQueryBatch_AsTask()
        {
            var runner  = RunnerFactory.Create();
            var batch   = runner.CreateBatch();
            var promise = batch.Add(new QuerySimpleQuery());
            var task    = promise.AsTask(TimeSpan.FromSeconds(10));

            runner.Execute(batch);

            var result = await task;

            result.Should().Be("TEST");
        }
        public async Task AsyncStreamResults_Tests()
        {
            var runner = RunnerFactory.Create();
            var stream = runner.QueryStream("SELECT 1 UNION SELECT 2 UNION SELECT 3");
            var result = stream.AsEnumerableAsync <int>();
            var sum    = 0;

            await foreach (var i in result)
            {
                sum += i;
            }

            sum.Should().Be(6);
        }
Example #4
0
        public void Query2_Stringify()
        {
            var runner     = RunnerFactory.Create();
            var parameters = new QueryValues
            {
                Value1 = 5,
                Value2 = 3.14f,
                Value3 = "TEST"
            };
            var query  = new Query(parameters);
            var result = runner.ObjectStringifier.Stringify(query);

            result.Should().NotBeNullOrEmpty();
        }
Example #5
0
        public void ParameterObject_Test()
        {
            var runner     = RunnerFactory.Create();
            var parameters = new QueryValues
            {
                Value1 = 5,
                Value2 = 3.14f,
                Value3 = "TEST"
            };
            var result = runner.Query(new Query(parameters));

            result.Value1.Should().Be(5);
            result.Value2.Should().Be(3.14f);
            result.Value3.Should().Be("TEST");
        }
Example #6
0
        public void CommandAndQueryBatch_Transaction()
        {
            var runner = RunnerFactory.Create(b => b.UseTransaction(IsolationLevel.Serializable));
            var batch  = runner.CreateBatch();

            batch.Add(new CreateTempTableCommand());
            var result = batch.Add(new QueryTempTableQuery());

            runner.Execute(batch);

            result.IsComplete.Should().Be(true);
            var list = result.GetValue();

            list.Should().NotBeNull();
            list.Should().BeEquivalentTo(1, 3, 5, 7);
        }
Example #7
0
        public void SqlQuery_Combine_string_Cached()
        {
            // Quick test for cacheMappings=true
            // We can't really test at this level that the cache was correctly utilized, but we can
            // test that repeated invocations don't break. Evidence that, at least, the cache
            // isn't making things stop working.
            var runner = RunnerFactory.Create();
            var query  = SqlQuery.Combine("SELECT 'TEST'", r => r.AsEnumerable <string>().First(), true);

            var result = runner.Query(query);

            result.Should().Be("TEST");

            // Run it again, to make sure it still works
            result = runner.Query(query);
            result.Should().Be("TEST");
        }
Example #8
0
        public void CommandAndQueryBatch_SimpleSql()
        {
            var runner = RunnerFactory.Create();
            var batch  = runner.CreateBatch();

            batch.Add(@"
                CREATE TEMPORARY TABLE castiron_test (
                    [Value] INT NOT NULL
                );
                INSERT INTO castiron_test ([Value]) VALUES (1),(3),(5),(7);");
            var result = batch.Add <int>("SELECT * FROM castiron_test;");

            runner.Execute(batch);

            result.IsComplete.Should().Be(true);
            var list = result.GetValue();

            list.Should().NotBeNull();
            list.Should().BeEquivalentTo(1, 3, 5, 7);
        }