Exemple #1
0
        public async Task ConnectionShouldConnectWhenCommandIsExecuted()
        {
            var connection = TestDatabase.GetConnection();

            using (var session = new Session(connection)) {
                var sampleQuery = @"Select 'Test'";

                connection.State.Should().Be(ConnectionState.Closed);

                var result = await session.CreateCommand(sampleQuery).ExecuteScalarAsync <string>();

                connection.State.Should().Be(ConnectionState.Open);

                result.Should().Be("Test");
            }
        }
		public async Task SampleQueryTest()
		{
			using (var unitOfWork = new UnitOfWork(TestDatabase.GetConnection())) {

				var session = new Session(unitOfWork);

				var createTableSql = @"Create Table ScalarTable (
	Id int primary key,
	Name varchar(20)
)";

				var insertIntoSql = @"Insert Into ScalarTable Values (1, 'One')";

				session.CreateCommand(createTableSql).ExecuteNonQuery();
				session.CreateCommand(insertIntoSql).ExecuteNonQuery();

				var value = await session.CreateCommand("Select Id From ScalarTable where Id = ?", 1).ExecuteScalarAsync<int>();

				value.Should().Be(1);
			}

		}
        [Test] public async Task OnlyTransformUnnamedParameters()
        {
            using (var session = new Session(TestDatabase.GetConnection()))
            {
                var createTableSql = @"Create Table OnlyTransformUnnamedParameters_Table (
	[Id] int primary key,
	[String] varchar(20)
)";

                var insertIntoSql = @"Insert Into OnlyTransformUnnamedParameters_Table Values (?,'?')";

                session.CreateCommand(createTableSql).ExecuteNonQuery();
                session.CreateCommand(insertIntoSql, 1).ExecuteNonQuery();

                using (var command = await session.CreateCommand("Select * From OnlyTransformUnnamedParameters_Table").ExecuteQueryAsync())
                {
                    var row = await command.SingleAsync <dynamic>();

                    ((int)row.Id).Should().Be(1);
                    ((string)row.String).Should().Be("?");
                }
            }
        }
Exemple #4
0
        public async Task SampleQueryTest()
        {
            using (var unitOfWork = new UnitOfWork(TestDatabase.GetConnection())) {
                var session = new Session(unitOfWork);

                var createTableSql = @"Create Table TableA (
	Id int primary key,
	Name varchar(20)
)";

                var insertIntoSql = @"Insert Into TableA Values (1, 'One')";

                session.CreateCommand(createTableSql).ExecuteNonQuery();
                session.CreateCommand(insertIntoSql).ExecuteNonQuery();

                using (var command = await session.CreateCommand("Select * From TableA where Id = ?", 1).ExecuteQueryAsync())
                {
                    var row = await command.SingleAsync <RawRow>();

                    ((int)row.Id).Should().Be(1);
                }
            }
        }
        public async Task MultipleParametersShouldMatchTypes()
        {
            using (var session = new Session(TestDatabase.GetConnection())) {
                var createTableSql = @"Create Table MultipleParametersShouldMatchTypes_Table (
	[Id] int primary key,
	[String] varchar(20),
	[Boolean] bit
)";

                var insertIntoSql = @"Insert Into MultipleParametersShouldMatchTypes_Table Values (?, ?, ?)";

                session.CreateCommand(createTableSql).ExecuteNonQuery();
                session.CreateCommand(insertIntoSql, 1, "value", true).ExecuteNonQuery();

                using (var command = await session.CreateCommand("Select * From MultipleParametersShouldMatchTypes_Table").ExecuteQueryAsync())
                {
                    var row = await command.SingleAsync <dynamic>();

                    ((int)row.Id).Should().Be(1);
                    ((string)row.String).Should().Be("value");
                    ((bool)row.Boolean).Should().Be(true);
                }
            }
        }