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:
Benjamin Russell
2017-10-21 11:08:40 -07:00
committed by Karl Burtram
parent 9499d73cec
commit e9bc97e290
37 changed files with 445 additions and 343 deletions

View File

@@ -8,23 +8,30 @@ using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
{
public class TestDbException : DbException
{
}
public class TestDbDataReader : DbDataReader, IDbColumnSchemaGenerator
{
#region Test Specific Implementations
private IEnumerable<TestResultSet> Data { get; }
public IEnumerator<TestResultSet> ResultSetEnumerator { get; }
private IEnumerator<TestResultSet> ResultSetEnumerator { get; }
private IEnumerator<object[]> RowEnumerator { get; set; }
private bool ThrowOnRead { get; }
public TestDbDataReader(IEnumerable<TestResultSet> data)
public TestDbDataReader(IEnumerable<TestResultSet> data, bool throwOnRead)
{
ThrowOnRead = throwOnRead;
Data = data;
if (Data != null)
{
@@ -59,6 +66,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
/// <returns>True if tere were more rows, false otherwise</returns>
public override bool Read()
{
if (ThrowOnRead)
{
throw new TestDbException();
}
if (RowEnumerator == null)
{
RowEnumerator = ResultSetEnumerator.Current.GetEnumerator();
@@ -97,11 +108,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
/// <returns>Number of cells in the current row</returns>
public override int GetValues(object[] values)
{
for (int i = 0; i < RowEnumerator.Current.Count(); i++)
for (int i = 0; i < RowEnumerator.Current.Length; i++)
{
values[i] = this[i];
}
return RowEnumerator.Current.Count();
return RowEnumerator.Current.Length;
}
/// <summary>

View File

@@ -182,7 +182,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
{
return new TestDbDataReader(Data);
return new TestDbDataReader(Data, false);
}
private List<DbParameter> listParams = new List<DbParameter>();