mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 01:25:41 -05:00
Add more code coverage tests. (#129)
This commit is contained in:
@@ -834,7 +834,10 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
|
||||
summary2.DatabaseName = "tempdb";
|
||||
Assert.False(comparer.Equals(summary1, summary2));
|
||||
}
|
||||
Assert.False(comparer.Equals(null, summary2));
|
||||
|
||||
Assert.False(summary1.GetHashCode() == summary2.GetHashCode());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify when a connection is created that the URI -> Connection mapping is created in the connection service.
|
||||
|
||||
@@ -19,6 +19,7 @@ using Xunit;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.ReliableConnectionHelper;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.RetryPolicy.TimeBasedRetryPolicy;
|
||||
using static Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.SqlSchemaModelErrorCodes;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
{
|
||||
@@ -28,6 +29,31 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
/// </summary>
|
||||
public class ReliableConnectionTests
|
||||
{
|
||||
internal class TestDataTransferErrorDetectionStrategy : DataTransferErrorDetectionStrategy
|
||||
{
|
||||
public bool InvokeCanRetrySqlException(SqlException exception)
|
||||
{
|
||||
return CanRetrySqlException(exception);
|
||||
}
|
||||
}
|
||||
internal class TestSqlAzureTemporaryAndIgnorableErrorDetectionStrategy : SqlAzureTemporaryAndIgnorableErrorDetectionStrategy
|
||||
{
|
||||
public TestSqlAzureTemporaryAndIgnorableErrorDetectionStrategy()
|
||||
: base (new int[] { 100 })
|
||||
{
|
||||
}
|
||||
|
||||
public bool InvokeCanRetrySqlException(SqlException exception)
|
||||
{
|
||||
return CanRetrySqlException(exception);
|
||||
}
|
||||
|
||||
public bool InvokeShouldIgnoreSqlException(SqlException exception)
|
||||
{
|
||||
return ShouldIgnoreSqlException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
internal class TestFixedDelayPolicy : FixedDelayPolicy
|
||||
{
|
||||
public TestFixedDelayPolicy(
|
||||
@@ -613,6 +639,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
var command = new ReliableSqlConnection.ReliableSqlCommand(connection);
|
||||
Assert.NotNull(command.Connection);
|
||||
|
||||
var retryPolicy = connection.CommandRetryPolicy;
|
||||
connection.CommandRetryPolicy = retryPolicy;
|
||||
Assert.True(connection.CommandRetryPolicy == retryPolicy);
|
||||
connection.ChangeDatabase("master");
|
||||
Assert.True(connection.ConnectionTimeout > 0);
|
||||
connection.ClearPool();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -640,6 +672,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
|
||||
var errorReason = RetryPolicy.ThrottlingReason.FromError(sqlException.Errors[0]);
|
||||
Assert.NotNull(errorReason);
|
||||
|
||||
var detectionStrategy = new TestDataTransferErrorDetectionStrategy();
|
||||
Assert.True(detectionStrategy.InvokeCanRetrySqlException(sqlException));
|
||||
Assert.True(detectionStrategy.CanRetry(new InvalidOperationException()));
|
||||
Assert.False(detectionStrategy.ShouldIgnoreError(new InvalidOperationException()));
|
||||
|
||||
var detectionStrategy2 = new TestSqlAzureTemporaryAndIgnorableErrorDetectionStrategy();
|
||||
Assert.NotNull(detectionStrategy2.InvokeCanRetrySqlException(sqlException));
|
||||
Assert.NotNull(detectionStrategy2.InvokeShouldIgnoreSqlException(sqlException));
|
||||
}
|
||||
|
||||
var unknownCodeReason = RetryPolicy.ThrottlingReason.FromReasonCode(-1);
|
||||
@@ -656,6 +697,29 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
Assert.NotNull(codeReason.IsUnknown);
|
||||
Assert.NotNull(codeReason.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RetryErrorsTest()
|
||||
{
|
||||
var sqlServerRetryError = new SqlServerRetryError(
|
||||
"test message", new Exception(),
|
||||
1, 200, ErrorSeverity.Warning);
|
||||
Assert.True(sqlServerRetryError.RetryCount == 1);
|
||||
Assert.NotNull(SqlServerRetryError.FormatRetryMessage(1, TimeSpan.FromSeconds(15), new Exception()));
|
||||
Assert.NotNull(SqlServerRetryError.FormatIgnoreMessage(1, new Exception()));
|
||||
|
||||
var sqlServerError1 = new SqlServerError("test message", "document", ErrorSeverity.Warning);
|
||||
var sqlServerError2 = new SqlServerError("test message", "document", 1, ErrorSeverity.Warning);
|
||||
var sqlServerError3 = new SqlServerError(new Exception(), "document",1, ErrorSeverity.Warning);
|
||||
var sqlServerError4 = new SqlServerError("test message", "document", 1, 2, ErrorSeverity.Warning);
|
||||
var sqlServerError5 = new SqlServerError(new Exception(), "document", 1, 2, 3, ErrorSeverity.Warning);
|
||||
var sqlServerError6 = new SqlServerError("test message", "document", 1, 2, 3, ErrorSeverity.Warning);
|
||||
var sqlServerError7 = new SqlServerError("test message", new Exception(), "document", 1, 2, 3, ErrorSeverity.Warning);
|
||||
|
||||
Assert.True(SqlSchemaModelErrorCodes.IsParseErrorCode(46010));
|
||||
Assert.True(SqlSchemaModelErrorCodes.IsInterpretationErrorCode(Interpretation.InterpretationBaseCode+ 1));
|
||||
Assert.True(SqlSchemaModelErrorCodes.IsStatementFilterError(StatementFilter.StatementFilterBaseCode + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
||||
string shortXml = storageReader.GetXmlWithMaxCapacity(0, 2);
|
||||
Assert.True(shortXml.Length == 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate StringWriterWithMaxCapacity Write test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void StringWriterWithMaxCapacityTest()
|
||||
{
|
||||
var writer = new StorageDataReader.StringWriterWithMaxCapacity(null, 100);
|
||||
string output = "...";
|
||||
writer.Write(output);
|
||||
Assert.True(writer.ToString().Equals(output));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
{
|
||||
/// <summary>
|
||||
/// ScriptFile test case
|
||||
/// </summary>
|
||||
public class SrTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple "test" to access string resources
|
||||
/// The purpose of this test is for code coverage. It's probably better to just
|
||||
/// exclude string resources in the code coverage report than maintain this test.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SrStringsTest()
|
||||
{
|
||||
var culture = SR.Culture;
|
||||
SR.Culture = culture;
|
||||
Assert.True(SR.Culture == culture);
|
||||
|
||||
var connectionServiceListDbErrorNullOwnerUri = SR.ConnectionServiceListDbErrorNullOwnerUri;
|
||||
var connectionParamsValidateNullConnection = SR.ConnectionParamsValidateNullConnection;
|
||||
var credentialsServiceInvalidCriticalHandle = SR.CredentialsServiceInvalidCriticalHandle;
|
||||
var credentialsServicePasswordLengthExceeded = SR.CredentialsServicePasswordLengthExceeded;
|
||||
var credentialsServiceTargetForDelete = SR.CredentialsServiceTargetForDelete;
|
||||
var credentialsServiceTargetForLookup = SR.CredentialsServiceTargetForLookup;
|
||||
var queryServiceCancelDisposeFailed = SR.QueryServiceCancelDisposeFailed;
|
||||
var queryServiceQueryCancelled = SR.QueryServiceQueryCancelled;
|
||||
var queryServiceDataReaderByteCountInvalid = SR.QueryServiceDataReaderByteCountInvalid;
|
||||
var queryServiceDataReaderCharCountInvalid = SR.QueryServiceDataReaderCharCountInvalid;
|
||||
var queryServiceDataReaderXmlCountInvalid = SR.QueryServiceDataReaderXmlCountInvalid;
|
||||
var queryServiceFileWrapperReadOnly = SR.QueryServiceFileWrapperReadOnly;
|
||||
var queryServiceAffectedOneRow = SR.QueryServiceAffectedOneRow;
|
||||
var queryServiceMessageSenderNotSql = SR.QueryServiceMessageSenderNotSql;
|
||||
var queryServiceResultSetNotRead = SR.QueryServiceResultSetNotRead;
|
||||
var queryServiceResultSetNoColumnSchema = SR.QueryServiceResultSetNoColumnSchema;
|
||||
var connectionServiceListDbErrorNotConnected = SR.ConnectionServiceListDbErrorNotConnected("..");
|
||||
var connectionServiceConnStringInvalidAuthType = SR.ConnectionServiceConnStringInvalidAuthType("..");
|
||||
var connectionServiceConnStringInvalidIntent = SR.ConnectionServiceConnStringInvalidIntent("..");
|
||||
var queryServiceAffectedRows = SR.QueryServiceAffectedRows(10);
|
||||
var queryServiceErrorFormat = SR.QueryServiceErrorFormat(1, 1, 1, 1, "\n", "..");
|
||||
var queryServiceQueryFailed = SR.QueryServiceQueryFailed("..");
|
||||
var workspaceServiceBufferPositionOutOfOrder = SR.WorkspaceServiceBufferPositionOutOfOrder(1, 2, 3, 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user