mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-16 17:23:38 -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:
@@ -25,5 +25,34 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
longList.RemoveAt(0);
|
||||
Assert.True(longList.Count == 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add and remove and item in a LongList causing an expansion
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void LongListExpandTest()
|
||||
{
|
||||
var longList = new LongList<int>();
|
||||
longList.ExpandListSize = 3;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
longList.Add(i);
|
||||
}
|
||||
Assert.Equal(longList.Count, 6);
|
||||
Assert.NotNull(longList.GetItem(4));
|
||||
|
||||
bool didEnum = false;
|
||||
foreach (var j in longList)
|
||||
{
|
||||
didEnum = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.True(didEnum);
|
||||
|
||||
longList.RemoveAt(4);
|
||||
Assert.Equal(longList.Count, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
27
test/Microsoft.SqlTools.ServiceLayer.Test/Utility/SrTests.cs
Normal file
27
test/Microsoft.SqlTools.ServiceLayer.Test/Utility/SrTests.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.Test.Utility
|
||||
{
|
||||
public class SrTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Add and remove and item in a LongList
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SrPropertiesTest()
|
||||
{
|
||||
Assert.NotNull(new SR());
|
||||
Assert.NotNull(SR.QueryServiceSubsetBatchNotCompleted);
|
||||
Assert.NotNull(SR.QueryServiceFileWrapperWriteOnly);
|
||||
Assert.NotNull(SR.QueryServiceFileWrapperNotInitialized);
|
||||
Assert.NotNull(SR.QueryServiceColumnNull);
|
||||
Assert.NotNull(new SR.Keys());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Credentials;
|
||||
@@ -192,7 +194,7 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
return connInfo;
|
||||
}
|
||||
|
||||
public static ConnectionInfo InitLiveConnectionInfoForDefinition()
|
||||
public static ServerConnection InitLiveConnectionInfoForDefinition()
|
||||
{
|
||||
TestObjects.InitializeTestServices();
|
||||
|
||||
@@ -210,7 +212,9 @@ namespace Microsoft.SqlTools.Test.Utility
|
||||
|
||||
ConnectionInfo connInfo = null;
|
||||
connectionService.TryFindConnection(ownerUri, out connInfo);
|
||||
return connInfo;
|
||||
|
||||
SqlConnection sqlConn = new SqlConnection(ConnectionService.BuildConnectionString(connInfo.ConnectionDetails));
|
||||
return new ServerConnection(sqlConn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// 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 Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.Test.Utility
|
||||
{
|
||||
public class ValidateTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsWithinRangeTest()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Validate.IsWithinRange("parameterName", 1, 2, 3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsLessThanTest()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => Validate.IsLessThan("parameterName", 2, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsNotEqualTest()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => Validate.IsNotEqual<int>("parameterName", 1, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsNullOrWhiteSpaceTest()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => Validate.IsNotNullOrWhitespaceString("parameterName", null));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user