Example #1
0
        public void Test(string connectionString, string[] nodes, string dataSource, bool?tcpKeepAlive, int?socketReceiveBufferSize, int?socketSendBufferSize)
        {
            var builder = new DqliteConnectionStringBuilder();

            if (nodes != null)
            {
                builder.Nodes = nodes;
            }
            if (dataSource != null)
            {
                builder.DataSource = dataSource;
            }
            if (tcpKeepAlive != null)
            {
                builder.TcpKeepAlive = tcpKeepAlive.Value;
            }
            if (socketReceiveBufferSize != null)
            {
                builder.SocketReceiveBufferSize = socketReceiveBufferSize.Value;
            }
            if (socketSendBufferSize != null)
            {
                builder.SocketSendBufferSize = socketSendBufferSize.Value;
            }

            Assert.Equal(connectionString, builder.ToString());
        }
Example #2
0
        public async Task Test1Async(int rows)
        {
            var builder = new DqliteConnectionStringBuilder()
            {
                Nodes      = new [] { "127.0.0.1:6543" },
                DataSource = "main"
            };

            using (var connection = new DqliteConnection(builder.ToString()))
            {
                await connection.OpenAsync();

                using (var command = new DqliteCommand()
                {
                    Connection = connection
                })
                {
                    command.CommandText = "CREATE TABLE IF NOT EXISTS Sample(n INT);";
                    await command.ExecuteNonQueryAsync();

                    command.CommandText = "DELETE FROM Sample;";
                    await command.ExecuteNonQueryAsync();

                    command.CommandText = "INSERT INTO Sample(n) VALUES(@value);";
                    await command.PrepareAsync();

                    for (int i = 0; i < rows; ++i)
                    {
                        command.Parameters.AddWithValue("@value", i);
                        await command.ExecuteNonQueryAsync();

                        command.Parameters.Clear();
                    }

                    command.CommandText = "SELECT count(0) FROM Sample;";

                    await using (var reader = await command.ExecuteReaderAsync())
                    {
                        Assert.True(await reader.ReadAsync());
                        Assert.Equal(1, reader.FieldCount);
                        Assert.Equal(rows, reader.GetInt64(0));
                        Assert.False(await reader.ReadAsync());
                    }

                    command.CommandText = "SELECT n FROM Sample;";

                    await using (var reader = await command.ExecuteReaderAsync())
                    {
                        for (int i = 0; i < rows; ++i)
                        {
                            Assert.True(await reader.ReadAsync());
                            Assert.Equal(i, reader.GetInt64(0));
                        }
                        Assert.False(await reader.ReadAsync());
                    }
                }
            }
        }