mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Edit Data: Better errors for possible truncation (#514)
* Fix to make sql exceptions surface properly to user (with important notes!) * Adding support for detecting column size issues when updating a cell * Adding unit tests for the exception on read scenario
This commit is contained in:
committed by
Karl Burtram
parent
9499d73cec
commit
e9bc97e290
@@ -285,6 +285,28 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.Equal(Common.StandardRows, resultSet.RowCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddRowThrowsOnRead()
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a standard result set with standard data
|
||||
var fileFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
var mockReader = GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery);
|
||||
ResultSet resultSet = new ResultSet(Common.Ordinal, Common.Ordinal, fileFactory);
|
||||
await resultSet.ReadResultToEnd(mockReader, CancellationToken.None);
|
||||
|
||||
// ... Create a mock reader that will throw on read
|
||||
var throwingReader = GetReader(new[] {new TestResultSet(5, 0)}, true, Constants.StandardQuery);
|
||||
|
||||
// If: I add a row with a reader that throws on read
|
||||
// Then:
|
||||
// ... I should get an exception
|
||||
await Assert.ThrowsAnyAsync<DbException>(() => resultSet.AddRow(throwingReader));
|
||||
|
||||
// ... The row count should not have changed
|
||||
Assert.Equal(Common.StandardRows, resultSet.RowCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddRowSuccess()
|
||||
{
|
||||
@@ -363,7 +385,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
private static DbDataReader GetReader(TestResultSet[] dataSet, bool throwOnRead, string query)
|
||||
{
|
||||
var info = Common.CreateTestConnectionInfo(dataSet, throwOnRead);
|
||||
var info = Common.CreateTestConnectionInfo(dataSet, false, throwOnRead);
|
||||
var connection = info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails));
|
||||
var command = connection.CreateCommand();
|
||||
command.CommandText = query;
|
||||
|
||||
Reference in New Issue
Block a user