mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-23 09:35:38 -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
@@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// If: I attempt to create a CellUpdate to set it to NULL
|
||||
const string nullString = "NULL";
|
||||
DbColumnWrapper col = GetWrapper<string>("ntext", true);
|
||||
DbColumnWrapper col = GetWrapper<string>("ntext");
|
||||
CellUpdate cu = new CellUpdate(col, nullString);
|
||||
|
||||
// Then: The value should be a DBNull and the string value should be the same as what
|
||||
@@ -46,7 +46,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Equal(nullString, cu.ValueAsString);
|
||||
Assert.Equal(col, cu.Column);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void NullStringNotAllowedTest()
|
||||
{
|
||||
@@ -69,6 +69,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Equal(col, cu.Column);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("This is way too long")]
|
||||
[InlineData("TooLong")]
|
||||
public void StringTooLongTest(string value)
|
||||
{
|
||||
// If: I attempt to create a CellUpdate to set it to a large string
|
||||
// Then: I should get an exception thrown
|
||||
DbColumnWrapper col = GetWrapper<string>("nvarchar", false, 6);
|
||||
Assert.Throws<FormatException>(() => new CellUpdate(col, value));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ByteArrayTestParams))]
|
||||
public void ByteArrayTest(string strValue, byte[] expectedValue, string expectedString)
|
||||
@@ -274,16 +285,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(ec.IsDirty);
|
||||
}
|
||||
|
||||
private static DbColumnWrapper GetWrapper<T>(string dataTypeName, bool allowNull = true)
|
||||
private static DbColumnWrapper GetWrapper<T>(string dataTypeName, bool allowNull = true, int? colSize = null)
|
||||
{
|
||||
return new DbColumnWrapper(new CellUpdateTestDbColumn(typeof(T), dataTypeName, allowNull));
|
||||
return new DbColumnWrapper(new CellUpdateTestDbColumn(typeof(T), dataTypeName, allowNull, colSize));
|
||||
}
|
||||
|
||||
private class CellUpdateTestDbColumn : DbColumn
|
||||
{
|
||||
public CellUpdateTestDbColumn(Type dataType, string dataTypeName, bool allowNull = true)
|
||||
public CellUpdateTestDbColumn(Type dataType, string dataTypeName, bool allowNull = true, int? colSize = null)
|
||||
{
|
||||
AllowDBNull = allowNull;
|
||||
ColumnSize = colSize;
|
||||
DataType = dataType;
|
||||
DataTypeName = dataTypeName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user