mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
Add tests to improve code coverage (#187)
* DbColumn and ReliableConnection tests * More retry connection tests * More tests * Fix broken peek definition integration tests * Fix test bug * Add a couple batch tests * Add some more tests * More tests for code coverage. * Validation and Diagnostic tests * A few more tests * A few mote test changes. * Update file path tests to run on Windows only
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#if LIVE_CONNECTION_TESTS
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
@@ -60,8 +61,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
||||
reader.Read();
|
||||
Assert.False(storageReader.IsDBNull(0));
|
||||
|
||||
Assert.NotNull(storageReader.GetValue(0));
|
||||
|
||||
string shortName = storageReader.GetCharsWithMaxCapacity(0, 2);
|
||||
Assert.True(shortName.Length == 2);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => storageReader.GetBytesWithMaxCapacity(0, 0));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => storageReader.GetCharsWithMaxCapacity(0, 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -88,10 +94,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.DataStorage
|
||||
[Fact]
|
||||
public void StringWriterWithMaxCapacityTest()
|
||||
{
|
||||
var writer = new StorageDataReader.StringWriterWithMaxCapacity(null, 100);
|
||||
var writer = new StorageDataReader.StringWriterWithMaxCapacity(null, 4);
|
||||
string output = "...";
|
||||
writer.Write(output);
|
||||
Assert.True(writer.ToString().Equals(output));
|
||||
writer.Write('.');
|
||||
Assert.True(writer.ToString().Equals(output + '.'));
|
||||
writer.Write(output);
|
||||
writer.Write('.');
|
||||
Assert.True(writer.ToString().Equals(output + '.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -388,8 +390,22 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Batch("stuff", Common.SubsectionDocument, -1, Common.GetFileStreamFactory(null)));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StatementCompletedHandlerTest()
|
||||
{
|
||||
// If:
|
||||
// ... I call the StatementCompletedHandler
|
||||
// Then:
|
||||
// ... a ResultMaessage should be logged in the resultsMessages collection
|
||||
Batch batch = new Batch(Common.StandardQuery, Common.SubsectionDocument, Common.Ordinal, Common.GetFileStreamFactory(null));
|
||||
batch.StatementCompletedHandler(null, new StatementCompletedEventArgs(1));
|
||||
Assert.True(batch.ResultMessages.Count() == 1);
|
||||
batch.StatementCompletedHandler(null, new StatementCompletedEventArgs(2));
|
||||
Assert.True(batch.ResultMessages.Count() == 2);
|
||||
}
|
||||
|
||||
private static DbConnection GetConnection(ConnectionInfo info)
|
||||
{
|
||||
return info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails));
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Data.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||
{
|
||||
/// <summary>
|
||||
/// DbColumnWrapper tests
|
||||
/// </summary>
|
||||
public class DbColumnWrapperTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Test DbColumn derived class
|
||||
/// </summary>
|
||||
class TestColumn : DbColumn
|
||||
{
|
||||
public TestColumn(
|
||||
string dataTypeName = null,
|
||||
int? columnSize = null,
|
||||
string columnName = null,
|
||||
string udtAssemblyQualifiedName = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(dataTypeName))
|
||||
{
|
||||
this.DataTypeName = dataTypeName;
|
||||
}
|
||||
|
||||
if (columnSize.HasValue)
|
||||
{
|
||||
this.ColumnSize = columnSize;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(columnName))
|
||||
{
|
||||
this.ColumnName = columnName;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(udtAssemblyQualifiedName))
|
||||
{
|
||||
this.UdtAssemblyQualifiedName = udtAssemblyQualifiedName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Basic data type and properites test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DataTypeAndPropertiesTest()
|
||||
{
|
||||
// check that data types array contains items
|
||||
var serverDataTypes = DbColumnWrapper.AllServerDataTypes;
|
||||
Assert.True(serverDataTypes.Count > 0);
|
||||
|
||||
// check default constructor doesn't throw
|
||||
Assert.NotNull(new DbColumnWrapper());
|
||||
|
||||
// check various properties are either null or not null
|
||||
var column = new TestColumn();
|
||||
var wrapper = new DbColumnWrapper(column);
|
||||
Assert.NotNull(wrapper.DataType);
|
||||
Assert.Null(wrapper.AllowDBNull);
|
||||
Assert.Null(wrapper.BaseCatalogName);
|
||||
Assert.Null(wrapper.BaseColumnName);
|
||||
Assert.Null(wrapper.BaseServerName);
|
||||
Assert.Null(wrapper.BaseTableName);
|
||||
Assert.Null(wrapper.ColumnOrdinal);
|
||||
Assert.Null(wrapper.ColumnSize);
|
||||
Assert.Null(wrapper.IsAliased);
|
||||
Assert.Null(wrapper.IsAutoIncrement);
|
||||
Assert.Null(wrapper.IsExpression);
|
||||
Assert.Null(wrapper.IsHidden);
|
||||
Assert.Null(wrapper.IsIdentity);
|
||||
Assert.Null(wrapper.IsKey);
|
||||
Assert.Null(wrapper. IsReadOnly);
|
||||
Assert.Null(wrapper.IsUnique);
|
||||
Assert.Null(wrapper.NumericPrecision);
|
||||
Assert.Null(wrapper.NumericScale);
|
||||
Assert.Null(wrapper.UdtAssemblyQualifiedName);
|
||||
Assert.Null(wrapper.DataTypeName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void DbColumnConstructorTests()
|
||||
{
|
||||
// check that various constructor parameters initial the wrapper correctly
|
||||
var w1 = new DbColumnWrapper(new TestColumn("varchar", int.MaxValue, "Microsoft SQL Server 2005 XML Showplan"));
|
||||
Assert.True(w1.IsXml);
|
||||
|
||||
var w2 = new DbColumnWrapper(new TestColumn("binary"));
|
||||
Assert.True(w2.IsBytes);
|
||||
|
||||
var w3 = new DbColumnWrapper(new TestColumn("varbinary", int.MaxValue));
|
||||
Assert.True(w3.IsBytes);
|
||||
|
||||
var w4 = new DbColumnWrapper(new TestColumn("sql_variant"));
|
||||
Assert.True(w4.IsSqlVariant);
|
||||
|
||||
var w5 = new DbColumnWrapper(new TestColumn("my_udt"));
|
||||
Assert.True(w5.IsUdt);
|
||||
|
||||
var w6 = new DbColumnWrapper(new TestColumn("my_hieracrchy", null, null, "MICROSOFT.SQLSERVER.TYPES.SQLHIERARCHYID"));
|
||||
Assert.True(w6.IsUdt);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user