mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
NULL column validation when updating cells (#274)
* Adding validation that NULL is allowed when setting cell values * Adding unit tests
This commit is contained in:
@@ -31,11 +31,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStringTest()
|
||||
public void NullStringAllowedTest()
|
||||
{
|
||||
// If: I attempt to create a CellUpdate to set it to NULL (with mixed cases)
|
||||
// If: I attempt to create a CellUpdate to set it to NULL
|
||||
const string nullString = "NULL";
|
||||
DbColumnWrapper col = GetWrapper<string>("ntext");
|
||||
DbColumnWrapper col = GetWrapper<string>("ntext", true);
|
||||
CellUpdate cu = new CellUpdate(col, nullString);
|
||||
|
||||
// Then: The value should be a DBNull and the string value should be the same as what
|
||||
@@ -46,6 +46,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Equal(col, cu.Column);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullStringNotAllowedTest()
|
||||
{
|
||||
// If: I attempt to create a cell update to set to null when its not allowed
|
||||
// Then: I should get an exception thrown
|
||||
Assert.Throws<InvalidOperationException>(() => new CellUpdate(GetWrapper<string>("ntext", false), "NULL"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NullTextStringTest()
|
||||
{
|
||||
@@ -197,15 +205,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
private static DbColumnWrapper GetWrapper<T>(string dataTypeName)
|
||||
private static DbColumnWrapper GetWrapper<T>(string dataTypeName, bool allowNull = true)
|
||||
{
|
||||
return new DbColumnWrapper(new CellUpdateTestDbColumn(typeof(T), dataTypeName));
|
||||
return new DbColumnWrapper(new CellUpdateTestDbColumn(typeof(T), dataTypeName, allowNull));
|
||||
}
|
||||
|
||||
private class CellUpdateTestDbColumn : DbColumn
|
||||
{
|
||||
public CellUpdateTestDbColumn(Type dataType, string dataTypeName)
|
||||
public CellUpdateTestDbColumn(Type dataType, string dataTypeName, bool allowNull = true)
|
||||
{
|
||||
AllowDBNull = allowNull;
|
||||
DataType = dataType;
|
||||
DataTypeName = dataTypeName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user