mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
The goal of this make sure that test code is correctly organized to ensure that test suites aren't dependent on each other.
* UnitTests get their own project now (renaming Microsoft.SqlTools.ServiceLayer.Test to Microsoft.SqlTools.ServiceLayer.UnitTests) which is about 90% of the changes to the files.
* IntegrationTests no longer depends on UnitTests, only Test.Common
* Any shared components from TestObjects that spins up a "live" connection has been moved to IntegrationTests Utility/LiveConnectionHelper.cs
* The dictionary-based mock file stream factory has been moved to Test.Common since it is used by UnitTests and IntegrationTests
* Added a overload that doesn't take a dictionary for when we don't care about monitoring the storage (about 90% of the time)
* The RunIf* wrapper methods have been moved to Test.Common
* OwnerUri and StandardQuery constants have been moved to Test.Common Constants file
* Updating to latest SDK version available at https://www.microsoft.com/net/core#windowscmd
* Moving unit tests to unit test folder
* Changing namespaces to UnitTests
* Moving some constants and shared functionality into common project, making the UnitTests reference it
* Unit tests are working!
* Integration tests are working
* Updating automated test runs
* Fixing one last broken unit test
* Exposing internals for other projects
* Moving edit data tests to UnitTest project
* Applying refactor fixes to unit tests
* Fixing flaky test that wasn't awaiting completion
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 Xunit;
|
|
|
|
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>
|
|
[Fact]
|
|
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>
|
|
[Fact]
|
|
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>
|
|
[Fact]
|
|
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>
|
|
[Fact]
|
|
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 + '.'));
|
|
}
|
|
}
|
|
} |