diff --git a/src/Microsoft.SqlTools.Credentials/Localization/sr.cs b/src/Microsoft.SqlTools.Credentials/Localization/sr.cs index 9f0625e1..6dd123a5 100755 --- a/src/Microsoft.SqlTools.Credentials/Localization/sr.cs +++ b/src/Microsoft.SqlTools.Credentials/Localization/sr.cs @@ -27,7 +27,7 @@ namespace Microsoft.SqlTools.Credentials Keys.Culture = value; } } - + public static string CredentialsServiceInvalidCriticalHandle { @@ -35,7 +35,7 @@ namespace Microsoft.SqlTools.Credentials { return Keys.GetString(Keys.CredentialsServiceInvalidCriticalHandle); } - } + } public static string CredentialsServicePasswordLengthExceeded { @@ -43,7 +43,7 @@ namespace Microsoft.SqlTools.Credentials { return Keys.GetString(Keys.CredentialsServicePasswordLengthExceeded); } - } + } public static string CredentialsServiceTargetForDelete { @@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.Credentials { return Keys.GetString(Keys.CredentialsServiceTargetForDelete); } - } + } public static string CredentialsServiceTargetForLookup { @@ -59,7 +59,7 @@ namespace Microsoft.SqlTools.Credentials { return Keys.GetString(Keys.CredentialsServiceTargetForLookup); } - } + } public static string CredentialServiceWin32CredentialDisposed { @@ -67,7 +67,7 @@ namespace Microsoft.SqlTools.Credentials { return Keys.GetString(Keys.CredentialServiceWin32CredentialDisposed); } - } + } [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Keys @@ -75,22 +75,22 @@ namespace Microsoft.SqlTools.Credentials static ResourceManager resourceManager = new ResourceManager("Microsoft.SqlTools.Credentials.Localization.SR", typeof(SR).GetTypeInfo().Assembly); static CultureInfo _culture = null; - - - public const string CredentialsServiceInvalidCriticalHandle = "CredentialsServiceInvalidCriticalHandle"; - - - public const string CredentialsServicePasswordLengthExceeded = "CredentialsServicePasswordLengthExceeded"; - - - public const string CredentialsServiceTargetForDelete = "CredentialsServiceTargetForDelete"; - - - public const string CredentialsServiceTargetForLookup = "CredentialsServiceTargetForLookup"; - - - public const string CredentialServiceWin32CredentialDisposed = "CredentialServiceWin32CredentialDisposed"; - + + + public const string CredentialsServiceInvalidCriticalHandle = "CredentialsServiceInvalidCriticalHandle"; + + + public const string CredentialsServicePasswordLengthExceeded = "CredentialsServicePasswordLengthExceeded"; + + + public const string CredentialsServiceTargetForDelete = "CredentialsServiceTargetForDelete"; + + + public const string CredentialsServiceTargetForLookup = "CredentialsServiceTargetForLookup"; + + + public const string CredentialServiceWin32CredentialDisposed = "CredentialServiceWin32CredentialDisposed"; + private Keys() { } @@ -111,7 +111,7 @@ namespace Microsoft.SqlTools.Credentials { return resourceManager.GetString(key, _culture); } - - } - } -} + + } + } +} diff --git a/src/Microsoft.SqlTools.Credentials/Localization/sr.resx b/src/Microsoft.SqlTools.Credentials/Localization/sr.resx index b4947a92..b2ab23ff 100755 --- a/src/Microsoft.SqlTools.Credentials/Localization/sr.resx +++ b/src/Microsoft.SqlTools.Credentials/Localization/sr.resx @@ -120,21 +120,21 @@ Invalid CriticalHandle! - + The password has exceeded 512 bytes - + Target must be specified to delete a credential - + Target must be specified to check existance of a credential - + Win32Credential object is already disposed - - + + diff --git a/src/Microsoft.SqlTools.Credentials/Localization/sr.xlf b/src/Microsoft.SqlTools.Credentials/Localization/sr.xlf index 577660b5..b340af8b 100644 --- a/src/Microsoft.SqlTools.Credentials/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.Credentials/Localization/sr.xlf @@ -1,32 +1,32 @@ - - - - - - Invalid CriticalHandle! - Invalid CriticalHandle! - - - - The password has exceeded 512 bytes - The password has exceeded 512 bytes - - - - Target must be specified to delete a credential - Target must be specified to delete a credential - - - - Target must be specified to check existance of a credential - Target must be specified to check existance of a credential - - - - Win32Credential object is already disposed - Win32Credential object is already disposed - - - - + + + + + + Invalid CriticalHandle! + Invalid CriticalHandle! + + + + The password has exceeded 512 bytes + The password has exceeded 512 bytes + + + + Target must be specified to delete a credential + Target must be specified to delete a credential + + + + Target must be specified to check existance of a credential + Target must be specified to check existance of a credential + + + + Win32Credential object is already disposed + Win32Credential object is already disposed + + + + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.Hosting/Localization/sr.cs b/src/Microsoft.SqlTools.Hosting/Localization/sr.cs index 52ae9e27..7ec9a964 100755 --- a/src/Microsoft.SqlTools.Hosting/Localization/sr.cs +++ b/src/Microsoft.SqlTools.Hosting/Localization/sr.cs @@ -27,7 +27,7 @@ namespace Microsoft.SqlTools.Hosting Keys.Culture = value; } } - + public static string CredentialsServiceInvalidCriticalHandle { @@ -35,7 +35,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.CredentialsServiceInvalidCriticalHandle); } - } + } public static string CredentialsServicePasswordLengthExceeded { @@ -43,7 +43,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.CredentialsServicePasswordLengthExceeded); } - } + } public static string CredentialsServiceTargetForDelete { @@ -51,7 +51,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.CredentialsServiceTargetForDelete); } - } + } public static string CredentialsServiceTargetForLookup { @@ -59,7 +59,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.CredentialsServiceTargetForLookup); } - } + } public static string CredentialServiceWin32CredentialDisposed { @@ -67,7 +67,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.CredentialServiceWin32CredentialDisposed); } - } + } public static string ServiceAlreadyRegistered { @@ -75,7 +75,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.ServiceAlreadyRegistered); } - } + } public static string MultipleServicesFound { @@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.MultipleServicesFound); } - } + } public static string IncompatibleServiceForExtensionLoader { @@ -91,7 +91,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.IncompatibleServiceForExtensionLoader); } - } + } public static string ServiceProviderNotSet { @@ -99,7 +99,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.ServiceProviderNotSet); } - } + } public static string ServiceNotFound { @@ -107,7 +107,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.ServiceNotFound); } - } + } public static string ServiceNotOfExpectedType { @@ -115,7 +115,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.ServiceNotOfExpectedType); } - } + } public static string HostingUnexpectedEndOfStream { @@ -123,7 +123,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.HostingUnexpectedEndOfStream); } - } + } public static string HostingHeaderMissingColon { @@ -131,7 +131,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.HostingHeaderMissingColon); } - } + } public static string HostingHeaderMissingContentLengthHeader { @@ -139,7 +139,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.HostingHeaderMissingContentLengthHeader); } - } + } public static string HostingHeaderMissingContentLengthValue { @@ -147,7 +147,7 @@ namespace Microsoft.SqlTools.Hosting { return Keys.GetString(Keys.HostingHeaderMissingContentLengthValue); } - } + } [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Keys @@ -155,52 +155,52 @@ namespace Microsoft.SqlTools.Hosting static ResourceManager resourceManager = new ResourceManager("Microsoft.SqlTools.Hosting.Localization.SR", typeof(SR).GetTypeInfo().Assembly); static CultureInfo _culture = null; - - - public const string CredentialsServiceInvalidCriticalHandle = "CredentialsServiceInvalidCriticalHandle"; - - - public const string CredentialsServicePasswordLengthExceeded = "CredentialsServicePasswordLengthExceeded"; - - - public const string CredentialsServiceTargetForDelete = "CredentialsServiceTargetForDelete"; - - - public const string CredentialsServiceTargetForLookup = "CredentialsServiceTargetForLookup"; - - - public const string CredentialServiceWin32CredentialDisposed = "CredentialServiceWin32CredentialDisposed"; - - - public const string ServiceAlreadyRegistered = "ServiceAlreadyRegistered"; - - - public const string MultipleServicesFound = "MultipleServicesFound"; - - - public const string IncompatibleServiceForExtensionLoader = "IncompatibleServiceForExtensionLoader"; - - - public const string ServiceProviderNotSet = "ServiceProviderNotSet"; - - - public const string ServiceNotFound = "ServiceNotFound"; - - - public const string ServiceNotOfExpectedType = "ServiceNotOfExpectedType"; - - - public const string HostingUnexpectedEndOfStream = "HostingUnexpectedEndOfStream"; - - - public const string HostingHeaderMissingColon = "HostingHeaderMissingColon"; - - - public const string HostingHeaderMissingContentLengthHeader = "HostingHeaderMissingContentLengthHeader"; - - - public const string HostingHeaderMissingContentLengthValue = "HostingHeaderMissingContentLengthValue"; - + + + public const string CredentialsServiceInvalidCriticalHandle = "CredentialsServiceInvalidCriticalHandle"; + + + public const string CredentialsServicePasswordLengthExceeded = "CredentialsServicePasswordLengthExceeded"; + + + public const string CredentialsServiceTargetForDelete = "CredentialsServiceTargetForDelete"; + + + public const string CredentialsServiceTargetForLookup = "CredentialsServiceTargetForLookup"; + + + public const string CredentialServiceWin32CredentialDisposed = "CredentialServiceWin32CredentialDisposed"; + + + public const string ServiceAlreadyRegistered = "ServiceAlreadyRegistered"; + + + public const string MultipleServicesFound = "MultipleServicesFound"; + + + public const string IncompatibleServiceForExtensionLoader = "IncompatibleServiceForExtensionLoader"; + + + public const string ServiceProviderNotSet = "ServiceProviderNotSet"; + + + public const string ServiceNotFound = "ServiceNotFound"; + + + public const string ServiceNotOfExpectedType = "ServiceNotOfExpectedType"; + + + public const string HostingUnexpectedEndOfStream = "HostingUnexpectedEndOfStream"; + + + public const string HostingHeaderMissingColon = "HostingHeaderMissingColon"; + + + public const string HostingHeaderMissingContentLengthHeader = "HostingHeaderMissingContentLengthHeader"; + + + public const string HostingHeaderMissingContentLengthValue = "HostingHeaderMissingContentLengthValue"; + private Keys() { } @@ -221,7 +221,7 @@ namespace Microsoft.SqlTools.Hosting { return resourceManager.GetString(key, _culture); } - - } - } -} + + } + } +} diff --git a/src/Microsoft.SqlTools.Hosting/Localization/sr.resx b/src/Microsoft.SqlTools.Hosting/Localization/sr.resx index 532f5e47..babafb52 100755 --- a/src/Microsoft.SqlTools.Hosting/Localization/sr.resx +++ b/src/Microsoft.SqlTools.Hosting/Localization/sr.resx @@ -120,61 +120,61 @@ Invalid CriticalHandle! - + The password has exceeded 512 bytes - + Target must be specified to delete a credential - + Target must be specified to check existance of a credential - + Win32Credential object is already disposed - + Cannot register service for type {0}, one or more services already registered - + Multiple services found for type {0}, expected only 1 - + Service of type {0} cannot be created by ExtensionLoader<{1}> - + SetServiceProvider() was not called to establish the required service provider - + Service {0} was not found in the service provider - + Service of Type {0} is not compatible with registered Type {1} - + MessageReader's input stream ended unexpectedly, terminating - + Message header must separate key and value using ':' - + Fatal error: Content-Length header must be provided - + Fatal error: Content-Length value is not an integer - - + + diff --git a/src/Microsoft.SqlTools.Hosting/Localization/sr.xlf b/src/Microsoft.SqlTools.Hosting/Localization/sr.xlf index 0d624148..eb98421f 100644 --- a/src/Microsoft.SqlTools.Hosting/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.Hosting/Localization/sr.xlf @@ -1,82 +1,82 @@ - - - - - - Invalid CriticalHandle! - Invalid CriticalHandle! - - - - The password has exceeded 512 bytes - The password has exceeded 512 bytes - - - - Target must be specified to delete a credential - Target must be specified to delete a credential - - - - Target must be specified to check existance of a credential - Target must be specified to check existance of a credential - - - - Win32Credential object is already disposed - Win32Credential object is already disposed - - - - MessageReader's input stream ended unexpectedly, terminating - MessageReader's input stream ended unexpectedly, terminating - - - - Message header must separate key and value using ':' - Message header must separate key and value using ':' - - - - Fatal error: Content-Length header must be provided - Fatal error: Content-Length header must be provided - - - - Fatal error: Content-Length value is not an integer - Fatal error: Content-Length value is not an integer - - - - Cannot register service for type {0}, one or more services already registered - Cannot register service for type {0}, one or more services already registered - - - - Multiple services found for type {0}, expected only 1 - Multiple services found for type {0}, expected only 1 - - - - Service of type {0} cannot be created by ExtensionLoader<{1}> - Service of type {0} cannot be created by ExtensionLoader<{1}> - - - - SetServiceProvider() was not called to establish the required service provider - SetServiceProvider() was not called to establish the required service provider - - - - Service {0} was not found in the service provider - Service {0} was not found in the service provider - - - - Service of Type {0} is not compatible with registered Type {1} - Service of Type {0} is not compatible with registered Type {1} - - - - + + + + + + Invalid CriticalHandle! + Invalid CriticalHandle! + + + + The password has exceeded 512 bytes + The password has exceeded 512 bytes + + + + Target must be specified to delete a credential + Target must be specified to delete a credential + + + + Target must be specified to check existance of a credential + Target must be specified to check existance of a credential + + + + Win32Credential object is already disposed + Win32Credential object is already disposed + + + + MessageReader's input stream ended unexpectedly, terminating + MessageReader's input stream ended unexpectedly, terminating + + + + Message header must separate key and value using ':' + Message header must separate key and value using ':' + + + + Fatal error: Content-Length header must be provided + Fatal error: Content-Length header must be provided + + + + Fatal error: Content-Length value is not an integer + Fatal error: Content-Length value is not an integer + + + + Cannot register service for type {0}, one or more services already registered + Cannot register service for type {0}, one or more services already registered + + + + Multiple services found for type {0}, expected only 1 + Multiple services found for type {0}, expected only 1 + + + + Service of type {0} cannot be created by ExtensionLoader<{1}> + Service of type {0} cannot be created by ExtensionLoader<{1}> + + + + SetServiceProvider() was not called to establish the required service provider + SetServiceProvider() was not called to establish the required service provider + + + + Service {0} was not found in the service provider + Service {0} was not found in the service provider + + + + Service of Type {0} is not compatible with registered Type {1} + Service of Type {0} is not compatible with registered Type {1} + + + + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ResourceProvider/Localization/sr.cs b/src/Microsoft.SqlTools.ResourceProvider/Localization/sr.cs old mode 100644 new mode 100755 diff --git a/src/Microsoft.SqlTools.ResourceProvider/Localization/sr.resx b/src/Microsoft.SqlTools.ResourceProvider/Localization/sr.resx old mode 100644 new mode 100755 diff --git a/src/Microsoft.SqlTools.ServiceLayer/EditData/UpdateManagement/CellUpdate.cs b/src/Microsoft.SqlTools.ServiceLayer/EditData/UpdateManagement/CellUpdate.cs index d1cce23d..3b761667 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/EditData/UpdateManagement/CellUpdate.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/EditData/UpdateManagement/CellUpdate.cs @@ -49,10 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement } else if (columnType == typeof(string)) { - // Special case for strings because the string value should stay the same as provided - // If user typed 'NULL' they mean NULL as text - Value = valueAsString == TextNullString ? NullString : valueAsString; - ValueAsString = valueAsString; + ProcessTextCell(valueAsString); } else if (columnType == typeof(Guid)) { @@ -245,6 +242,23 @@ namespace Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement ValueAsString = NullString; } + private void ProcessTextCell(string valueAsString) + { + // Special case for strings because the string value should stay the same as provided + // If user typed 'NULL' they mean NULL as text + Value = valueAsString == TextNullString ? NullString : valueAsString; + + // Make sure that the value fits inside the size of the column + if (Column.ColumnSize.HasValue && valueAsString.Length > Column.ColumnSize) + { + string columnSizeString = $"({Column.ColumnSize.Value})"; + string columnTypeString = Column.DataTypeName.ToUpperInvariant() + columnSizeString; + throw new FormatException(SR.EditDataValueTooLarge(valueAsString, columnTypeString)); + } + + ValueAsString = valueAsString; + } + #endregion } } diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs index 0fb58c60..9cfdb072 100755 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.cs @@ -3651,6 +3651,11 @@ namespace Microsoft.SqlTools.ServiceLayer return Keys.GetString(Keys.EditDataUnsupportedObjectType, typeName); } + public static string EditDataValueTooLarge(string value, string columnType) + { + return Keys.GetString(Keys.EditDataValueTooLarge, value, columnType); + } + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Keys { @@ -3932,6 +3937,9 @@ namespace Microsoft.SqlTools.ServiceLayer public const string EditDataNullNotAllowed = "EditDataNullNotAllowed"; + public const string EditDataValueTooLarge = "EditDataValueTooLarge"; + + public const string EE_BatchSqlMessageNoProcedureInfo = "EE_BatchSqlMessageNoProcedureInfo"; diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx index 8c948393..0c7d3c4b 100755 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.resx @@ -495,6 +495,11 @@ NULL is not allowed for this column + + Value {0} is too large to fit in column of type {1} + . + Parameters: 0 - value (string), 1 - columnType (string) + Msg {0}, Level {1}, State {2}, Line {3} diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings index cd65c296..1d7d1c16 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.strings @@ -232,6 +232,8 @@ EditDataTimeOver24Hrs = TIME column values must be between 00:00:00.0000000 and EditDataNullNotAllowed = NULL is not allowed for this column +EditDataValueTooLarge(string value, string columnType) = Value {0} is too large to fit in column of type {1} + ############################################################################ # DacFx Resources diff --git a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf index 79bb6be2..84b7d2c9 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf +++ b/src/Microsoft.SqlTools.ServiceLayer/Localization/sr.xlf @@ -2305,6 +2305,12 @@ For directory {0} a file with name {1} already exists + + Value {0} is too large to fit in column of type {1} + Value {0} is too large to fit in column of type {1} + . + Parameters: 0 - value (string), 1 - columnType (string) + \ No newline at end of file diff --git a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/ResultSet.cs b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/ResultSet.cs index 390a774b..cddb4f6e 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/ResultSet.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/QueryExecution/ResultSet.cs @@ -616,19 +616,23 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution { throw new InvalidOperationException(SR.QueryServiceResultSetNotRead); } - if (!dbDataReader.HasRows) + // NOTE: We are no longer checking to see if the data reader has rows before reading + // b/c of a quirk in SqlClient. In some scenarios, a SqlException isn't thrown until we + // read. In order to get appropriate errors back to the user, we'll read first. + // Returning false from .ReadAsync means there aren't any rows. + + // Create a storage data reader, read it, make sure there were results + StorageDataReader dataReader = new StorageDataReader(dbDataReader); + if (!await dataReader.ReadAsync(CancellationToken.None)) { throw new InvalidOperationException(SR.QueryServiceResultSetAddNoRows); } - - StorageDataReader dataReader = new StorageDataReader(dbDataReader); - + using (IFileStreamWriter writer = fileStreamFactory.GetWriter(outputFileName)) { // Write the row to the end of the file long currentFileOffset = totalBytesWritten; writer.Seek(currentFileOffset); - await dataReader.ReadAsync(CancellationToken.None); totalBytesWritten += writer.WriteRow(dataReader); return currentFileOffset; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs index db82dba7..282b110a 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Connection/ConnectionServiceTests.cs @@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection var commandMockSetup = commandMock.Protected() .Setup("ExecuteDbDataReader", It.IsAny()); - commandMockSetup.Returns(() => new TestDbDataReader(data)); + commandMockSetup.Returns(() => new TestDbDataReader(data, false)); return commandMock.Object; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/CellUpdateTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/CellUpdateTests.cs index 23c45aaf..9a81f56f 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/CellUpdateTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/CellUpdateTests.cs @@ -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("ntext", true); + DbColumnWrapper col = GetWrapper("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("nvarchar", false, 6); + Assert.Throws(() => 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(string dataTypeName, bool allowNull = true) + private static DbColumnWrapper GetWrapper(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; } diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/Common.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/Common.cs index e5801d05..36a73b1b 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/Common.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/Common.cs @@ -118,7 +118,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData ? Enumerable.Repeat(new object[] { "id", "1", "2", "3" }, rowCount) : Enumerable.Repeat(new object[] { "1", "2", "3" }, rowCount); var testResultSet = new TestResultSet(columns, rows); - var reader = new TestDbDataReader(new[] { testResultSet }); + var reader = new TestDbDataReader(new[] { testResultSet }, false); var resultSet = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory()); await resultSet.ReadResultToEnd(reader, CancellationToken.None); return resultSet; @@ -130,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData ? new[] {new object[] {"id", "q", "q", "q"}} : new[] {new object[] {"q", "q", "q"}}; var testResultSet = new TestResultSet(columns, rows); - return new TestDbDataReader(new [] {testResultSet}); + return new TestDbDataReader(new [] {testResultSet}, false); } public static void AddCells(RowEditBase rc, bool includeIdentity) diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowCreateTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowCreateTests.cs index a4f3cecc..dc3e6ed9 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowCreateTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowCreateTests.cs @@ -293,7 +293,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData }}; object[][] rows = {}; var testResultSet = new TestResultSet(cols, rows); - var testReader = new TestDbDataReader(new[] {testResultSet}); + var testReader = new TestDbDataReader(new[] {testResultSet}, false); var rs = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory()); await rs.ReadResultToEnd(testReader, CancellationToken.None); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowEditBaseTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowEditBaseTests.cs index c8d17b6d..9a0b1fc1 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowEditBaseTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowEditBaseTests.cs @@ -243,7 +243,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData { object[][] rows = {row}; var testResultSet = new TestResultSet(columns, rows); - var testReader = new TestDbDataReader(new [] {testResultSet}); + var testReader = new TestDbDataReader(new [] {testResultSet}, false); var resultSet = new ResultSet(0,0, MemoryFileSystem.GetFileStreamFactory()); await resultSet.ReadResultToEnd(testReader, CancellationToken.None); return resultSet; diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowUpdateTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowUpdateTests.cs index 65ea7f9d..09a30034 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowUpdateTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/RowUpdateTests.cs @@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData }; object[][] rows = { new object[]{new byte[] {0x00}}}; var testResultSet = new TestResultSet(cols, rows); - var testReader = new TestDbDataReader(new[] { testResultSet }); + var testReader = new TestDbDataReader(new[] { testResultSet }, false); var rs = new ResultSet(0, 0, MemoryFileSystem.GetFileStreamFactory()); rs.ReadResultToEnd(testReader, CancellationToken.None).Wait(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/ServiceIntegrationTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/ServiceIntegrationTests.cs index 1c8f520e..5154699c 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/ServiceIntegrationTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/ServiceIntegrationTests.cs @@ -363,7 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData .Returns(etm); // ... Create a query execution service that will return a successful query - var qes = QueryExecution.Common.GetPrimedExecutionService(mockQueryResults, true, false, null); + var qes = QueryExecution.Common.GetPrimedExecutionService(mockQueryResults, true, false, false, null); // ... Create a connection service that doesn't throw when asked for a connection var cs = new Mock(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/SessionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/SessionTests.cs index b7b49313..7e5b1a24 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/SessionTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/EditData/SessionTests.cs @@ -81,7 +81,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData }; // @TODO: Fix when the connection service is fixed - ConnectionInfo ci = QueryExecution.Common.CreateConnectedConnectionInfo(results, false); + ConnectionInfo ci = QueryExecution.Common.CreateConnectedConnectionInfo(results, false, false); ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci; var fsf = MemoryFileSystem.GetFileStreamFactory(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/LanguageServer/BindingQueueTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/LanguageServer/BindingQueueTests.cs index 06d03641..ffb3d9aa 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/LanguageServer/BindingQueueTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/LanguageServer/BindingQueueTests.cs @@ -146,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.LanguageServer object defaultReturnObject = new object(); var queueItem = this.bindingQueue.QueueBindingOperation( key: "testkey", - bindOperation: (context, CancellationToken) => throw new Exception("Unhandled!!"), + bindOperation: (context, CancellationToken) => { throw new Exception("Unhandled!!"); }, timeoutOperation: TestTimeoutOperation, errorHandler: (exception) => { isExceptionHandled = true; diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/CancelTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/CancelTests.cs index 4a5b3706..220e871e 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/CancelTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/CancelTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I request a query (doesn't matter what kind) and execute it var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri }; var executeRequest = RequestContextMocks.Create(null); @@ -53,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I request a query (doesn't matter what kind) and wait for execution var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri}; var executeRequest = RequestContextMocks.Create(null); @@ -82,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I request to cancel a query that doesn't exist var workspaceService = new Mock>(); - var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService.Object); + var queryService = Common.GetPrimedExecutionService(null, false, false, false, workspaceService.Object); var cancelParams = new QueryCancelParams { OwnerUri = "Doesn't Exist" }; var cancelRequest = new EventFlowValidator() diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Common.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Common.cs index 55115bc6..af243d6e 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Common.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Common.cs @@ -1,6 +1,7 @@ // // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +// using System.Collections.Concurrent; using System.Data; @@ -24,7 +25,7 @@ using HostingProtocol = Microsoft.SqlTools.Hosting.Protocol; namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution { - public class Common + public static class Common { #region Constants @@ -38,8 +39,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution public const int StandardRows = 5; - public const string UdtQuery = "SELECT hierarchyid::Parse('/')"; - public const SelectionData WholeDocument = null; public static readonly ConnectionDetails StandardConnectionDetails = new ConnectionDetails @@ -72,29 +71,29 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution public static Batch GetBasicExecutedBatch() { - Batch batch = new Batch(Test.Common.Constants.StandardQuery, SubsectionDocument, 1, + Batch batch = new Batch(Constants.StandardQuery, SubsectionDocument, 1, MemoryFileSystem.GetFileStreamFactory()); - batch.Execute(CreateTestConnection(StandardTestDataSet, false), CancellationToken.None).Wait(); + batch.Execute(CreateTestConnection(StandardTestDataSet, false, false), CancellationToken.None).Wait(); return batch; } public static Batch GetExecutedBatchWithExecutionPlan() { - Batch batch = new Batch(Test.Common.Constants.StandardQuery, SubsectionDocument, 1, + Batch batch = new Batch(Constants.StandardQuery, SubsectionDocument, 1, MemoryFileSystem.GetFileStreamFactory()); - batch.Execute(CreateTestConnection(ExecutionPlanTestDataSet, false), CancellationToken.None).Wait(); + batch.Execute(CreateTestConnection(ExecutionPlanTestDataSet, false, false), CancellationToken.None).Wait(); return batch; } public static Query GetBasicExecutedQuery() { - ConnectionInfo ci = CreateConnectedConnectionInfo(StandardTestDataSet, false); + ConnectionInfo ci = CreateConnectedConnectionInfo(StandardTestDataSet, false, false); // Query won't be able to request a new query DbConnection unless the ConnectionService has a // ConnectionInfo with the same URI as the query, so we will manually set it ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci; - Query query = new Query(Test.Common.Constants.StandardQuery, ci, new QueryExecutionSettings(), + Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory()); query.Execute(); query.ExecutionTask.Wait(); @@ -103,13 +102,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution public static Query GetBasicExecutedQuery(QueryExecutionSettings querySettings) { - ConnectionInfo ci = CreateConnectedConnectionInfo(StandardTestDataSet, false); + ConnectionInfo ci = CreateConnectedConnectionInfo(StandardTestDataSet, false, false); // Query won't be able to request a new query DbConnection unless the ConnectionService has a // ConnectionInfo with the same URI as the query, so we will manually set it ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci; - Query query = new Query(Test.Common.Constants.StandardQuery, ci, querySettings, + Query query = new Query(Constants.StandardQuery, ci, querySettings, MemoryFileSystem.GetFileStreamFactory()); query.Execute(); query.ExecutionTask.Wait(); @@ -135,14 +134,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution #region DbConnection Mocking - public static DbCommand CreateTestCommand(TestResultSet[] data, bool throwOnRead) + private static DbCommand CreateTestCommand(TestResultSet[] data, bool throwOnExecute, bool throwOnRead) { var commandMock = new Mock { CallBase = true }; var commandMockSetup = commandMock.Protected() .Setup("ExecuteDbDataReader", It.IsAny()); - // Setup the expected behavior - if (throwOnRead) + // Setup the expected execute behavior + if (throwOnExecute) { var mockException = new Mock(); mockException.SetupGet(dbe => dbe.Message).Returns("Message"); @@ -150,19 +149,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution } else { - commandMockSetup.Returns(new TestDbDataReader(data)); + commandMockSetup.Returns(new TestDbDataReader(data, throwOnRead)); } return commandMock.Object; } - public static DbConnection CreateTestConnection(TestResultSet[] data, bool throwOnRead) + private static DbConnection CreateTestConnection(TestResultSet[] data, bool throwOnExecute, bool throwOnRead) { var connectionMock = new Mock { CallBase = true }; connectionMock.Protected() .Setup("CreateDbCommand") - .Returns(() => CreateTestCommand(data, throwOnRead)); + .Returns(() => CreateTestCommand(data, throwOnExecute, throwOnRead)); connectionMock.Setup(dbc => dbc.Open()) .Callback(() => connectionMock.SetupGet(dbc => dbc.State).Returns(ConnectionState.Open)); connectionMock.Setup(dbc => dbc.Close()) @@ -171,34 +170,38 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution return connectionMock.Object; } - public static ISqlConnectionFactory CreateMockFactory(TestResultSet[] data, bool throwOnRead) + private static ISqlConnectionFactory CreateMockFactory(TestResultSet[] data, bool throwOnExecute, bool throwOnRead) { var mockFactory = new Mock(); mockFactory.Setup(factory => factory.CreateSqlConnection(It.IsAny())) - .Returns(() => CreateTestConnection(data, throwOnRead)); + .Returns(() => CreateTestConnection(data, throwOnExecute, throwOnRead)); return mockFactory.Object; } - public static ConnectionInfo CreateTestConnectionInfo(TestResultSet[] data, bool throwOnRead) + public static ConnectionInfo CreateTestConnectionInfo(TestResultSet[] data, bool throwOnExecute, bool throwOnRead) { // Create a connection info and add the default connection to it - ISqlConnectionFactory factory = CreateMockFactory(data, throwOnRead); - ConnectionInfo ci = new ConnectionInfo(factory, Test.Common.Constants.OwnerUri, StandardConnectionDetails); + ISqlConnectionFactory factory = CreateMockFactory(data, throwOnExecute, throwOnRead); + ConnectionInfo ci = new ConnectionInfo(factory, Constants.OwnerUri, StandardConnectionDetails); ci.ConnectionTypeToConnectionMap[ConnectionType.Default] = factory.CreateSqlConnection(null); return ci; } - public static ConnectionInfo CreateConnectedConnectionInfo(TestResultSet[] data, bool throwOnRead, string type = ConnectionType.Default) + public static ConnectionInfo CreateConnectedConnectionInfo( + TestResultSet[] data, + bool throwOnExecute, + bool throwOnRead, + string type = ConnectionType.Default) { ConnectionService connectionService = ConnectionService.Instance; connectionService.OwnerToConnectionMap.Clear(); - connectionService.ConnectionFactory = CreateMockFactory(data, throwOnRead); + connectionService.ConnectionFactory = CreateMockFactory(data, throwOnExecute, throwOnRead); ConnectParams connectParams = new ConnectParams { Connection = StandardConnectionDetails, - OwnerUri = Test.Common.Constants.OwnerUri, + OwnerUri = Constants.OwnerUri, Type = type }; @@ -210,8 +213,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution #region Service Mocking - public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] data, - bool isConnected, bool throwOnRead, WorkspaceService workspaceService, + public static QueryExecutionService GetPrimedExecutionService( + TestResultSet[] data, + bool isConnected, + bool throwOnExecute, + bool throwOnRead, + WorkspaceService workspaceService, out ConcurrentDictionary storage) { // Create a place for the temp "files" to be written @@ -219,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // Mock the connection service var connectionService = new Mock(); - ConnectionInfo ci = CreateConnectedConnectionInfo(data, throwOnRead); + ConnectionInfo ci = CreateConnectedConnectionInfo(data, throwOnExecute, throwOnRead); ConnectionInfo outValMock; connectionService .Setup(service => service.TryFindConnection(It.IsAny(), out outValMock)) @@ -229,10 +236,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution return new QueryExecutionService(connectionService.Object, workspaceService) { BufferFileStreamFactory = MemoryFileSystem.GetFileStreamFactory(storage) }; } - public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] data, bool isConnected, bool throwOnRead, WorkspaceService workspaceService) + public static QueryExecutionService GetPrimedExecutionService( + TestResultSet[] data, + bool isConnected, + bool throwOnExecute, + bool throwOnRead, + WorkspaceService workspaceService) { ConcurrentDictionary storage; - return GetPrimedExecutionService(data, isConnected, throwOnRead, workspaceService, out storage); + return GetPrimedExecutionService(data, isConnected, throwOnExecute, throwOnRead, workspaceService, out storage); } public static WorkspaceService GetPrimedWorkspaceService(string query) diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/DisposeTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/DisposeTests.cs index 4e114b9c..56f480fc 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/DisposeTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/DisposeTests.cs @@ -40,7 +40,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I request a query (doesn't matter what kind) var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri}; var executeRequest = RequestContextMocks.Create(null); await queryService.HandleExecuteRequest(executeParams, executeRequest.Object); @@ -65,7 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I attempt to dispose a query that doesn't exist var workspaceService = new Mock>(); - var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService.Object); + var queryService = Common.GetPrimedExecutionService(null, false, false, false, workspaceService.Object); var disposeParams = new QueryDisposeParams {OwnerUri = Constants.OwnerUri}; var disposeRequest = new EventFlowValidator() @@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // Setup: // ... We need a query service var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); // If: // ... I execute some bogus query diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/BatchTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/BatchTests.cs index 4e5159c4..4a756edd 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/BatchTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/BatchTests.cs @@ -71,7 +71,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution b => batchEndCalls++, m => messages.Add(m), r => resultSetCalls++); - await batch.Execute(GetConnection(Common.CreateTestConnectionInfo(null, false)), CancellationToken.None); + await batch.Execute(GetConnection(Common.CreateTestConnectionInfo(null, false, false)), CancellationToken.None); // Then: // ... Callbacks should have been called the appropriate number of times @@ -97,7 +97,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // ... Build a data set to return const int resultSets = 1; - ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false, false); // If I execute a query that should get one result set var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); @@ -133,7 +133,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // ... Build a data set to return const int resultSets = 2; - ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false, false); // If I execute a query that should get two result sets var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); @@ -167,7 +167,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution List messages = new List(); // If I execute a batch that is invalid - var ci = Common.CreateTestConnectionInfo(null, true); + var ci = Common.CreateTestConnectionInfo(null, true, false); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); Batch batch = new Batch(Constants.StandardQuery, Common.SubsectionDocument, Common.Ordinal, fileStreamFactory); BatchCallbackHelper(batch, @@ -200,7 +200,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution { // Setup: Build a data set to return const int resultSets = 1; - ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(Common.GetTestDataSet(resultSets), false, false); // If I execute a batch var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/QueryTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/QueryTests.cs index da040ce9..aabba053 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/QueryTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/QueryTests.cs @@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution { // If: // ... I create a query - ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false, false); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(), fileStreamFactory); @@ -53,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // Then: // ... It should throw an exception Assert.Throws(() => - new Query("Some query", Common.CreateTestConnectionInfo(null, false), null, MemoryFileSystem.GetFileStreamFactory())); + new Query("Some query", Common.CreateTestConnectionInfo(null, false, false), null, MemoryFileSystem.GetFileStreamFactory())); } [Fact] @@ -64,7 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // Then: // ... It should throw an exception Assert.Throws(() => - new Query("Some query", Common.CreateTestConnectionInfo(null, false), new QueryExecutionSettings(), null)); + new Query("Some query", Common.CreateTestConnectionInfo(null, false, false), new QueryExecutionSettings(), null)); } [Fact] @@ -78,7 +78,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I create a query from a single batch (without separator) - ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false, false); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); Query query = new Query(Constants.StandardQuery, ci, new QueryExecutionSettings(), fileStreamFactory); BatchCallbackHelper(query, @@ -114,7 +114,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I create a query from a single batch that does nothing - ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false, false); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); Query query = new Query(Common.NoOpQuery, ci, new QueryExecutionSettings(), fileStreamFactory); BatchCallbackHelper(query, @@ -149,7 +149,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I create a query from two batches (with separator) - ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false); + ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false, false); string queryText = string.Format("{0}\r\nGO\r\n{0}", Constants.StandardQuery); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); @@ -190,7 +190,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I create a query from a two batches (with separator) - ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false); + ConnectionInfo ci = Common.CreateConnectedConnectionInfo(null, false, false); string queryText = string.Format("{0}\r\nGO\r\n{1}", Constants.StandardQuery, Common.NoOpQuery); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory); @@ -226,7 +226,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I create a query from a two batches (with separator) - ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false); + ConnectionInfo ci = Common.CreateTestConnectionInfo(null, false, false); string queryText = string.Format("{0}\r\nGO\r\n{1}", Common.NoOpQuery, Common.NoOpQuery); var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); Query query = new Query(queryText, ci, new QueryExecutionSettings(), fileStreamFactory); @@ -261,7 +261,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I create a query from an invalid batch - ConnectionInfo ci = Common.CreateTestConnectionInfo(null, true); + ConnectionInfo ci = Common.CreateTestConnectionInfo(null, true, false); ConnectionService.Instance.OwnerToConnectionMap[ci.OwnerUri] = ci; var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory(); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ResultSetTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ResultSetTests.cs index 2afc67cd..eb8e6fed 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ResultSetTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ResultSetTests.cs @@ -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(() => 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; diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ServiceIntegrationTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ServiceIntegrationTests.cs index 27f27cc0..ea7d787f 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ServiceIntegrationTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/Execution/ServiceIntegrationTests.cs @@ -204,7 +204,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a valid query with all batches as no op var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.NoOpQuery)); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri }; var efv = new EventFlowValidator() @@ -239,7 +239,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a valid query with no results var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri}; var efv = new EventFlowValidator() @@ -266,8 +266,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a valid query with results var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, - workspaceService); + var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument}; var efv = new EventFlowValidator() @@ -295,7 +294,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // ... I request to execute a valid query with one batch and multiple result sets var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); var dataset = new[] {Common.StandardTestResultSet, Common.StandardTestResultSet}; - var queryService = Common.GetPrimedExecutionService(dataset, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(dataset, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument}; var efv = new EventFlowValidator() @@ -322,7 +321,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request a to execute a valid query with multiple batches var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Constants.StandardQuery)); - var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument}; var efv = new EventFlowValidator() @@ -354,7 +353,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a query using a file URI that isn't connected var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, false, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = "notConnected", QuerySelection = Common.WholeDocument }; var efv = new EventFlowValidator() @@ -376,7 +375,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a query var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument}; // Note, we don't care about the results of the first request @@ -404,7 +403,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a query var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument}; // Note, we don't care about the results of the first request @@ -435,7 +434,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // If: // ... I request to execute a query that is invalid var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, true, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, true, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument}; var efv = new EventFlowValidator() @@ -458,7 +457,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution // [Fact] public async Task SimpleExecuteErrorWithNoResultsTest() { - var queryService = Common.GetPrimedExecutionService(null, true, false, null); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, null); var queryParams = new SimpleExecuteParams { OwnerUri = Constants.OwnerUri, QueryString = Constants.StandardQuery }; var efv = new EventFlowValidator() .AddSimpleExecuteErrorValidator(SR.QueryServiceResultSetHasNoResults) @@ -480,7 +479,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution [Fact] public async Task SimpleExecuteVerifyResultsTest() { - var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, null); + var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, null); var queryParams = new SimpleExecuteParams { OwnerUri = Constants.OwnerUri, QueryString = Constants.StandardQuery }; var efv = new EventFlowValidator() .AddSimpleExecuteQueryResultValidator(Common.StandardTestDataSet) @@ -504,7 +503,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution [Fact] public async Task SimpleExecuteMultipleQueriesTest() { - var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, null); + var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, null); var queryParams = new SimpleExecuteParams { OwnerUri = Constants.OwnerUri, QueryString = Constants.StandardQuery }; var efv1 = new EventFlowValidator() .AddSimpleExecuteQueryResultValidator(Common.StandardTestDataSet) diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/ExecutionPlanTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/ExecutionPlanTests.cs index ec6733ac..c0223c48 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/ExecutionPlanTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/ExecutionPlanTests.cs @@ -139,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I have a query that has results in the form of an execution plan var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, @@ -173,7 +173,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I ask for an execution plan for a file that hasn't executed a query var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0 }; var executionPlanRequest = new EventFlowValidator() .AddStandardErrorValidation() @@ -188,7 +188,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I have a query that hasn't finished executing (doesn't matter what) var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, @@ -219,7 +219,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I have a query that doesn't have any result sets var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ResultSetTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ResultSetTests.cs index 2f1ea00e..52690adc 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ResultSetTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ResultSetTests.cs @@ -93,7 +93,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults ResultSet rs = new ResultSet( Common.Ordinal, Common.Ordinal, resultFactory); - await rs.ReadResultToEnd(GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery), CancellationToken.None); + await rs.ReadResultToEnd(GetReader(Common.StandardTestDataSet, Constants.StandardQuery), CancellationToken.None); // ... Create a mock writer for writing the save as file Mock saveWriter = GetMockWriter(); @@ -125,7 +125,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults ResultSet rs = new ResultSet( Common.Ordinal, Common.Ordinal, resultFactory); - await rs.ReadResultToEnd(GetReader(Common.StandardTestDataSet, false, Constants.StandardQuery), CancellationToken.None); + await rs.ReadResultToEnd(GetReader(Common.StandardTestDataSet, Constants.StandardQuery), CancellationToken.None); // ... Create a mock writer for writing the save as file Mock saveWriter = GetMockWriter(); @@ -171,9 +171,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults return mockFactory.Object; } - private static DbDataReader GetReader(TestResultSet[] dataSet, bool throwOnRead, string query) + private static DbDataReader GetReader(TestResultSet[] dataSet, string query) { - var info = Common.CreateTestConnectionInfo(dataSet, throwOnRead); + var info = Common.CreateTestConnectionInfo(dataSet, false, false); var connection = info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails)); var command = connection.CreateCommand(); command.CommandText = query; diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ServiceIntegrationTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ServiceIntegrationTests.cs index 36fb4a6c..4f1a8334 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ServiceIntegrationTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SaveResults/ServiceIntegrationTests.cs @@ -30,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults { // Given: A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(null); - QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, ws); + QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, false, ws); // If: I attempt to save a result set from a query that doesn't exist SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams @@ -55,7 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults // ... A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary storage; - QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage); + QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; @@ -100,7 +100,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults // ... A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary storage; - QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage); + QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri}; @@ -142,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults { // Given: A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(null); - QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, ws); + QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, false, ws); // If: I attempt to save a result set from a query that doesn't exist SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams @@ -167,7 +167,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults // ... A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary storage; - QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage); + QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; @@ -210,7 +210,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults // ... A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary storage; - QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage); + QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; @@ -251,7 +251,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults { // Given: A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(null); - QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, ws); + QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, false, ws); // If: I attempt to save a result set from a query that doesn't exist SaveResultsAsExcelRequestParams saveParams = new SaveResultsAsExcelRequestParams @@ -276,7 +276,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults // ... A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary storage; - QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage); + QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; @@ -319,7 +319,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults // ... A working query and workspace service WorkspaceService ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary storage; - QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage); + QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SubsetTests.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SubsetTests.cs index b59dc0ae..5740dbae 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SubsetTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/QueryExecution/SubsetTests.cs @@ -132,7 +132,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I have a query that has results (doesn't matter what) var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Constants.OwnerUri}; var executeRequest = RequestContextMocks.Create(null); await queryService.HandleExecuteRequest(executeParams, executeRequest.Object); @@ -156,7 +156,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I ask for a set of results for a file that hasn't executed a query var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var subsetParams = new SubsetParams { OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 }; var subsetRequest = new EventFlowValidator() .AddStandardErrorValidation() @@ -171,7 +171,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I have a query that hasn't finished executing (doesn't matter what) var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; var executeRequest = RequestContextMocks.Create(null); await queryService.HandleExecuteRequest(executeParams, executeRequest.Object); @@ -193,7 +193,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution // If: // ... I have a query that doesn't have any result sets var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); - var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); + var queryService = Common.GetPrimedExecutionService(null, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; var executeRequest = RequestContextMocks.Create(null); await queryService.HandleExecuteRequest(executeParams, executeRequest.Object); diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ResourceProvider/Fakes/FakeDatabaseDiscoveryProvider.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ResourceProvider/Fakes/FakeDatabaseDiscoveryProvider.cs index 1c696584..f587173e 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ResourceProvider/Fakes/FakeDatabaseDiscoveryProvider.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/ResourceProvider/Fakes/FakeDatabaseDiscoveryProvider.cs @@ -20,9 +20,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Fakes public IExportableMetadata Metadata { get; set; } public ExportableStatus Status { get; } - IExportableMetadata IExportable.Metadata { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + IExportableMetadata IExportable.Metadata + { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } - ExportableStatus IExportable.Status => throw new NotImplementedException(); + ExportableStatus IExportable.Status + { + get { throw new NotImplementedException(); } + } public Task> GetDatabaseInstancesAsync(string serverName, CancellationToken cancellationToken) { diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs index d6ec82fb..3b02434d 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestDbDataReader.cs @@ -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 Data { get; } - public IEnumerator ResultSetEnumerator { get; } + private IEnumerator ResultSetEnumerator { get; } private IEnumerator RowEnumerator { get; set; } + + private bool ThrowOnRead { get; } - public TestDbDataReader(IEnumerable data) + public TestDbDataReader(IEnumerable data, bool throwOnRead) { + ThrowOnRead = throwOnRead; Data = data; if (Data != null) { @@ -59,6 +66,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility /// True if tere were more rows, false otherwise 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 /// Number of cells in the current row 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; } /// diff --git a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestObjects.cs b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestObjects.cs index c9cf078e..3afb7b50 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestObjects.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.UnitTests/Utility/TestObjects.cs @@ -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 listParams = new List();