public async Task ShouldReadNoDataFromNotCommitedTransaction()
        {
            // Given
            var createTableQuery = new QueryObject("create table ##TransactionsTest ([ID] int, [Value] varchar(32));");
            var insertQuery      = new QueryObject("insert into ##TransactionsTest ([ID], [Value]) values (1, '123');");
            var countQuery       = new QueryObject("select count(*) from ##TransactionsTest;");
            var dropTableQuery   = new QueryObject("drop table ##TransactionsTest;");

            using (var connection = ConnectionsFactory.Create())
                try
                {
                    // When
                    await connection.ExecuteAsync(createTableQuery);

                    using (var session = _sessionsFactory.Create())
                        await session.ExecuteAsync(insertQuery);

                    // Then
                    int actualRecordsCount;
                    using (var session = _sessionsFactory.Create())
                        actualRecordsCount = (await session.QueryAsync <int>(countQuery)).Single();
                    Assert.Equal(0, actualRecordsCount);
                }
                finally
                {
                    await connection.ExecuteAsync(dropTableQuery);
                }
        }
        public void ShouldUseDecimalValuesListInQuery(ValuesListUsageTestCase <decimal> testCase)
        {
            // When
            decimal[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(@"
if type_id (N'[dbo].[DecimalValuesList]') is null
    create type [dbo].[DecimalValuesList] as table([Value] [numeric](6,3) not null)");

                actual = connection.Query <decimal>(@"
select [Value] from @Param",
                                                    new
                {
                    Param = PrimitiveValuesList.Create(
                        "DecimalValuesList",
                        testCase.Source,
                        new MetaDataCreationOptions {
                        Precision = 6, Scale = 3
                    }
                        )
                })
                         .ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
        public void ShouldReadDataFromCommitedTransaction()
        {
            // Given
            var createTableQuery = new QueryObject("create table ##TransactionsTest ([ID] int, [Value] varchar(32));");
            var insertQuery      = new QueryObject("insert into ##TransactionsTest ([ID], [Value]) values (1, '123');");
            var countQuery       = new QueryObject("select count(*) from ##TransactionsTest;");
            var dropTableQuery   = new QueryObject("drop table ##TransactionsTest;");

            using (var connection = ConnectionsFactory.Create())
                try
                {
                    // When
                    connection.Execute(createTableQuery);
                    using (var session = _sessionsFactory.Create())
                    {
                        session.Execute(insertQuery);
                        session.Commit();
                    }

                    // Then
                    int actualRecordsCount;
                    using (var session = _sessionsFactory.Create())
                        actualRecordsCount = session.Query <int>(countQuery).Single();
                    Assert.Equal(1, actualRecordsCount);
                }
                finally
                {
                    connection.Execute(dropTableQuery);
                }
        }
示例#4
0
        public void ShouldPerformBulkInsert(TestEntity[] expected)
        {
            // Given
            var createTableQuery = new QueryObject("create table ##TransactionsTest (Id int identity(1, 1) not null, Name nvarchar(max) not null, Value int not null);");
            var selectAllQuery   = new QueryObject("select * from ##TransactionsTest");
            var dropTableQuery   = new QueryObject("drop table ##TransactionsTest;");

            // When
            TestEntity[] actual;
            using (var connection = ConnectionsFactory.Create())
                try
                {
                    connection.Execute(createTableQuery);

                    using (var session = _sessionsFactory.Create())
                    {
                        session.BulkInsert("##TransactionsTest", expected);
                        session.Commit();
                    }

                    actual = connection.Query <TestEntity>(selectAllQuery).ToArray();
                }
                finally
                {
                    connection.Execute(dropTableQuery);
                }

            // Then
            Assert.Equal(expected, actual);
        }
        public async Task ShouldUseInt32ValuesListInQuery(ValuesListUsageTestCase <int> testCase)
        {
            // When
            int[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = (await connection.QueryAsync <int>(GetAllValuesQuery(testCase.Source))).ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
示例#6
0
        public async Task ShouldUseInt32ValuesListInQuery(int[] expected)
        {
            // When
            int[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = (await connection.QueryAsync <int>(GetAllValuesQuery(expected))).ToArray();
            }

            // Then
            Assert.Equal(expected, actual);
        }
        public void ShouldUseTvpInQueryWithAllTypes(TestEntityWithAllTypes[] expected)
        {
            // When
            TestEntityWithAllTypes[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = connection.Query <TestEntityWithAllTypes>(GetAllValuesQuery(expected)).ToArray();
            }

            // Then
            Assert.Equal(expected, actual);
        }
        public void ShouldUseTvpInQueryWithAllTypes(TvpUsageTestCase <TestEntityWithAllTypes> testCase)
        {
            // When
            TestEntityWithAllTypes[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = connection.Query <TestEntityWithAllTypes>(GetAllValuesQuery(testCase.Source)).ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
        public void ShouldUseInt64ValuesListInQuery(ValuesListUsageTestCase <long> testCase)
        {
            // When
            long[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(@"
if type_id (N'[dbo].[Int64ValuesList]') is null
    create type [dbo].[Int64ValuesList] as table([Value] [bigint] not null)");

                actual = connection.Query <long>(@"
select [Value] from @Param",
                                                 new { Param = new Int64ValuesList("Int64ValuesList", testCase.Source) })
                         .ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }