public async Task Read([Values(CommandBehavior.Default, CommandBehavior.SequentialAccess)] CommandBehavior behavior) { using (var conn = await OpenConnectionAsync()) await using (await CreateTempTable(conn, "bytes BYTEA", out var table)) { // TODO: This is too small to actually test any interesting sequential behavior byte[] expected = { 1, 2, 3, 4, 5 }; await conn.ExecuteNonQueryAsync($"INSERT INTO {table} (bytes) VALUES ({EncodeByteaHex(expected)})"); string queryText = $"SELECT bytes, 'foo', bytes, bytes, bytes FROM {table}"; using (var cmd = new NpgsqlCommand(queryText, conn)) using (var reader = await cmd.ExecuteReaderAsync(behavior)) { reader.Read(); var actual = reader.GetFieldValue <byte[]>(0); Assert.That(actual, Is.EqualTo(expected)); if (behavior.IsSequential()) { Assert.That(() => reader[0], Throws.Exception.TypeOf <InvalidOperationException>(), "Seek back sequential"); } else { Assert.That(reader.GetFieldValue <byte[]>(0), Is.EqualTo(expected)); } Assert.That(reader.GetString(1), Is.EqualTo("foo")); Assert.That(reader[2], Is.EqualTo(expected)); Assert.That(reader.GetValue(3), Is.EqualTo(expected)); Assert.That(reader.GetFieldValue <byte[]>(4), Is.EqualTo(expected)); } } }
public void Read([Values(CommandBehavior.Default, CommandBehavior.SequentialAccess)] CommandBehavior behavior) { using (var conn = OpenConnection()) { // TODO: This is too small to actually test any interesting sequential behavior byte[] expected = { 1, 2, 3, 4, 5 }; conn.ExecuteNonQuery("CREATE TEMP TABLE data (bytes BYTEA)"); conn.ExecuteNonQuery($@"INSERT INTO data (bytes) VALUES ({TestUtil.EncodeByteaHex(expected)})"); const string queryText = @"SELECT bytes, 'foo', bytes, bytes, bytes FROM data"; using (var cmd = new NpgsqlCommand(queryText, conn)) using (var reader = cmd.ExecuteReader(behavior)) { reader.Read(); var actual = reader.GetFieldValue <byte[]>(0); Assert.That(actual, Is.EqualTo(expected)); if (behavior.IsSequential()) { Assert.That(() => reader[0], Throws.Exception.TypeOf <InvalidOperationException>(), "Seek back sequential"); } else { Assert.That(reader.GetFieldValue <byte[]>(0), Is.EqualTo(expected)); } Assert.That(reader.GetString(1), Is.EqualTo("foo")); Assert.That(reader[2], Is.EqualTo(expected)); Assert.That(reader.GetValue(3), Is.EqualTo(expected)); Assert.That(reader.GetFieldValue <byte[]>(4), Is.EqualTo(expected)); } } }
public async Task Long([Values(CommandBehavior.Default, CommandBehavior.SequentialAccess)] CommandBehavior behavior) { using var conn = await OpenConnectionAsync(); await using var _ = await CreateTempTable(conn, "name TEXT", out var table); var builder = new StringBuilder("ABCDEééé", conn.Settings.WriteBufferSize); builder.Append('X', conn.Settings.WriteBufferSize); var expected = builder.ToString(); using (var cmd = new NpgsqlCommand($"INSERT INTO {table} (name) VALUES (@p)", conn)) { cmd.Parameters.Add(new NpgsqlParameter("p", expected)); await cmd.ExecuteNonQueryAsync(); } using (var cmd = new NpgsqlCommand($"SELECT name, 'foo', name, name, name, name FROM {table}", conn)) { var reader = await cmd.ExecuteReaderAsync(behavior); reader.Read(); var actual = reader[0]; Assert.That(actual, Is.EqualTo(expected)); if (behavior.IsSequential()) { Assert.That(() => reader[0], Throws.Exception.TypeOf <InvalidOperationException>(), "Seek back sequential"); } else { Assert.That(reader[0], Is.EqualTo(expected)); } Assert.That(reader.GetString(1), Is.EqualTo("foo")); Assert.That(reader.GetFieldValue <string>(2), Is.EqualTo(expected)); Assert.That(reader.GetValue(3), Is.EqualTo(expected)); Assert.That(reader.GetFieldValue <string>(4), Is.EqualTo(expected)); //Assert.That(reader.GetFieldValue<char[]>(5), Is.EqualTo(expected.ToCharArray())); } }
public void Long([Values(CommandBehavior.Default, CommandBehavior.SequentialAccess)] CommandBehavior behavior) { using (var conn = OpenConnection()) { var builder = new StringBuilder("ABCDEééé", conn.Settings.WriteBufferSize); builder.Append('X', conn.Settings.WriteBufferSize); var expected = builder.ToString(); using (var cmd = new NpgsqlCommand(@"INSERT INTO data (name) VALUES (@p)", conn)) { conn.ExecuteNonQuery("CREATE TEMP TABLE data (name TEXT)"); cmd.Parameters.Add(new NpgsqlParameter("p", expected)); cmd.ExecuteNonQuery(); } const string queryText = @"SELECT name, 'foo', name, name, name, name FROM data"; using (var cmd = new NpgsqlCommand(queryText, conn)) { var reader = cmd.ExecuteReader(behavior); reader.Read(); var actual = reader[0]; Assert.That(actual, Is.EqualTo(expected)); if (behavior.IsSequential()) { Assert.That(() => reader[0], Throws.Exception.TypeOf <InvalidOperationException>(), "Seek back sequential"); } else { Assert.That(reader[0], Is.EqualTo(expected)); } Assert.That(reader.GetString(1), Is.EqualTo("foo")); Assert.That(reader.GetFieldValue <string>(2), Is.EqualTo(expected)); Assert.That(reader.GetValue(3), Is.EqualTo(expected)); Assert.That(reader.GetFieldValue <string>(4), Is.EqualTo(expected)); //Assert.That(reader.GetFieldValue<char[]>(5), Is.EqualTo(expected.ToCharArray())); } } }