mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
* Remove xunit dependency from testdriver * swap expected/actual as needed * Convert Test.Common to nunit * port hosting unit tests to nunit * port batchparser integration tests to nunit * port testdriver.tests to nunit * fix target to copy dependency * port servicelayer unittests to nunit * more unit test fixes * port integration tests to nunit * fix test method type * try using latest windows build for PRs * reduce test memory use
103 lines
3.6 KiB
C#
103 lines
3.6 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using System.Data.Common;
|
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
|
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
|
using NUnit.Framework;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.QueryExecution.DataStorage
|
|
{
|
|
public class StorageDataReaderTests
|
|
{
|
|
private StorageDataReader GetTestStorageDataReader(string query)
|
|
{
|
|
var result = LiveConnectionHelper.InitLiveConnectionInfo();
|
|
DbConnection connection;
|
|
result.ConnectionInfo.TryGetConnection(ConnectionType.Default, out connection);
|
|
|
|
var command = connection.CreateCommand();
|
|
command.CommandText = query;
|
|
DbDataReader reader = command.ExecuteReader();
|
|
|
|
return new StorageDataReader(reader);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate GetBytesWithMaxCapacity
|
|
/// </summary>
|
|
[Test]
|
|
public void GetBytesWithMaxCapacityTest()
|
|
{
|
|
var storageReader = GetTestStorageDataReader(
|
|
"SELECT CAST([name] as TEXT) As TextName FROM sys.all_columns");
|
|
DbDataReader reader = storageReader.DbDataReader;
|
|
|
|
reader.Read();
|
|
Assert.False(storageReader.IsDBNull(0));
|
|
|
|
byte[] bytes = storageReader.GetBytesWithMaxCapacity(0, 100);
|
|
Assert.NotNull(bytes);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate GetCharsWithMaxCapacity
|
|
/// </summary>
|
|
[Test]
|
|
public void GetCharsWithMaxCapacityTest()
|
|
{
|
|
var storageReader = GetTestStorageDataReader(
|
|
"SELECT name FROM sys.all_columns");
|
|
DbDataReader reader = storageReader.DbDataReader;
|
|
|
|
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>
|
|
/// Validate GetXmlWithMaxCapacity
|
|
/// </summary>
|
|
[Test]
|
|
public void GetXmlWithMaxCapacityTest()
|
|
{
|
|
var storageReader = GetTestStorageDataReader(
|
|
"SELECT CAST('<xml>Test XML context</xml>' AS XML) As XmlColumn");
|
|
DbDataReader reader = storageReader.DbDataReader;
|
|
|
|
reader.Read();
|
|
Assert.False(storageReader.IsDBNull(0));
|
|
|
|
string shortXml = storageReader.GetXmlWithMaxCapacity(0, 2);
|
|
Assert.True(shortXml.Length == 3);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate StringWriterWithMaxCapacity Write test
|
|
/// </summary>
|
|
[Test]
|
|
public void StringWriterWithMaxCapacityTest()
|
|
{
|
|
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 + '.'));
|
|
}
|
|
}
|
|
} |