mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-15 09:35:37 -05:00
Convert most tools service tests to nunit (#1037)
* 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
This commit is contained in:
@@ -14,13 +14,13 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
public class CancelTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CancelInProgressQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -46,12 +46,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... The query should not have been disposed but should have been cancelled
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.Equal(true, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(true, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
|
||||
cancelRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CancelExecutedQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -77,12 +77,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... The query should not have been disposed and cancel should not have excecuted
|
||||
Assert.NotEmpty(queryService.ActiveQueries);
|
||||
Assert.Equal(false, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
|
||||
Assert.That(queryService.ActiveQueries, Is.Not.Empty);
|
||||
Assert.AreEqual(false, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
|
||||
cancelRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CancelNonExistantTest()
|
||||
{
|
||||
// If:
|
||||
@@ -100,7 +100,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
cancelRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CancelQueryBeforeExecutionStartedTest()
|
||||
{
|
||||
// Setup query settings
|
||||
@@ -130,9 +130,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
await query.ExecutionTask;
|
||||
|
||||
// Validate that query has not been executed but cancelled and query failed called function was called
|
||||
Assert.Equal(true, query.HasCancelled);
|
||||
Assert.Equal(false, query.HasExecuted);
|
||||
Assert.Equal("Error Occured", errorMessage);
|
||||
Assert.AreEqual(true, query.HasCancelled);
|
||||
Assert.AreEqual(false, query.HasExecuted);
|
||||
Assert.AreEqual("Error Occured", errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,23 +11,23 @@ using System.Text.RegularExpressions;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
{
|
||||
public class SaveAsCsvFileStreamWriterTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("Something\rElse")]
|
||||
[InlineData("Something\nElse")]
|
||||
[InlineData("Something\"Else")]
|
||||
[InlineData("Something,Else")]
|
||||
[InlineData("\tSomething")]
|
||||
[InlineData("Something\t")]
|
||||
[InlineData(" Something")]
|
||||
[InlineData("Something ")]
|
||||
[InlineData(" \t\r\n\",\r\n\"\r ")]
|
||||
public void EncodeCsvFieldShouldWrap(string field)
|
||||
[Test]
|
||||
public void EncodeCsvFieldShouldWrap(
|
||||
[Values("Something\rElse",
|
||||
"Something\nElse",
|
||||
"Something\"Else",
|
||||
"Something,Else",
|
||||
"\tSomething",
|
||||
"Something\t",
|
||||
" Something",
|
||||
"Something ",
|
||||
" \t\r\n\",\r\n\"\r ")] string field)
|
||||
{
|
||||
// If: I CSV encode a field that has forbidden characters in it
|
||||
string output = SaveAsCsvFileStreamWriter.EncodeCsvField(field, ',', '\"');
|
||||
@@ -37,11 +37,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
&& Regex.IsMatch(output, ".*\"$"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("Something")]
|
||||
[InlineData("Something valid.")]
|
||||
[InlineData("Something\tvalid")]
|
||||
public void EncodeCsvFieldShouldNotWrap(string field)
|
||||
[Test]
|
||||
public void EncodeCsvFieldShouldNotWrap(
|
||||
[Values(
|
||||
"Something",
|
||||
"Something valid.",
|
||||
"Something\tvalid"
|
||||
)] string field)
|
||||
{
|
||||
// If: I CSV encode a field that does not have forbidden characters in it
|
||||
string output = SaveAsCsvFileStreamWriter.EncodeCsvField(field, ',', '\"');
|
||||
@@ -50,27 +52,27 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
Assert.False(Regex.IsMatch(output, "^\".*\"$"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void EncodeCsvFieldReplace()
|
||||
{
|
||||
// If: I CSV encode a field that has a double quote in it,
|
||||
string output = SaveAsCsvFileStreamWriter.EncodeCsvField("Some\"thing", ',', '\"');
|
||||
|
||||
// Then: It should be replaced with double double quotes
|
||||
Assert.Equal("\"Some\"\"thing\"", output);
|
||||
Assert.AreEqual("\"Some\"\"thing\"", output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void EncodeCsvFieldNull()
|
||||
{
|
||||
// If: I CSV encode a null
|
||||
string output = SaveAsCsvFileStreamWriter.EncodeCsvField(null, ',', '\"');
|
||||
|
||||
// Then: there should be a string version of null returned
|
||||
Assert.Equal("NULL", output);
|
||||
Assert.AreEqual("NULL", output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithoutColumnSelectionOrHeader()
|
||||
{
|
||||
// Setup:
|
||||
@@ -100,12 +102,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// Then: It should write one line with 2 items, comma delimited
|
||||
string outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
string[] lines = outputString.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
Assert.Equal(1, lines.Length);
|
||||
Assert.AreEqual(1, lines.Length);
|
||||
string[] values = lines[0].Split(',');
|
||||
Assert.Equal(2, values.Length);
|
||||
Assert.AreEqual(2, values.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithHeader()
|
||||
{
|
||||
// Setup:
|
||||
@@ -139,20 +141,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have written two lines
|
||||
string outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
string[] lines = outputString.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.AreEqual(2, lines.Length);
|
||||
|
||||
// ... It should have written a header line with two, comma separated names
|
||||
string[] headerValues = lines[0].Split(',');
|
||||
Assert.Equal(2, headerValues.Length);
|
||||
Assert.AreEqual(2, headerValues.Length);
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
Assert.Equal(columns[i].ColumnName, headerValues[i]);
|
||||
Assert.AreEqual(columns[i].ColumnName, headerValues[i]);
|
||||
}
|
||||
|
||||
// Note: No need to check values, it is done as part of the previous test
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithColumnSelection()
|
||||
{
|
||||
// Setup:
|
||||
@@ -194,26 +196,26 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have written two lines
|
||||
string outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
string[] lines = outputString.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.AreEqual(2, lines.Length);
|
||||
|
||||
// ... It should have written a header line with two, comma separated names
|
||||
string[] headerValues = lines[0].Split(',');
|
||||
Assert.Equal(2, headerValues.Length);
|
||||
Assert.AreEqual(2, headerValues.Length);
|
||||
for (int i = 1; i <= 2; i++)
|
||||
{
|
||||
Assert.Equal(columns[i].ColumnName, headerValues[i - 1]);
|
||||
Assert.AreEqual(columns[i].ColumnName, headerValues[i - 1]);
|
||||
}
|
||||
|
||||
// ... The second line should have two, comma separated values
|
||||
string[] dataValues = lines[1].Split(',');
|
||||
Assert.Equal(2, dataValues.Length);
|
||||
Assert.AreEqual(2, dataValues.Length);
|
||||
for (int i = 1; i <= 2; i++)
|
||||
{
|
||||
Assert.Equal(data[i].DisplayValue, dataValues[i - 1]);
|
||||
Assert.AreEqual(data[i].DisplayValue, dataValues[i - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithCustomDelimiters()
|
||||
{
|
||||
// Setup:
|
||||
@@ -248,20 +250,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have written two lines
|
||||
string outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
string[] lines = outputString.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.AreEqual(2, lines.Length);
|
||||
|
||||
// ... It should have written a header line with two, pipe("|") separated names
|
||||
string[] headerValues = lines[0].Split('|');
|
||||
Assert.Equal(2, headerValues.Length);
|
||||
Assert.AreEqual(2, headerValues.Length);
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
Assert.Equal(columns[i].ColumnName, headerValues[i]);
|
||||
Assert.AreEqual(columns[i].ColumnName, headerValues[i]);
|
||||
}
|
||||
|
||||
// Note: No need to check values, it is done as part of the previous tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowsWithCustomLineSeperator()
|
||||
{
|
||||
// Setup:
|
||||
@@ -301,7 +303,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have splitten the lines by system's default line seperator
|
||||
outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
lines = outputString.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.AreEqual(2, lines.Length);
|
||||
|
||||
// If: I set \n (line feed) as seperator and write a row
|
||||
requestParams.LineSeperator = "\n";
|
||||
@@ -316,7 +318,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have splitten the lines by \n
|
||||
outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
lines = outputString.Split(new[] { '\n' }, StringSplitOptions.None);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.AreEqual(2, lines.Length);
|
||||
|
||||
// If: I set \r\n (carriage return + line feed) as seperator and write a row
|
||||
requestParams.LineSeperator = "\r\n";
|
||||
@@ -331,11 +333,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have splitten the lines by \r\n
|
||||
outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
lines = outputString.Split(new[] { "\r\n" }, StringSplitOptions.None);
|
||||
Assert.Equal(2, lines.Length);
|
||||
Assert.AreEqual(2, lines.Length);
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithCustomTextIdentifier()
|
||||
{
|
||||
// Setup:
|
||||
@@ -373,10 +375,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// Then:
|
||||
// ... It should have splitten the columns by delimiter, embedded in text identifier when field contains delimiter or the text identifier
|
||||
string outputString = Encoding.UTF8.GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
Assert.Equal("\'item;1\';item,2;item\"3;\'item\'\'4\'", outputString);
|
||||
Assert.AreEqual("\'item;1\';item,2;item\"3;\'item\'\'4\'", outputString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithCustomEncoding()
|
||||
{
|
||||
// Setup:
|
||||
@@ -408,7 +410,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... It should have written the umlaut using the encoding Windows-1252
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
string outputString = Encoding.GetEncoding("Windows-1252").GetString(output).TrimEnd('\0', '\r', '\n');
|
||||
Assert.Equal("ü", outputString);
|
||||
Assert.AreEqual("ü", outputString);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
{
|
||||
@@ -86,36 +86,36 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
using (var reader = new StreamReader(zip.GetEntry(fileName).Open()))
|
||||
{
|
||||
string realContent = reader.ReadToEnd();
|
||||
Assert.Equal(referenceContent, realContent);
|
||||
Assert.AreEqual(referenceContent, realContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CheckContentType()
|
||||
{
|
||||
ContentMatch("[Content_Types].xml");
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CheckTopRels()
|
||||
{
|
||||
ContentMatch("_rels/.rels");
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CheckWorkbookRels()
|
||||
{
|
||||
ContentMatch("xl/_rels/workbook.xml.rels");
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CheckStyles()
|
||||
{
|
||||
ContentMatch("xl/styles.xml");
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CheckWorkbook()
|
||||
{
|
||||
ContentMatch("xl/workbook.xml");
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CheckSheet1()
|
||||
{
|
||||
ContentMatch("xl/worksheets/sheet1.xml");
|
||||
@@ -148,16 +148,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReferenceA1()
|
||||
{
|
||||
var xmlWriter = _xmlWriterMock.Object;
|
||||
var manager = new SaveAsExcelFileStreamWriterHelper.ReferenceManager(xmlWriter);
|
||||
manager.WriteAndIncreaseRowReference();
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("A1", LastWrittenReference);
|
||||
Assert.AreEqual("A1", LastWrittenReference);
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReferenceZ1()
|
||||
{
|
||||
var xmlWriter = _xmlWriterMock.Object;
|
||||
@@ -168,11 +168,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
manager.IncreaseColumnReference();
|
||||
}
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("Z1", LastWrittenReference);
|
||||
Assert.AreEqual("Z1", LastWrittenReference);
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("AA1", LastWrittenReference);
|
||||
Assert.AreEqual("AA1", LastWrittenReference);
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReferenceZZ1()
|
||||
{
|
||||
var xmlWriter = _xmlWriterMock.Object;
|
||||
@@ -184,11 +184,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
manager.IncreaseColumnReference();
|
||||
}
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("ZZ1", LastWrittenReference);
|
||||
Assert.AreEqual("ZZ1", LastWrittenReference);
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("AAA1", LastWrittenReference);
|
||||
Assert.AreEqual("AAA1", LastWrittenReference);
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReferenceXFD()
|
||||
{
|
||||
var xmlWriter = _xmlWriterMock.Object;
|
||||
@@ -202,31 +202,31 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
//The 16384 should be the maximal column and not throw
|
||||
manager.AssureColumnReference();
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("XFD1", LastWrittenReference);
|
||||
Assert.AreEqual("XFD1", LastWrittenReference);
|
||||
var ex = Assert.Throws<InvalidOperationException>(
|
||||
() => manager.AssureColumnReference());
|
||||
Assert.Contains("max column number is 16384", ex.Message);
|
||||
Assert.That(ex.Message, Does.Contain("max column number is 16384"));
|
||||
}
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReferenceRowReset()
|
||||
{
|
||||
var xmlWriter = _xmlWriterMock.Object;
|
||||
var manager = new SaveAsExcelFileStreamWriterHelper.ReferenceManager(xmlWriter);
|
||||
manager.WriteAndIncreaseRowReference();
|
||||
Assert.Equal(1, LastWrittenRow);
|
||||
Assert.AreEqual(1, LastWrittenRow);
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("A1", LastWrittenReference);
|
||||
Assert.AreEqual("A1", LastWrittenReference);
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("B1", LastWrittenReference);
|
||||
Assert.AreEqual("B1", LastWrittenReference);
|
||||
|
||||
//add row should reset column reference
|
||||
manager.WriteAndIncreaseRowReference();
|
||||
Assert.Equal(2, LastWrittenRow);
|
||||
Assert.AreEqual(2, LastWrittenRow);
|
||||
manager.WriteAndIncreaseColumnReference();
|
||||
Assert.Equal("A2", LastWrittenReference);
|
||||
Assert.AreEqual("A2", LastWrittenReference);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void AddRowMustBeCalledBeforeAddCellException()
|
||||
{
|
||||
var xmlWriter = _xmlWriterMock.Object;
|
||||
@@ -234,7 +234,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
|
||||
var ex = Assert.Throws<InvalidOperationException>(
|
||||
() => manager.AssureColumnReference());
|
||||
Assert.Contains("AddRow must be called before AddCell", ex.Message);
|
||||
Assert.That(ex.Message, Does.Contain("AddRow must be called before AddCell"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
{
|
||||
public class SaveAsJsonFileStreamWriterTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ArrayWrapperTest()
|
||||
{
|
||||
// Setup:
|
||||
@@ -34,10 +34,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... The output should be an empty array
|
||||
string outputString = Encoding.UTF8.GetString(output).TrimEnd('\0');
|
||||
object[] outputArray = JsonConvert.DeserializeObject<object[]>(outputString);
|
||||
Assert.Equal(0, outputArray.Length);
|
||||
Assert.AreEqual(0, outputArray.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithoutColumnSelection()
|
||||
{
|
||||
// Setup:
|
||||
@@ -74,19 +74,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
|
||||
// ... There should be 2 items in the array,
|
||||
// ... The item should have two fields, and two values, assigned appropriately
|
||||
Assert.Equal(2, outputObject.Length);
|
||||
Assert.AreEqual(2, outputObject.Length);
|
||||
foreach (var item in outputObject)
|
||||
{
|
||||
Assert.Equal(2, item.Count);
|
||||
Assert.AreEqual(2, item.Count);
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
Assert.True(item.ContainsKey(columns[i].ColumnName));
|
||||
Assert.Equal(data[i].RawObject == null ? null : data[i].DisplayValue, item[columns[i].ColumnName]);
|
||||
Assert.AreEqual(data[i].RawObject == null ? null : data[i].DisplayValue, item[columns[i].ColumnName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithColumnSelection()
|
||||
{
|
||||
// Setup:
|
||||
@@ -132,19 +132,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
|
||||
// ... There should be 2 items in the array
|
||||
// ... The items should have 2 fields and values
|
||||
Assert.Equal(2, outputObject.Length);
|
||||
Assert.AreEqual(2, outputObject.Length);
|
||||
foreach (var item in outputObject)
|
||||
{
|
||||
Assert.Equal(2, item.Count);
|
||||
Assert.AreEqual(2, item.Count);
|
||||
for (int i = 1; i <= 2; i++)
|
||||
{
|
||||
Assert.True(item.ContainsKey(columns[i].ColumnName));
|
||||
Assert.Equal(data[i].RawObject == null ? null : data[i].DisplayValue, item[columns[i].ColumnName]);
|
||||
Assert.AreEqual(data[i].RawObject == null ? null : data[i].DisplayValue, item[columns[i].ColumnName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriteRowWithSpecialTypesSuccess()
|
||||
{
|
||||
|
||||
@@ -186,14 +186,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
// ... There should be 2 items in the array,
|
||||
// ... The item should have three fields, and three values, assigned appropriately
|
||||
// ... The deserialized values should match the display value
|
||||
Assert.Equal(2, outputObject.Length);
|
||||
Assert.AreEqual(2, outputObject.Length);
|
||||
foreach (var item in outputObject)
|
||||
{
|
||||
Assert.Equal(3, item.Count);
|
||||
Assert.AreEqual(3, item.Count);
|
||||
for (int i = 0; i < columns.Count; i++)
|
||||
{
|
||||
Assert.True(item.ContainsKey(columns[i].ColumnName));
|
||||
Assert.Equal(data[i].RawObject == null ? null : data[i].DisplayValue, item[columns[i].ColumnName]);
|
||||
Assert.AreEqual(data[i].RawObject == null ? null : data[i].DisplayValue, item[columns[i].ColumnName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
{
|
||||
public class ServiceBufferReaderWriterTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReaderStreamNull()
|
||||
{
|
||||
// If: I create a service buffer file stream reader with a null stream
|
||||
@@ -29,7 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
Assert.Throws<ArgumentNullException>(() => new ServiceBufferFileStreamReader(null, new QueryExecutionSettings()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReaderSettingsNull()
|
||||
{
|
||||
// If: I create a service buffer file stream reader with null settings
|
||||
@@ -37,7 +37,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
Assert.Throws<ArgumentNullException>(() => new ServiceBufferFileStreamReader(Stream.Null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReaderInvalidStreamCannotRead()
|
||||
{
|
||||
// If: I create a service buffer file stream reader with a stream that cannot be read
|
||||
@@ -52,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReaderInvalidStreamCannotSeek()
|
||||
{
|
||||
// If: I create a service buffer file stream reader with a stream that cannot seek
|
||||
@@ -67,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriterStreamNull()
|
||||
{
|
||||
// If: I create a service buffer file stream writer with a null stream
|
||||
@@ -75,7 +75,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
Assert.Throws<ArgumentNullException>(() => new ServiceBufferFileStreamWriter(null, new QueryExecutionSettings()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriterSettingsNull()
|
||||
{
|
||||
// If: I create a service buffer file stream writer with null settings
|
||||
@@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
Assert.Throws<ArgumentNullException>(() => new ServiceBufferFileStreamWriter(Stream.Null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriterInvalidStreamCannotWrite()
|
||||
{
|
||||
// If: I create a service buffer file stream writer with a stream that cannot be read
|
||||
@@ -98,7 +98,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void WriterInvalidStreamCannotSeek()
|
||||
{
|
||||
// If: I create a service buffer file stream writer with a stream that cannot seek
|
||||
@@ -129,7 +129,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
using (ServiceBufferFileStreamWriter writer = new ServiceBufferFileStreamWriter(new MemoryStream(storage), overrideSettings))
|
||||
{
|
||||
int writtenBytes = writeFunc(writer, value);
|
||||
Assert.Equal(valueLength, writtenBytes);
|
||||
Assert.AreEqual(valueLength, writtenBytes);
|
||||
}
|
||||
|
||||
// ... And read the type T back
|
||||
@@ -140,78 +140,80 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
|
||||
// Then:
|
||||
Assert.Equal(value, outValue.Value.RawObject);
|
||||
Assert.Equal(valueLength, outValue.TotalLength);
|
||||
Assert.AreEqual(value, outValue.Value.RawObject);
|
||||
Assert.AreEqual(valueLength, outValue.TotalLength);
|
||||
Assert.NotNull(outValue.Value);
|
||||
|
||||
// ... The id we set should be stored in the returned db cell value
|
||||
Assert.Equal(rowId, outValue.Value.RowId);
|
||||
Assert.AreEqual(rowId, outValue.Value.RowId);
|
||||
|
||||
return outValue.Value.DisplayValue;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10)]
|
||||
[InlineData(-10)]
|
||||
[InlineData(short.MaxValue)] // Two byte number
|
||||
[InlineData(short.MinValue)] // Negative two byte number
|
||||
public void Int16(short value)
|
||||
[Test]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void Int16([Values(
|
||||
0,
|
||||
10,
|
||||
-10,
|
||||
short.MaxValue, // Two byte number
|
||||
short.MinValue // Negative two byte number
|
||||
)] short value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(short) + 1, value, (writer, val) => writer.WriteInt16(val), (reader, rowId) => reader.ReadInt16(0, rowId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10)]
|
||||
[InlineData(-10)]
|
||||
[InlineData(short.MaxValue)] // Two byte number
|
||||
[InlineData(short.MinValue)] // Negative two byte number
|
||||
[InlineData(int.MaxValue)] // Four byte number
|
||||
[InlineData(int.MinValue)] // Negative four byte number
|
||||
public void Int32(int value)
|
||||
[Test]
|
||||
public void Int32([Values(
|
||||
0,
|
||||
10,
|
||||
-10,
|
||||
short.MaxValue, // Two byte number
|
||||
short.MinValue, // Negative two byte number
|
||||
int.MaxValue, // Four byte number
|
||||
int.MinValue // Negative four byte number
|
||||
)] int value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(int) + 1, value, (writer, val) => writer.WriteInt32(val), (reader, rowId) => reader.ReadInt32(0, rowId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10)]
|
||||
[InlineData(-10)]
|
||||
[InlineData(short.MaxValue)] // Two byte number
|
||||
[InlineData(short.MinValue)] // Negative two byte number
|
||||
[InlineData(int.MaxValue)] // Four byte number
|
||||
[InlineData(int.MinValue)] // Negative four byte number
|
||||
[InlineData(long.MaxValue)] // Eight byte number
|
||||
[InlineData(long.MinValue)] // Negative eight byte number
|
||||
public void Int64(long value)
|
||||
[Test]
|
||||
public void Int64([Values(
|
||||
0,
|
||||
10,
|
||||
-10,
|
||||
short.MaxValue, // Two byte number
|
||||
short.MinValue, // Negative two byte number
|
||||
int.MaxValue, // Four byte number
|
||||
int.MinValue, // Negative four byte number
|
||||
long.MaxValue, // Eight byte number
|
||||
long.MinValue // Negative eight byte number
|
||||
)] long value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(long) + 1, value, (writer, val) => writer.WriteInt64(val), (reader, rowId) => reader.ReadInt64(0, rowId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10)]
|
||||
public void Byte(byte value)
|
||||
[Test]
|
||||
public void Byte([Values(0,10)] byte value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(byte) + 1, value, (writer, val) => writer.WriteByte(val), (reader, rowId) => reader.ReadByte(0, rowId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData('a')]
|
||||
[InlineData('1')]
|
||||
[InlineData((char)0x9152)] // Test something in the UTF-16 space
|
||||
public void Char(char value)
|
||||
[Test]
|
||||
public void Char([Values('a',
|
||||
'1',
|
||||
(char)0x9152)] // Test something in the UTF-16 space
|
||||
char value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(char) + 1, value, (writer, val) => writer.WriteChar(val), (reader, rowId) => reader.ReadChar(0, rowId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, true)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, false)]
|
||||
public void Boolean(bool value, bool preferNumeric)
|
||||
[Test]
|
||||
public void Boolean([Values] bool value, [Values] bool preferNumeric)
|
||||
{
|
||||
string displayValue = VerifyReadWrite(sizeof(bool) + 1, value,
|
||||
(writer, val) => writer.WriteBoolean(val),
|
||||
@@ -232,37 +234,39 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10.1)]
|
||||
[InlineData(-10.1)]
|
||||
[InlineData(float.MinValue)]
|
||||
[InlineData(float.MaxValue)]
|
||||
[InlineData(float.PositiveInfinity)]
|
||||
[InlineData(float.NegativeInfinity)]
|
||||
public void Single(float value)
|
||||
[Test]
|
||||
public void Single([Values(
|
||||
0,
|
||||
10.1F,
|
||||
-10.1F,
|
||||
float.MinValue,
|
||||
float.MaxValue,
|
||||
float.PositiveInfinity,
|
||||
float.NegativeInfinity
|
||||
)] float value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(float) + 1, value, (writer, val) => writer.WriteSingle(val), (reader, rowId) => reader.ReadSingle(0, rowId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(10.1)]
|
||||
[InlineData(-10.1)]
|
||||
[InlineData(float.MinValue)]
|
||||
[InlineData(float.MaxValue)]
|
||||
[InlineData(float.PositiveInfinity)]
|
||||
[InlineData(float.NegativeInfinity)]
|
||||
[InlineData(double.PositiveInfinity)]
|
||||
[InlineData(double.NegativeInfinity)]
|
||||
[InlineData(double.MinValue)]
|
||||
[InlineData(double.MaxValue)]
|
||||
public void Double(double value)
|
||||
[Test]
|
||||
public void Double([Values(
|
||||
0,
|
||||
10.1,
|
||||
-10.1,
|
||||
float.MinValue,
|
||||
float.MaxValue,
|
||||
float.PositiveInfinity,
|
||||
float.NegativeInfinity,
|
||||
double.PositiveInfinity,
|
||||
double.NegativeInfinity,
|
||||
double.MinValue,
|
||||
double.MaxValue
|
||||
)]double value)
|
||||
{
|
||||
VerifyReadWrite(sizeof(double) + 1, value, (writer, val) => writer.WriteDouble(val), (reader, rowId) => reader.ReadDouble(0, rowId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SqlDecimalTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -278,7 +282,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void Decimal()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -295,7 +299,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DateTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -318,7 +322,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DateTimeTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -341,15 +345,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
[InlineData(3)]
|
||||
[InlineData(4)]
|
||||
[InlineData(5)]
|
||||
[InlineData(6)]
|
||||
[InlineData(7)]
|
||||
public void DateTime2Test(int precision)
|
||||
[Test]
|
||||
public void DateTime2Test([Values(1,2,3,4,5,6,7)] int precision)
|
||||
{
|
||||
// Setup: Create some test values
|
||||
// NOTE: We are doing these here instead of InlineData because DateTime values can't be written as constant expressions
|
||||
@@ -379,7 +376,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DateTime2ZeroScaleTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -402,7 +399,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DateTime2InvalidScaleTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -426,7 +423,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DateTimeOffsetTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -446,7 +443,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void TimeSpanTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
@@ -462,7 +459,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void StringNullTest()
|
||||
{
|
||||
// Setup: Create a mock file stream
|
||||
@@ -479,13 +476,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, null)] // Test of empty string
|
||||
[InlineData(1, new[] { 'j' })]
|
||||
[InlineData(1, new[] { (char)0x9152 })]
|
||||
[InlineData(100, new[] { 'j', (char)0x9152 })] // Test alternating utf-16/ascii characters
|
||||
[InlineData(512, new[] { 'j', (char)0x9152 })] // Test that requires a 4 byte length
|
||||
public void StringTest(int length, char[] values)
|
||||
[Test, Sequential]
|
||||
public void StringTest([Values(0,1,1,100,512)] int length,
|
||||
[Values(null,
|
||||
new[] { 'j' },
|
||||
new[] { (char)0x9152 },
|
||||
new[] { 'j', (char)0x9152 }, // Test alternating utf-16/ascii characters
|
||||
new[] { 'j', (char)0x9152 })] // Test that requires a 4 byte length
|
||||
char[] values)
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate the test value
|
||||
@@ -500,7 +498,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
(reader, rowId) => reader.ReadString(0, rowId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BytesNullTest()
|
||||
{
|
||||
// Setup: Create a mock file stream wrapper
|
||||
@@ -517,13 +515,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, new byte[] { 0x00 })] // Test of empty byte[]
|
||||
[InlineData(1, new byte[] { 0x00 })]
|
||||
[InlineData(1, new byte[] { 0xFF })]
|
||||
[InlineData(100, new byte[] { 0x10, 0xFF, 0x00 })]
|
||||
[InlineData(512, new byte[] { 0x10, 0xFF, 0x00 })] // Test that requires a 4 byte length
|
||||
public void Bytes(int length, byte[] values)
|
||||
[Test, Sequential]
|
||||
public void Bytes([Values(0, 1, 1, 100, 512)] int length,
|
||||
[Values(new byte[] { 0x00 }, // Test of empty byte[]
|
||||
new byte[] { 0x00 },
|
||||
new byte[] { 0xFF },
|
||||
new byte[] { 0x10, 0xFF, 0x00 },
|
||||
new byte[] { 0x10, 0xFF, 0x00 } // Test that requires a 4 byte length
|
||||
)]
|
||||
byte[] values)
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate the test value
|
||||
@@ -539,26 +539,28 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.DataStorage
|
||||
(reader, rowId) => reader.ReadBytes(0, rowId));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> GuidTestParameters
|
||||
private static IEnumerable<Guid> GuidTestParameters
|
||||
{
|
||||
get
|
||||
{
|
||||
yield return new object[] {Guid.Empty};
|
||||
yield return new object[] {Guid.NewGuid()};
|
||||
yield return new object[] {Guid.NewGuid()};
|
||||
yield return Guid.Empty;
|
||||
yield return Guid.NewGuid();
|
||||
yield return Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GuidTestParameters))]
|
||||
public void GuidTest(Guid testValue)
|
||||
[Test]
|
||||
public void GuidTest()
|
||||
{
|
||||
VerifyReadWrite(testValue.ToByteArray().Length + 1, testValue,
|
||||
(writer, val) => writer.WriteGuid(testValue),
|
||||
(reader, rowId) => reader.ReadGuid(0, rowId));
|
||||
foreach (var testValue in GuidTestParameters)
|
||||
{
|
||||
VerifyReadWrite(testValue.ToByteArray().Length + 1, testValue,
|
||||
(writer, val) => writer.WriteGuid(testValue),
|
||||
(reader, rowId) => reader.ReadGuid(0, rowId));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void MoneyTest()
|
||||
{
|
||||
// Setup: Create some test values
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
public class DbCellValueTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructValid()
|
||||
{
|
||||
// If: I construct a new DbCellValue
|
||||
@@ -23,12 +23,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
};
|
||||
|
||||
// Then: It should have the values I specified in it
|
||||
Assert.Equal("qqq", dbc.DisplayValue);
|
||||
Assert.Equal(12, dbc.RawObject);
|
||||
Assert.AreEqual("qqq", dbc.DisplayValue);
|
||||
Assert.AreEqual(12, dbc.RawObject);
|
||||
Assert.True(dbc.IsNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CopyToNullOther()
|
||||
{
|
||||
// If: I copy a DbCellValue to null
|
||||
@@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
Assert.Throws<ArgumentNullException>(() => new DbCellValue().CopyTo(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CopyToValid()
|
||||
{
|
||||
// If: I copy a DbCellValue to another DbCellValue
|
||||
@@ -45,9 +45,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
source.CopyTo(dest);
|
||||
|
||||
// Then: The source values should be in the dest
|
||||
Assert.Equal(source.DisplayValue, dest.DisplayValue);
|
||||
Assert.Equal(source.IsNull, dest.IsNull);
|
||||
Assert.Equal(source.RawObject, dest.RawObject);
|
||||
Assert.AreEqual(source.DisplayValue, dest.DisplayValue);
|
||||
Assert.AreEqual(source.IsNull, dest.IsNull);
|
||||
Assert.AreEqual(source.RawObject, dest.RawObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
public class DisposeTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DisposeResultSet()
|
||||
{
|
||||
// Setup: Mock file stream factory, mock db reader
|
||||
@@ -34,7 +34,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
mockFileStreamFactory.Verify(fsf => fsf.DisposeFile(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task DisposeExecutedQuery()
|
||||
{
|
||||
// If:
|
||||
@@ -57,10 +57,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// Then:
|
||||
// ... And the active queries should be empty
|
||||
disposeRequest.Validate();
|
||||
Assert.Empty(queryService.ActiveQueries);
|
||||
Assert.That(queryService.ActiveQueries, Is.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryDisposeMissingQuery()
|
||||
{
|
||||
// If:
|
||||
@@ -78,7 +78,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
disposeRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ServiceDispose()
|
||||
{
|
||||
// Setup:
|
||||
@@ -95,14 +95,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;
|
||||
|
||||
// ... And it sticks around as an active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
|
||||
// ... The query execution service is disposed, like when the service is shutdown
|
||||
queryService.Dispose();
|
||||
|
||||
// Then:
|
||||
// ... There should no longer be an active query
|
||||
Assert.Empty(queryService.ActiveQueries);
|
||||
Assert.That(queryService.ActiveQueries, Is.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
public class BatchTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BatchCreationTest()
|
||||
{
|
||||
// If I create a new batch...
|
||||
@@ -30,32 +30,32 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... The text of the batch should be stored
|
||||
Assert.NotEmpty(batch.BatchText);
|
||||
Assert.That(batch.BatchText, Is.Not.Empty);
|
||||
|
||||
// ... It should not have executed and no error
|
||||
Assert.False(batch.HasExecuted, "The query should not have executed.");
|
||||
Assert.False(batch.HasError);
|
||||
|
||||
// ... The results should be empty
|
||||
Assert.Empty(batch.ResultSets);
|
||||
Assert.Empty(batch.ResultSummaries);
|
||||
Assert.That(batch.ResultSets, Is.Empty);
|
||||
Assert.That(batch.ResultSummaries, Is.Empty);
|
||||
|
||||
// ... The start line of the batch should be 0
|
||||
Assert.Equal(0, batch.Selection.StartLine);
|
||||
Assert.AreEqual(0, batch.Selection.StartLine);
|
||||
|
||||
// ... It's ordinal ID should be what I set it to
|
||||
Assert.Equal(Common.Ordinal, batch.Id);
|
||||
Assert.AreEqual(Common.Ordinal, batch.Id);
|
||||
|
||||
// ... The summary should have the same info
|
||||
Assert.Equal(Common.Ordinal, batch.Summary.Id);
|
||||
Assert.AreEqual(Common.Ordinal, batch.Summary.Id);
|
||||
Assert.Null(batch.Summary.ResultSetSummaries);
|
||||
Assert.Equal(0, batch.Summary.Selection.StartLine);
|
||||
Assert.NotEqual(default(DateTime).ToString("o"), batch.Summary.ExecutionStart); // Should have been set at construction
|
||||
Assert.AreEqual(0, batch.Summary.Selection.StartLine);
|
||||
Assert.That(batch.Summary.ExecutionStart, Is.Not.EqualTo(default(DateTime).ToString("o"))); // Should have been set at construction
|
||||
Assert.Null(batch.Summary.ExecutionEnd);
|
||||
Assert.Null(batch.Summary.ExecutionElapsed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteNoResultSets()
|
||||
{
|
||||
// Setup:
|
||||
@@ -77,9 +77,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... Callbacks should have been called the appropriate number of times
|
||||
Assert.Equal(1, batchStartCalls);
|
||||
Assert.Equal(1, batchEndCalls);
|
||||
Assert.Equal(0, resultSetCalls);
|
||||
Assert.AreEqual(1, batchStartCalls);
|
||||
Assert.AreEqual(1, batchEndCalls);
|
||||
Assert.AreEqual(0, resultSetCalls);
|
||||
|
||||
// ... The batch and the summary should be correctly assigned
|
||||
ValidateBatch(batch, 0, false);
|
||||
@@ -87,7 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
ValidateMessages(batch, 1, messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteOneResultSet()
|
||||
{
|
||||
// Setup:
|
||||
@@ -113,9 +113,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... Callbacks should have been called the appropriate number of times
|
||||
Assert.Equal(1, batchStartCalls);
|
||||
Assert.Equal(1, batchEndCalls);
|
||||
Assert.Equal(1, resultSetCalls);
|
||||
Assert.AreEqual(1, batchStartCalls);
|
||||
Assert.AreEqual(1, batchEndCalls);
|
||||
Assert.AreEqual(1, resultSetCalls);
|
||||
|
||||
// ... There should be exactly one result set
|
||||
ValidateBatch(batch, resultSets, false);
|
||||
@@ -123,7 +123,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
ValidateMessages(batch, 1, messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteTwoResultSets()
|
||||
{
|
||||
// Setup:
|
||||
@@ -149,9 +149,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... Callbacks should have been called the appropriate number of times
|
||||
Assert.Equal(1, batchStartCalls);
|
||||
Assert.Equal(1, batchEndCalls);
|
||||
Assert.Equal(2, resultSetCalls);
|
||||
Assert.AreEqual(1, batchStartCalls);
|
||||
Assert.AreEqual(1, batchEndCalls);
|
||||
Assert.AreEqual(2, resultSetCalls);
|
||||
|
||||
// ... It should have executed without error
|
||||
ValidateBatch(batch, resultSets, false);
|
||||
@@ -159,7 +159,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
ValidateMessages(batch, 1, messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteMultiExecutions()
|
||||
{
|
||||
// Setup:
|
||||
@@ -185,9 +185,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... Callbacks should have been called the appropriate number of times
|
||||
Assert.Equal(1, batchStartCalls);
|
||||
Assert.Equal(1, batchEndCalls);
|
||||
Assert.Equal(2, resultSetCalls);
|
||||
Assert.AreEqual(1, batchStartCalls);
|
||||
Assert.AreEqual(1, batchEndCalls);
|
||||
Assert.AreEqual(2, resultSetCalls);
|
||||
|
||||
// ... There should be exactly two result sets
|
||||
ValidateBatch(batch, 2, false);
|
||||
@@ -196,7 +196,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
ValidateMessages(batch, 2, messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteInvalidQuery()
|
||||
{
|
||||
// Setup:
|
||||
@@ -218,23 +218,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... Callbacks should have been called the appropriate number of times
|
||||
Assert.Equal(1, batchStartCalls);
|
||||
Assert.Equal(1, batchEndCalls);
|
||||
Assert.AreEqual(1, batchStartCalls);
|
||||
Assert.AreEqual(1, batchEndCalls);
|
||||
|
||||
// ... It should have executed with error
|
||||
ValidateBatch(batch, 0, true);
|
||||
ValidateBatchSummary(batch);
|
||||
|
||||
// ... There should be one error message returned
|
||||
Assert.Equal(1, messages.Count);
|
||||
Assert.All(messages, m =>
|
||||
{
|
||||
Assert.True(m.IsError);
|
||||
Assert.Equal(batch.Id, m.BatchId);
|
||||
});
|
||||
Assert.That(messages.Select(m => new { m.IsError, m.BatchId.Value }), Is.EqualTo(new[] { new { IsError = true, Value = batch.Id } }), "There should be one error message returned");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteInvalidQueryMultiExecutions()
|
||||
{
|
||||
// Setup:
|
||||
@@ -256,23 +250,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... Callbacks should have been called the appropriate number of times
|
||||
Assert.Equal(1, batchStartCalls);
|
||||
Assert.Equal(1, batchEndCalls);
|
||||
Assert.AreEqual(1, batchStartCalls);
|
||||
Assert.AreEqual(1, batchEndCalls);
|
||||
|
||||
// ... It should have executed with error
|
||||
ValidateBatch(batch, 0, true);
|
||||
ValidateBatchSummary(batch);
|
||||
|
||||
// ... There should be two error messages returned and 4 info messages (loop start/end, plus 2 for ignoring the error)
|
||||
Assert.Equal(6, messages.Count);
|
||||
Assert.All(messages, m =>
|
||||
{
|
||||
Assert.Equal(batch.Id, m.BatchId);
|
||||
});
|
||||
Assert.Equal(2, messages.Where(m => m.IsError).Count());
|
||||
Assert.AreEqual(6, messages.Count);
|
||||
Assert.That(messages.Select(m => m.BatchId), Is.EquivalentTo(new[] { batch.Id, batch.Id, batch.Id, batch.Id, batch.Id, batch.Id }));
|
||||
Assert.That(messages.Select(m => m.IsError), Has.Exactly(2).True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecuteExecuted()
|
||||
{
|
||||
// Setup: Build a data set to return
|
||||
@@ -296,7 +287,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
b => { throw new Exception("Batch completion callback should not have been called"); },
|
||||
m => { throw new Exception("Message callback should not have been called"); },
|
||||
null);
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => batch.Execute(GetConnection(ci), CancellationToken.None));
|
||||
|
||||
// ... The data should still be available without error
|
||||
@@ -304,10 +295,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
ValidateBatchSummary(batch);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
public void BatchExecuteNoSql(string query)
|
||||
[Test]
|
||||
public void BatchExecuteNoSql([Values(null, "")] string query)
|
||||
{
|
||||
// If:
|
||||
// ... I create a batch that has an empty query
|
||||
@@ -316,7 +305,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.Throws<ArgumentException>(() => new Batch(query, Common.SubsectionDocument, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BatchNoBufferFactory()
|
||||
{
|
||||
// If:
|
||||
@@ -326,7 +315,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.Throws<ArgumentNullException>(() => new Batch("stuff", Common.SubsectionDocument, Common.Ordinal, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BatchInvalidOrdinal()
|
||||
{
|
||||
// If:
|
||||
@@ -336,7 +325,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Batch("stuff", Common.SubsectionDocument, -1, MemoryFileSystem.GetFileStreamFactory()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void StatementCompletedHandlerTest()
|
||||
{
|
||||
// If:
|
||||
@@ -357,7 +346,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.True(messageCalls == 2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ServerMessageHandlerShowsErrorMessages()
|
||||
{
|
||||
// Set up the batch to track message calls
|
||||
@@ -384,14 +373,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
await batch.HandleSqlErrorMessage(1, 15, 0, 1, string.Empty, errorMessage);
|
||||
|
||||
// Then one error message call should be recorded
|
||||
Assert.Equal(1, errorMessageCalls);
|
||||
Assert.Equal(0, infoMessageCalls);
|
||||
Assert.AreEqual(1, errorMessageCalls);
|
||||
Assert.AreEqual(0, infoMessageCalls);
|
||||
|
||||
// And the actual message should be a formatted version of the error message
|
||||
Assert.True(actualMessage.Length > errorMessage.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ServerMessageHandlerShowsInfoMessages()
|
||||
{
|
||||
// Set up the batch to track message calls
|
||||
@@ -418,11 +407,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
await batch.HandleSqlErrorMessage(0, 0, 0, 1, string.Empty, infoMessage);
|
||||
|
||||
// Then one info message call should be recorded
|
||||
Assert.Equal(0, errorMessageCalls);
|
||||
Assert.Equal(1, infoMessageCalls);
|
||||
Assert.AreEqual(0, errorMessageCalls);
|
||||
Assert.AreEqual(1, infoMessageCalls);
|
||||
|
||||
// And the actual message should be the exact info message
|
||||
Assert.Equal(infoMessage, actualMessage);
|
||||
Assert.AreEqual(infoMessage, actualMessage);
|
||||
}
|
||||
|
||||
private static DbConnection GetConnection(ConnectionInfo info)
|
||||
@@ -441,15 +430,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.NotNull(batch.ResultSummaries);
|
||||
|
||||
// Make sure the number of result sets matches
|
||||
Assert.Equal(expectedResultSets, batch.ResultSets.Count);
|
||||
Assert.AreEqual(expectedResultSets, batch.ResultSets.Count);
|
||||
for (int i = 0; i < expectedResultSets; i++)
|
||||
{
|
||||
Assert.Equal(i, batch.ResultSets[i].Id);
|
||||
Assert.AreEqual(i, batch.ResultSets[i].Id);
|
||||
}
|
||||
Assert.Equal(expectedResultSets, batch.ResultSummaries.Length);
|
||||
Assert.AreEqual(expectedResultSets, batch.ResultSummaries.Length);
|
||||
|
||||
// Make sure that the error state is set properly
|
||||
Assert.Equal(isError, batch.HasError);
|
||||
Assert.AreEqual(isError, batch.HasError);
|
||||
}
|
||||
|
||||
private static void ValidateBatchSummary(Batch batch)
|
||||
@@ -457,10 +446,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
BatchSummary batchSummary = batch.Summary;
|
||||
|
||||
Assert.NotNull(batchSummary);
|
||||
Assert.Equal(batch.Id, batchSummary.Id);
|
||||
Assert.Equal(batch.ResultSets.Count, batchSummary.ResultSetSummaries.Length);
|
||||
Assert.Equal(batch.Selection, batchSummary.Selection);
|
||||
Assert.Equal(batch.HasError, batchSummary.HasError);
|
||||
Assert.AreEqual(batch.Id, batchSummary.Id);
|
||||
Assert.AreEqual(batch.ResultSets.Count, batchSummary.ResultSetSummaries.Length);
|
||||
Assert.AreEqual(batch.Selection, batchSummary.Selection);
|
||||
Assert.AreEqual(batch.HasError, batchSummary.HasError);
|
||||
|
||||
// Something other than default date is provided for start and end times
|
||||
Assert.True(DateTime.Parse(batchSummary.ExecutionStart) > default(DateTime));
|
||||
@@ -472,15 +461,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
private static void ValidateMessages(Batch batch, int expectedMessages, IList<ResultMessage> messages)
|
||||
{
|
||||
// There should be equal number of messages to result sets
|
||||
Assert.Equal(expectedMessages, messages.Count);
|
||||
Assert.AreEqual(expectedMessages, messages.Count);
|
||||
|
||||
// No messages should be errors
|
||||
// All messages must have the batch ID
|
||||
Assert.All(messages, m =>
|
||||
{
|
||||
Assert.False(m.IsError);
|
||||
Assert.Equal(batch.Id, m.BatchId);
|
||||
});
|
||||
Assert.That(messages.Select(m => new { m.IsError, m.BatchId.Value }), Has.All.EqualTo(new { IsError = false, Value = batch.Id }));
|
||||
}
|
||||
|
||||
private static void BatchCallbackHelper(Batch batch, Action<Batch> startCallback, Action<Batch> endCallback,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
using System.Data.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
@@ -55,7 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
/// <summary>
|
||||
/// Basic data type and properties test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DataTypeAndPropertiesTest()
|
||||
{
|
||||
// check default constructor doesn't throw
|
||||
@@ -89,7 +89,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
/// <summary>
|
||||
/// constructor test
|
||||
/// </summary>
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DbColumnConstructorTests()
|
||||
{
|
||||
// check that various constructor parameters initial the wrapper correctly
|
||||
|
||||
@@ -12,14 +12,14 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
public class QueryTests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryCreationCorrect()
|
||||
{
|
||||
// If:
|
||||
@@ -30,12 +30,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... I should get back two batches to execute that haven't been executed
|
||||
Assert.NotEmpty(query.QueryText);
|
||||
Assert.That(query.QueryText, Is.Not.Empty);
|
||||
Assert.False(query.HasExecuted);
|
||||
Assert.Throws<InvalidOperationException>(() => query.BatchSummaries);
|
||||
Assert.Throws<InvalidOperationException>(() => { var x = query.BatchSummaries; });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryExecuteNoConnectionInfo()
|
||||
{
|
||||
// If:
|
||||
@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
Assert.Throws<ArgumentNullException>(() => new Query("Some Query", null, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryExecuteNoSettings()
|
||||
{
|
||||
// If:
|
||||
@@ -56,7 +56,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
new Query("Some query", Common.CreateTestConnectionInfo(null, false, false), null, MemoryFileSystem.GetFileStreamFactory()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryExecuteNoBufferFactory()
|
||||
{
|
||||
// If:
|
||||
@@ -67,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
new Query("Some query", Common.CreateTestConnectionInfo(null, false, false), new QueryExecutionSettings(), null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryExecuteSingleBatch()
|
||||
{
|
||||
// Setup:
|
||||
@@ -92,21 +92,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... There should be exactly 1 batch
|
||||
Assert.NotEmpty(query.Batches);
|
||||
Assert.Equal(1, query.Batches.Length);
|
||||
Assert.That(query.Batches, Is.Not.Empty);
|
||||
Assert.AreEqual(1, query.Batches.Length);
|
||||
|
||||
// ... The query should have completed successfully with one batch summary returned
|
||||
Assert.True(query.HasExecuted);
|
||||
Assert.NotEmpty(query.BatchSummaries);
|
||||
Assert.Equal(1, query.BatchSummaries.Length);
|
||||
Assert.That(query.BatchSummaries, Is.Not.Empty);
|
||||
Assert.AreEqual(1, query.BatchSummaries.Length);
|
||||
|
||||
// ... The batch callbacks should have been called precisely 1 time
|
||||
Assert.Equal(1, batchStartCallbacksReceived);
|
||||
Assert.Equal(1, batchCompleteCallbacksReceived);
|
||||
Assert.Equal(1, batchMessageCallbacksReceived);
|
||||
Assert.AreEqual(1, batchStartCallbacksReceived);
|
||||
Assert.AreEqual(1, batchCompleteCallbacksReceived);
|
||||
Assert.AreEqual(1, batchMessageCallbacksReceived);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteSingleNoOpBatch()
|
||||
{
|
||||
// Setup: Keep track of all the messages received
|
||||
@@ -129,16 +129,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... There should be no batches
|
||||
Assert.Equal(1, query.Batches.Length);
|
||||
Assert.AreEqual(1, query.Batches.Length);
|
||||
|
||||
// ... The query shouldn't have completed successfully
|
||||
Assert.False(query.HasExecuted);
|
||||
|
||||
// ... The message callback should have been called 0 times
|
||||
Assert.Equal(0, messages.Count);
|
||||
Assert.AreEqual(0, messages.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryExecuteMultipleResultBatches()
|
||||
{
|
||||
// Setup:
|
||||
@@ -165,21 +165,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... I should get back a query with one batch (no op batch is not included)
|
||||
Assert.NotEmpty(query.Batches);
|
||||
Assert.Equal(2, query.Batches.Length);
|
||||
Assert.That(query.Batches, Is.Not.Empty);
|
||||
Assert.AreEqual(2, query.Batches.Length);
|
||||
|
||||
// ... The query should have completed successfully with two batch summaries returned
|
||||
Assert.True(query.HasExecuted);
|
||||
Assert.NotEmpty(query.BatchSummaries);
|
||||
Assert.Equal(2, query.BatchSummaries.Length);
|
||||
Assert.That(query.BatchSummaries, Is.Not.Empty);
|
||||
Assert.AreEqual(2, query.BatchSummaries.Length);
|
||||
|
||||
// ... The batch start, complete, and message callbacks should have been called precisely 2 times
|
||||
Assert.Equal(2, batchStartCallbacksReceived);
|
||||
Assert.Equal(2, batchCompletedCallbacksReceived);
|
||||
Assert.Equal(2, batchMessageCallbacksReceived);
|
||||
Assert.AreEqual(2, batchStartCallbacksReceived);
|
||||
Assert.AreEqual(2, batchCompletedCallbacksReceived);
|
||||
Assert.AreEqual(2, batchMessageCallbacksReceived);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteMultipleBatchesWithNoOp()
|
||||
{
|
||||
// Setup:
|
||||
@@ -205,19 +205,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... I should get back a query with two batches
|
||||
Assert.NotEmpty(query.Batches);
|
||||
Assert.Equal(2, query.Batches.Length);
|
||||
Assert.That(query.Batches, Is.Not.Empty);
|
||||
Assert.AreEqual(2, query.Batches.Length);
|
||||
|
||||
// ... The query should have completed successfully
|
||||
Assert.True(query.HasExecuted);
|
||||
|
||||
// ... The batch callbacks should have been called 2 times (for each no op batch)
|
||||
Assert.Equal(2, batchStartCallbacksReceived);
|
||||
Assert.Equal(2, batchCompletionCallbacksReceived);
|
||||
Assert.Equal(2, batchMessageCallbacksReceived);
|
||||
Assert.AreEqual(2, batchStartCallbacksReceived);
|
||||
Assert.AreEqual(2, batchCompletionCallbacksReceived);
|
||||
Assert.AreEqual(2, batchMessageCallbacksReceived);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteMultipleNoOpBatches()
|
||||
{
|
||||
// Setup:
|
||||
@@ -241,16 +241,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... I should get back a query with no batches
|
||||
Assert.Equal(2, query.Batches.Length);
|
||||
Assert.AreEqual(2, query.Batches.Length);
|
||||
|
||||
// ... The query shouldn't have completed successfully
|
||||
Assert.False(query.HasExecuted);
|
||||
|
||||
// ... The message callback should have been called exactly once
|
||||
Assert.Equal(0, messages.Count);
|
||||
Assert.AreEqual(0, messages.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void QueryExecuteInvalidBatch()
|
||||
{
|
||||
// Setup:
|
||||
@@ -277,18 +277,18 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... I should get back a query with one batch
|
||||
Assert.NotEmpty(query.Batches);
|
||||
Assert.Equal(1, query.Batches.Length);
|
||||
Assert.That(query.Batches, Is.Not.Empty);
|
||||
Assert.AreEqual(1, query.Batches.Length);
|
||||
|
||||
// ... There should be an error on the batch
|
||||
Assert.True(query.HasExecuted);
|
||||
Assert.NotEmpty(query.BatchSummaries);
|
||||
Assert.Equal(1, query.BatchSummaries.Length);
|
||||
Assert.That(query.BatchSummaries, Is.Not.Empty);
|
||||
Assert.AreEqual(1, query.BatchSummaries.Length);
|
||||
Assert.True(messages.Any(m => m.IsError));
|
||||
|
||||
// ... The batch callbacks should have been called once
|
||||
Assert.Equal(1, batchStartCallbacksReceived);
|
||||
Assert.Equal(1, batchCompletionCallbacksReceived);
|
||||
Assert.AreEqual(1, batchStartCallbacksReceived);
|
||||
Assert.AreEqual(1, batchCompletionCallbacksReceived);
|
||||
}
|
||||
|
||||
private static void BatchCallbackHelper(Query q, Action<Batch> startCallback, Action<Batch> endCallback,
|
||||
|
||||
@@ -17,13 +17,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
public class ResultSetTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ResultCreation()
|
||||
{
|
||||
// If:
|
||||
@@ -33,32 +33,32 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// Then:
|
||||
// ... There should not be any data read yet
|
||||
Assert.Null(resultSet.Columns);
|
||||
Assert.Equal(0, resultSet.RowCount);
|
||||
Assert.Equal(Common.Ordinal, resultSet.Id);
|
||||
Assert.AreEqual(0, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.Ordinal, resultSet.Id);
|
||||
|
||||
// ... The summary should include the same info
|
||||
Assert.Null(resultSet.Summary.ColumnInfo);
|
||||
Assert.Equal(0, resultSet.Summary.RowCount);
|
||||
Assert.Equal(Common.Ordinal, resultSet.Summary.Id);
|
||||
Assert.Equal(Common.Ordinal, resultSet.Summary.BatchId);
|
||||
Assert.AreEqual(0, resultSet.Summary.RowCount);
|
||||
Assert.AreEqual(Common.Ordinal, resultSet.Summary.Id);
|
||||
Assert.AreEqual(Common.Ordinal, resultSet.Summary.BatchId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ReadToEndNullReader()
|
||||
{
|
||||
// If: I create a new result set with a null db data reader
|
||||
// Then: I should get an exception
|
||||
var fsf = MemoryFileSystem.GetFileStreamFactory();
|
||||
ResultSet resultSet = new ResultSet(Common.Ordinal, Common.Ordinal, fsf);
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => resultSet.ReadResultToEnd(null, CancellationToken.None));
|
||||
Assert.ThrowsAsync<ArgumentNullException>(() => resultSet.ReadResultToEnd(null, CancellationToken.None));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read to End test
|
||||
/// </summary>
|
||||
/// <param name="testDataSet"></param>
|
||||
[Theory]
|
||||
[MemberData(nameof(ReadToEndSuccessData), parameters: 6)]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(ReadToEndSuccessData))]
|
||||
public async Task ReadToEndSuccess(TestResultSet[] testDataSet)
|
||||
{
|
||||
// Setup: Create a results Available callback for result set
|
||||
@@ -113,13 +113,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// ... The columns should be set
|
||||
// ... There should be rows to read back
|
||||
Assert.NotNull(resultSet.Columns);
|
||||
Assert.Equal(Common.StandardColumns, resultSet.Columns.Length);
|
||||
Assert.Equal(testDataSet[0].Rows.Count, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.StandardColumns, resultSet.Columns.Length);
|
||||
Assert.AreEqual(testDataSet[0].Rows.Count, resultSet.RowCount);
|
||||
|
||||
// ... The summary should have the same info
|
||||
Assert.NotNull(resultSet.Summary.ColumnInfo);
|
||||
Assert.Equal(Common.StandardColumns, resultSet.Summary.ColumnInfo.Length);
|
||||
Assert.Equal(testDataSet[0].Rows.Count, resultSet.Summary.RowCount);
|
||||
Assert.AreEqual(Common.StandardColumns, resultSet.Summary.ColumnInfo.Length);
|
||||
Assert.AreEqual(testDataSet[0].Rows.Count, resultSet.Summary.RowCount);
|
||||
|
||||
// and:
|
||||
//
|
||||
@@ -130,11 +130,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
/// Read to End test
|
||||
/// </summary>
|
||||
/// <param name="testDataSet"></param>
|
||||
[Theory]
|
||||
[MemberData(nameof(ReadToEndSuccessData), parameters: 3)]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(ReadToEndSuccessDataParallel))]
|
||||
public async Task ReadToEndSuccessSeveralTimes(TestResultSet[] testDataSet)
|
||||
{
|
||||
const int NumberOfInvocations = 5000;
|
||||
const int NumberOfInvocations = 50;
|
||||
List<Task> allTasks = new List<Task>();
|
||||
Parallel.ForEach(Partitioner.Create(0, NumberOfInvocations), (range) =>
|
||||
{
|
||||
@@ -149,21 +149,18 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
await Task.WhenAll(allTasks);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ReadToEndSuccessData(int numTests) => Common.TestResultSetsEnumeration.Select(r => new object[] { new TestResultSet[] { r } }).Take(numTests);
|
||||
public static readonly IEnumerable<object[]> ReadToEndSuccessData = Common.TestResultSetsEnumeration.Select(r => new object[] { new TestResultSet[] { r } }).Take(6);
|
||||
// using all 6 sets with the parallel test can raise an OutOfMemoryException
|
||||
public static readonly IEnumerable<object[]> ReadToEndSuccessDataParallel = Common.TestResultSetsEnumeration.Select(r => new object[] { new TestResultSet[] { r } }).Take(3);
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CallMethodWithoutReadingData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(CallMethodWithoutReadingData))]
|
||||
public void CallMethodWithoutReading(Action<ResultSet> testMethod)
|
||||
{
|
||||
// Setup: Create a new result set with valid db data reader
|
||||
var fileStreamFactory = MemoryFileSystem.GetFileStreamFactory();
|
||||
ResultSet resultSet = new ResultSet(Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||
|
||||
// If:
|
||||
// ... I have a result set that has not been read
|
||||
// ... and I attempt to call a method on it
|
||||
// Then: It should throw an exception
|
||||
Assert.ThrowsAny<Exception>(() => testMethod(resultSet));
|
||||
Assert.That(() => testMethod(resultSet), Throws.InstanceOf<Exception>(), "I have a result set that has not been read. I attempt to call a method on it. It should throw an exception");
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> CallMethodWithoutReadingData
|
||||
@@ -239,10 +236,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
/// </summary>
|
||||
/// <param name="forType"></param>
|
||||
/// <returns></returns>
|
||||
[Theory]
|
||||
[InlineData("JSON")]
|
||||
[InlineData("XML")]
|
||||
public async Task ReadToEndForXmlJson(string forType)
|
||||
[Test]
|
||||
public async Task ReadToEndForXmlJson([Values("JSON", "XML")] string forType)
|
||||
{
|
||||
// Setup:
|
||||
// ... Build a FOR XML or FOR JSON data set
|
||||
@@ -306,8 +301,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// ... There should only be one column
|
||||
// ... There should only be one row
|
||||
//
|
||||
Assert.Equal(1, resultSet.Columns.Length);
|
||||
Assert.Equal(1, resultSet.RowCount);
|
||||
Assert.AreEqual(1, resultSet.Columns.Length);
|
||||
Assert.AreEqual(1, resultSet.RowCount);
|
||||
|
||||
|
||||
// and:
|
||||
@@ -322,14 +317,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
var task = resultSet.GetSubset(0, 10);
|
||||
task.Wait();
|
||||
var subset = task.Result;
|
||||
Assert.Equal(1, subset.RowCount);
|
||||
Assert.AreEqual(1, subset.RowCount);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1, 0)] // Too small start row
|
||||
[InlineData(20, 0)] // Too large start row
|
||||
[InlineData(0, -1)] // Negative row count
|
||||
public async Task GetSubsetInvalidParameters(int startRow, int rowCount)
|
||||
[Test, Sequential]
|
||||
public async Task GetSubsetInvalidParameters([Values(-1,20,0)] int startRow,
|
||||
[Values(0,0,-1)] int rowCount)
|
||||
{
|
||||
// If:
|
||||
// ... I create a new result set with a valid db data reader
|
||||
@@ -342,15 +335,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// ... And attempt to get a subset with invalid parameters
|
||||
// Then:
|
||||
// ... It should throw an exception for an invalid parameter
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => resultSet.GetSubset(startRow, rowCount));
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => resultSet.GetSubset(startRow, rowCount));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 3)] // Standard scenario, 3 rows should come back
|
||||
[InlineData(0, 20)] // Asking for too many rows, 5 rows should come back
|
||||
[InlineData(1, 3)] // Asking for proper subset of rows from non-zero start
|
||||
[InlineData(1, 20)] // Asking for too many rows at a non-zero start
|
||||
public async Task GetSubsetSuccess(int startRow, int rowCount)
|
||||
[Test]
|
||||
public async Task GetSubsetSuccess([Values(0,1)]int startRow,
|
||||
[Values(3,20)] int rowCount)
|
||||
{
|
||||
// If:
|
||||
// ... I create a new result set with a valid db data reader
|
||||
@@ -365,20 +355,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... rows sub-array and RowCount field of the subset should match
|
||||
Assert.Equal(subset.RowCount, subset.Rows.Length);
|
||||
Assert.AreEqual(subset.RowCount, subset.Rows.Length);
|
||||
|
||||
// Then:
|
||||
// ... There should be rows in the subset, either the number of rows or the number of
|
||||
// rows requested or the number of rows in the result set, whichever is lower
|
||||
long availableRowsFromStart = resultSet.RowCount - startRow;
|
||||
Assert.Equal(Math.Min(availableRowsFromStart, rowCount), subset.RowCount);
|
||||
Assert.AreEqual(Math.Min(availableRowsFromStart, rowCount), subset.RowCount);
|
||||
|
||||
// ... The rows should have the same number of columns as the resultset
|
||||
Assert.Equal(resultSet.Columns.Length, subset.Rows[0].Length);
|
||||
Assert.AreEqual(resultSet.Columns.Length, subset.Rows[0].Length);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RowInvalidParameterData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(RowInvalidParameterData))]
|
||||
public async Task RowInvalidParameter(Action<ResultSet> actionToPerform)
|
||||
{
|
||||
// If: I create a new result set and execute it
|
||||
@@ -387,8 +377,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
ResultSet resultSet = new ResultSet(Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||
await resultSet.ReadResultToEnd(mockReader, CancellationToken.None);
|
||||
|
||||
// Then: Attempting to read an invalid row should fail
|
||||
Assert.ThrowsAny<Exception>(() => actionToPerform(resultSet));
|
||||
Assert.That(() => actionToPerform(resultSet), Throws.InstanceOf<Exception>(), "Attempting to read an invalid row should fail");
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> RowInvalidParameterData
|
||||
@@ -413,7 +402,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RemoveRowSuccess()
|
||||
{
|
||||
// Setup: Create a result set that has the standard data set on it
|
||||
@@ -428,11 +417,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// Then:
|
||||
// ... The row count should decrease
|
||||
// ... The last row should have moved up by 1
|
||||
Assert.Equal(Common.StandardRows - 1, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.StandardRows - 1, resultSet.RowCount);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => resultSet.GetRow(Common.StandardRows - 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task AddRowNoRows()
|
||||
{
|
||||
// Setup:
|
||||
@@ -448,13 +437,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// If: I add a row with a reader that has no rows
|
||||
// Then:
|
||||
// ... I should get an exception
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => resultSet.AddRow(emptyReader));
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => resultSet.AddRow(emptyReader));
|
||||
|
||||
// ... The row count should not have changed
|
||||
Assert.Equal(Common.StandardRows, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task AddRowThrowsOnRead()
|
||||
{
|
||||
// Setup:
|
||||
@@ -467,16 +456,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// ... Create a mock reader that will throw on read
|
||||
var throwingReader = GetReader(new[] {new TestResultSet(5, 0)}, true, Constants.StandardQuery);
|
||||
|
||||
// If: I add a row with a reader that throws on read
|
||||
// Then:
|
||||
// ... I should get an exception
|
||||
await Assert.ThrowsAnyAsync<DbException>(() => resultSet.AddRow(throwingReader));
|
||||
|
||||
// ... The row count should not have changed
|
||||
Assert.Equal(Common.StandardRows, resultSet.RowCount);
|
||||
Assert.ThrowsAsync<TestDbException>(() => resultSet.AddRow(throwingReader), "I add a row with a reader that throws on read. I should get an exception");
|
||||
|
||||
// ... The row count should not have changed
|
||||
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task AddRowSuccess()
|
||||
{
|
||||
// Setup:
|
||||
@@ -497,13 +483,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... There should be a new row in the list of rows
|
||||
Assert.Equal(Common.StandardRows + 1, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.StandardRows + 1, resultSet.RowCount);
|
||||
|
||||
// ... The new row should be readable and all cells contain the test value
|
||||
Assert.All(resultSet.GetRow(Common.StandardRows), cell => Assert.Equal("QQQ", cell.RawObject));
|
||||
Assert.That(resultSet.GetRow(Common.StandardRows).Select(r => r.RawObject), Has.All.EqualTo("QQQ"), "The new row should be readable and all cells contain the test value");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task UpdateRowNoRows()
|
||||
{
|
||||
// Setup:
|
||||
@@ -519,13 +504,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// If: I add a row with a reader that has no rows
|
||||
// Then:
|
||||
// ... I should get an exception
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => resultSet.UpdateRow(0, emptyReader));
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => resultSet.UpdateRow(0, emptyReader));
|
||||
|
||||
// ... The row count should not have changed
|
||||
Assert.Equal(Common.StandardRows, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task UpdateRowSuccess()
|
||||
{
|
||||
// Setup:
|
||||
@@ -546,10 +531,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// Then:
|
||||
// ... There should be the same number of rows
|
||||
Assert.Equal(Common.StandardRows, resultSet.RowCount);
|
||||
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
|
||||
|
||||
// ... The new row should be readable and all cells contain the test value
|
||||
Assert.All(resultSet.GetRow(0), cell => Assert.Equal("QQQ", cell.RawObject));
|
||||
Assert.That(resultSet.GetRow(0).Select(c => c.RawObject), Has.All.EqualTo("QQQ"), "The new row should be readable and all cells contain the test value");
|
||||
}
|
||||
|
||||
private static DbDataReader GetReader(TestResultSet[] dataSet, bool throwOnRead, string query)
|
||||
|
||||
@@ -20,8 +20,6 @@ using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Xunit;
|
||||
using Assert = Xunit.Assert;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
@@ -30,7 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
#region Get SQL Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ExecuteDocumentStatementTest()
|
||||
{
|
||||
string query = string.Format("{0}{1}GO{1}{0}", Constants.StandardQuery, Environment.NewLine);
|
||||
@@ -41,10 +39,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// The text should match the standard query
|
||||
Assert.Equal(queryText, Constants.StandardQuery);
|
||||
Assert.AreEqual(queryText, Constants.StandardQuery);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ExecuteDocumentStatementSameLine()
|
||||
{
|
||||
var statement1 = Constants.StandardQuery;
|
||||
@@ -72,10 +70,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// The query text should match the expected statement at the cursor
|
||||
Assert.Equal(expectedQueryText, queryText);
|
||||
Assert.AreEqual(expectedQueryText, queryText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void GetSqlTextFromDocumentRequestFull()
|
||||
{
|
||||
// Setup:
|
||||
@@ -91,10 +89,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// Then: The text should match the constructed query
|
||||
Assert.Equal(query, queryText);
|
||||
Assert.AreEqual(query, queryText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void GetSqlTextFromDocumentRequestPartial()
|
||||
{
|
||||
// Setup:
|
||||
@@ -107,11 +105,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Constants.OwnerUri, QuerySelection = Common.SubsectionDocument };
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// Then: The text should be a subset of the constructed query
|
||||
Assert.Contains(queryText, query);
|
||||
Assert.That(query, Does.Contain(queryText), "The text should be a subset of the constructed query");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void GetSqlTextFromStringRequest()
|
||||
{
|
||||
// Setup:
|
||||
@@ -124,10 +121,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
var queryText = queryService.GetSqlText(queryParams);
|
||||
|
||||
// Then: The text should match the standard query
|
||||
Assert.Equal(Constants.StandardQuery, queryText);
|
||||
Assert.AreEqual(Constants.StandardQuery, queryText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void GetSqlTextFromInvalidType()
|
||||
{
|
||||
// Setup:
|
||||
@@ -146,7 +143,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
#region Inter-Service API Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InterServiceExecuteNullExecuteParams()
|
||||
{
|
||||
// Setup: Create a query service
|
||||
@@ -156,11 +153,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// If: I call the inter-service API to execute with a null execute params
|
||||
// Then: It should throw
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(
|
||||
Assert.ThrowsAsync<ArgumentNullException>(
|
||||
() => qes.InterServiceExecuteQuery(null, null, eventSender, null, null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InterServiceExecuteNullEventSender()
|
||||
{
|
||||
// Setup: Create a query service, and execute params
|
||||
@@ -169,11 +166,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// If: I call the inter-service API to execute a query with a a null event sender
|
||||
// Then: It should throw
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(
|
||||
Assert.ThrowsAsync<ArgumentNullException>(
|
||||
() => qes.InterServiceExecuteQuery(executeParams, null, null, null, null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InterServiceDisposeNullSuccessFunc()
|
||||
{
|
||||
// Setup: Create a query service and dispose params
|
||||
@@ -182,11 +179,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// If: I call the inter-service API to dispose a query with a null success function
|
||||
// Then: It should throw
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(
|
||||
Assert.ThrowsAsync<ArgumentNullException>(
|
||||
() => qes.InterServiceDisposeQuery(Constants.OwnerUri, null, failureFunc));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InterServiceDisposeNullFailureFunc()
|
||||
{
|
||||
// Setup: Create a query service and dispose params
|
||||
@@ -195,7 +192,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
// If: I call the inter-service API to dispose a query with a null success function
|
||||
// Then: It should throw
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(
|
||||
Assert.ThrowsAsync<ArgumentNullException>(
|
||||
() => qes.InterServiceDisposeQuery(Constants.OwnerUri, successFunc, null));
|
||||
}
|
||||
|
||||
@@ -205,8 +202,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
// NOTE: In order to limit test duplication, we're running the ExecuteDocumentSelection
|
||||
// version of execute query. The code paths are almost identical.
|
||||
|
||||
[Fact]
|
||||
private async Task QueryExecuteAllBatchesNoOp()
|
||||
[Test]
|
||||
public async Task QueryExecuteAllBatchesNoOp()
|
||||
{
|
||||
// If:
|
||||
// ... I request to execute a valid query with all batches as no op
|
||||
@@ -225,10 +222,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
.AddEventValidation(QueryCompleteEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI matches
|
||||
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.BatchSummaries);
|
||||
Assert.Equal(2, p.BatchSummaries.Length);
|
||||
Assert.All(p.BatchSummaries, bs => Assert.Equal(0, bs.ResultSetSummaries.Length));
|
||||
Assert.AreEqual(2, p.BatchSummaries.Length);
|
||||
Assert.That(p.BatchSummaries.Select(s => s.ResultSetSummaries.Length), Has.All.EqualTo(0));
|
||||
}).Complete();
|
||||
await Common.AwaitExecution(queryService, queryParams, efv.Object);
|
||||
|
||||
@@ -237,10 +234,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.Validate();
|
||||
|
||||
// ... There should be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteSingleBatchNoResultsTest()
|
||||
{
|
||||
// If:
|
||||
@@ -264,13 +261,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.Validate();
|
||||
|
||||
// ... There should be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> TestResultSetsData(int numTests) => Common.TestResultSetsEnumeration.Select(r => new object[] { r }).Take(numTests);
|
||||
private static readonly IEnumerable<object[]> TestResultSetsData = Common.TestResultSetsEnumeration.Select(r => new object[] { r }).Take(5);
|
||||
|
||||
[Xunit.Theory]
|
||||
[MemberData(nameof(TestResultSetsData), parameters: 5)]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(TestResultSetsData))]
|
||||
public async Task QueryExecuteSingleBatchSingleResultTest(TestResultSet testResultSet)
|
||||
{
|
||||
// If:
|
||||
@@ -298,11 +295,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.ValidateResultSetSummaries(collectedResultSetEventParams).Validate();
|
||||
|
||||
// ... There should be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Xunit.Theory]
|
||||
[MemberData(nameof(TestResultSetsData), parameters: 4)]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(TestResultSetsData))]
|
||||
public async Task QueryExecuteSingleBatchMultipleResultTest(TestResultSet testResultSet)
|
||||
{
|
||||
// If:
|
||||
@@ -329,10 +326,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.ValidateResultSetSummaries(collectedResultSetEventParams).Validate();
|
||||
|
||||
// ... There should be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteMultipleBatchSingleResultTest()
|
||||
{
|
||||
// If:
|
||||
@@ -362,10 +359,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.ValidateResultSetSummaries(collectedResultSetEventParams).Validate();
|
||||
|
||||
// ... There should be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteUnconnectedUriTest()
|
||||
{
|
||||
// Given:
|
||||
@@ -385,10 +382,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.Validate();
|
||||
|
||||
// ... There should be no active queries
|
||||
Assert.Empty(queryService.ActiveQueries);
|
||||
Assert.That(queryService.ActiveQueries, Is.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteInProgressTest()
|
||||
{
|
||||
// If:
|
||||
@@ -413,10 +410,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.Validate();
|
||||
|
||||
// ... There should only be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteCompletedTest()
|
||||
{
|
||||
// If:
|
||||
@@ -445,10 +442,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.Validate();
|
||||
|
||||
// ... There should only be one active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task QueryExecuteInvalidQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -471,11 +468,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv.Validate();
|
||||
|
||||
// ... There should not be an active query
|
||||
Assert.Equal(1, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(1, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
// TODO https://github.com/Microsoft/vscode-mssql/issues/1003 reenable and make non-flaky
|
||||
// [Fact]
|
||||
// [Test]
|
||||
public async Task SimpleExecuteErrorWithNoResultsTest()
|
||||
{
|
||||
var queryService = Common.GetPrimedExecutionService(null, true, false, false, null);
|
||||
@@ -493,12 +490,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
efv.Validate();
|
||||
|
||||
Assert.Equal(0, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(0, queryService.ActiveQueries.Count);
|
||||
|
||||
}
|
||||
|
||||
// TODO reenable and make non-flaky
|
||||
// [Fact]
|
||||
// [Test]
|
||||
public async Task SimpleExecuteVerifyResultsTest()
|
||||
{
|
||||
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, null);
|
||||
@@ -519,10 +516,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
|
||||
efv.Validate();
|
||||
|
||||
Assert.Equal(0, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(0, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SimpleExecuteMultipleQueriesTest()
|
||||
{
|
||||
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, null);
|
||||
@@ -548,7 +545,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
efv1.Validate();
|
||||
efv2.Validate();
|
||||
|
||||
Assert.Equal(0, queryService.ActiveQueries.Count);
|
||||
Assert.AreEqual(0, queryService.ActiveQueries.Count);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -569,7 +566,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
return efv.AddResultValidation(p =>
|
||||
{
|
||||
Assert.Equal(p.RowCount, testData[0].Rows.Count);
|
||||
Assert.AreEqual(p.RowCount, testData[0].Rows.Count);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -578,7 +575,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
return efv.AddSimpleErrorValidation((m, e) =>
|
||||
{
|
||||
Assert.Equal(m, expectedMessage);
|
||||
Assert.AreEqual(m, expectedMessage);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -595,7 +592,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
return efv.AddEventValidation(BatchStartEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and batch summary is returned
|
||||
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.BatchSummary);
|
||||
});
|
||||
}
|
||||
@@ -606,7 +603,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
return efv.AddEventValidation(BatchCompleteEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and result summary are returned
|
||||
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.BatchSummary);
|
||||
});
|
||||
}
|
||||
@@ -617,7 +614,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
return efv.AddEventValidation(MessageEvent.Type, p =>
|
||||
{
|
||||
// Validate OwnerURI and message are returned
|
||||
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.Message);
|
||||
});
|
||||
}
|
||||
@@ -628,7 +625,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
return efv.SetupCallbackOnMethodSendEvent(expectedEvent, (p) =>
|
||||
{
|
||||
// Validate OwnerURI and summary are returned
|
||||
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.ResultSetSummary);
|
||||
resultSetEventParamList?.Add(p);
|
||||
});
|
||||
@@ -768,9 +765,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
|
||||
{
|
||||
return efv.AddEventValidation(QueryCompleteEvent.Type, p =>
|
||||
{
|
||||
Assert.Equal(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, p.OwnerUri);
|
||||
Assert.NotNull(p.BatchSummaries);
|
||||
Assert.Equal(expectedBatches, p.BatchSummaries.Length);
|
||||
Assert.AreEqual(expectedBatches, p.BatchSummaries.Length);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
#region ResultSet Class Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ExecutionPlanValid()
|
||||
{
|
||||
// Setup:
|
||||
@@ -32,14 +32,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// ... I have a result set and I ask for a valid execution plan
|
||||
ResultSet planResultSet = b.ResultSets.First();
|
||||
ExecutionPlan plan = planResultSet.GetExecutionPlan().Result;
|
||||
|
||||
// Then:
|
||||
// ... I should get the execution plan back
|
||||
Assert.Equal("xml", plan.Format);
|
||||
Assert.Contains("Execution Plan", plan.Content);
|
||||
Assert.AreEqual("xml", plan.Format);
|
||||
Assert.That(plan.Content, Does.Contain("Execution Plan"), "I should get the execution plan back");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ExecutionPlanInvalid()
|
||||
{
|
||||
// Setup:
|
||||
@@ -52,14 +49,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
await Assert.ThrowsAsync<Exception>(() => planResultSet.GetExecutionPlan());
|
||||
Assert.ThrowsAsync<Exception>(() => planResultSet.GetExecutionPlan());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Batch Class Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BatchExecutionPlanValidTest()
|
||||
{
|
||||
// If I have an executed batch which has an execution plan
|
||||
@@ -68,13 +65,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// ... And I ask for a valid execution plan
|
||||
ExecutionPlan plan = b.GetExecutionPlan(0).Result;
|
||||
|
||||
// Then:
|
||||
// ... I should get the execution plan back
|
||||
Assert.Equal("xml", plan.Format);
|
||||
Assert.Contains("Execution Plan", plan.Content);
|
||||
Assert.AreEqual("xml", plan.Format);
|
||||
Assert.That(plan.Content, Does.Contain("Execution Plan"), "I should get the execution plan back");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task BatchExecutionPlanInvalidTest()
|
||||
{
|
||||
// Setup:
|
||||
@@ -83,13 +78,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// If:
|
||||
// ... I ask for an invalid execution plan
|
||||
await Assert.ThrowsAsync<Exception>(() => b.GetExecutionPlan(0));
|
||||
Assert.ThrowsAsync<Exception>(() => b.GetExecutionPlan(0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Invalid result set, too low
|
||||
[InlineData(2)] // Invalid result set, too high
|
||||
public async Task BatchExecutionPlanInvalidParamsTest(int resultSetIndex)
|
||||
[Test]
|
||||
public async Task BatchExecutionPlanInvalidParamsTest([Values(-1,2)] int resultSetIndex)
|
||||
{
|
||||
// If I have an executed batch which has an execution plan
|
||||
Batch b = Common.GetExecutedBatchWithExecutionPlan();
|
||||
@@ -97,17 +90,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// ... And I ask for an execution plan with an invalid result set index
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => b.GetExecutionPlan(resultSetIndex));
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => b.GetExecutionPlan(resultSetIndex));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Query Class Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Invalid batch, too low
|
||||
[InlineData(2)] // Invalid batch, too high
|
||||
public async Task QueryExecutionPlanInvalidParamsTest(int batchIndex)
|
||||
[Test]
|
||||
public async Task QueryExecutionPlanInvalidParamsTest([Values(-1,2)]int batchIndex)
|
||||
{
|
||||
// Setup query settings
|
||||
QueryExecutionSettings querySettings = new QueryExecutionSettings
|
||||
@@ -125,7 +116,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// ... And I ask for a subset with an invalid result set index
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => q.GetExecutionPlan(batchIndex, 0));
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => q.GetExecutionPlan(batchIndex, 0));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -133,7 +124,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
#region Service Intergration Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ExecutionPlanServiceValidTest()
|
||||
{
|
||||
// If:
|
||||
@@ -168,7 +159,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ExecutionPlanServiceMissingQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -183,7 +174,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
executionPlanRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ExecutionPlanServiceUnexecutedQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -215,7 +206,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
executionPlanRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ExecutionPlanServiceOutOfRangeSubsetTest()
|
||||
{
|
||||
// If:
|
||||
|
||||
@@ -6,16 +6,14 @@
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
{
|
||||
public class BatchTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(100)]
|
||||
public void SaveAsFailsOutOfRangeResultSet(int resultSetIndex)
|
||||
[Test]
|
||||
public void SaveAsFailsOutOfRangeResultSet([Values(-1,100)] int resultSetIndex)
|
||||
{
|
||||
// If: I attempt to save results for an invalid result set index
|
||||
// Then: I should get an ArgumentOutOfRange exception
|
||||
|
||||
@@ -6,16 +6,14 @@
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
{
|
||||
public class QueryTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(100)]
|
||||
public void SaveAsFailsOutOfRangeBatch(int batchIndex)
|
||||
[Test]
|
||||
public void SaveAsFailsOutOfRangeBatch([Values(-1,100)] int batchIndex)
|
||||
{
|
||||
// If: I save a basic query's results with out of range batch index
|
||||
// Then: I should get an out of range exception
|
||||
|
||||
@@ -15,13 +15,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
{
|
||||
public class ResultSetTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SaveAsNullParams()
|
||||
{
|
||||
// If: I attempt to save with a null set of params
|
||||
@@ -35,7 +35,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SaveAsNullFactory()
|
||||
{
|
||||
// If: I attempt to save with a null set of params
|
||||
@@ -48,7 +48,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SaveAsFailedIncomplete()
|
||||
{
|
||||
// If: I attempt to save a result set that hasn't completed execution
|
||||
@@ -62,7 +62,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SaveAsFailedExistingTaskInProgress()
|
||||
{
|
||||
// Setup:
|
||||
@@ -82,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveAsWithoutRowSelection()
|
||||
{
|
||||
// Setup:
|
||||
@@ -106,7 +106,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
// Then:
|
||||
// ... The task should have completed successfully
|
||||
Assert.Equal(TaskStatus.RanToCompletion, rs.SaveTasks[Constants.OwnerUri].Status);
|
||||
Assert.AreEqual(TaskStatus.RanToCompletion, rs.SaveTasks[Constants.OwnerUri].Status);
|
||||
|
||||
// ... All the rows should have been written successfully
|
||||
saveWriter.Verify(
|
||||
@@ -114,7 +114,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
Times.Exactly(Common.StandardRows));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveAsWithRowSelection()
|
||||
{
|
||||
// Setup:
|
||||
@@ -146,7 +146,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
// Then:
|
||||
// ... The task should have completed successfully
|
||||
Assert.Equal(TaskStatus.RanToCompletion, rs.SaveTasks[Constants.OwnerUri].Status);
|
||||
Assert.AreEqual(TaskStatus.RanToCompletion, rs.SaveTasks[Constants.OwnerUri].Status);
|
||||
|
||||
// ... All the rows should have been written successfully
|
||||
saveWriter.Verify(
|
||||
|
||||
@@ -17,7 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Moq;
|
||||
using Newtonsoft.Json;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
{
|
||||
@@ -60,13 +60,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
protected Mock<IProtocolEndpoint> HostMock { get; private set; }
|
||||
protected SerializationService SerializationService { get; private set; }
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsCsvNoHeaderSuccess()
|
||||
{
|
||||
await TestSaveAsCsvSuccess(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsCsvWithHeaderSuccess()
|
||||
{
|
||||
await TestSaveAsCsvSuccess(true);
|
||||
@@ -102,13 +102,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsCsvNoHeaderMultiRequestSuccess()
|
||||
{
|
||||
await TestSaveAsCsvMultiRequestSuccess(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsCsvWithHeaderMultiRequestSuccess()
|
||||
{
|
||||
await TestSaveAsCsvMultiRequestSuccess(true);
|
||||
@@ -125,8 +125,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
await this.TestSerializeDataMultiRequestSuccess(setParams, validation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private async Task SaveAsJsonMultiRequestSuccess()
|
||||
[Test]
|
||||
public async Task SaveAsJsonMultiRequestSuccess()
|
||||
{
|
||||
Action<SerializeDataStartRequestParams> setParams = (serializeParams) => {
|
||||
serializeParams.SaveFormat = "json";
|
||||
@@ -137,8 +137,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
await this.TestSerializeDataMultiRequestSuccess(setParams, validation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
private async Task SaveAsXmlMultiRequestSuccess()
|
||||
[Test]
|
||||
public async Task SaveAsXmlMultiRequestSuccess()
|
||||
{
|
||||
Action<SerializeDataStartRequestParams> setParams = (serializeParams) => {
|
||||
serializeParams.SaveFormat = "xml";
|
||||
@@ -239,7 +239,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
Assert.True(File.Exists(filePath), "Expected file to have been written");
|
||||
string[] lines = File.ReadAllLines(filePath);
|
||||
int expectedLength = includeHeaders ? data.Length + 1 : data.Length;
|
||||
Assert.Equal(expectedLength, lines.Length);
|
||||
Assert.AreEqual(expectedLength, lines.Length);
|
||||
int lineIndex = 0;
|
||||
if (includeHeaders)
|
||||
{
|
||||
@@ -278,18 +278,18 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
// ... There should be 2 items in the array,
|
||||
// ... The item should have three fields, and three values, assigned appropriately
|
||||
// ... The deserialized values should match the display value
|
||||
Assert.Equal(data.Length, outputObject.Length);
|
||||
Assert.AreEqual(data.Length, outputObject.Length);
|
||||
for (int rowIndex = 0; rowIndex < outputObject.Length; rowIndex++)
|
||||
{
|
||||
Dictionary<string,object> item = outputObject[rowIndex];
|
||||
Assert.Equal(columns.Length, item.Count);
|
||||
Assert.AreEqual(columns.Length, item.Count);
|
||||
for (int columnIndex = 0; columnIndex < columns.Length; columnIndex++)
|
||||
{
|
||||
var key = columns[columnIndex].Name;
|
||||
Assert.True(item.ContainsKey(key));
|
||||
DbCellValue value = data[rowIndex][columnIndex];
|
||||
object expectedValue = GetJsonExpectedValue(value, columns[columnIndex]);
|
||||
Assert.Equal(expectedValue, item[key]);
|
||||
Assert.AreEqual(expectedValue, item[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,12 +325,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
string xpath = "data/row";
|
||||
var rows = xmlDoc.SelectNodes(xpath);
|
||||
|
||||
Assert.Equal(data.Length, rows.Count);
|
||||
Assert.AreEqual(data.Length, rows.Count);
|
||||
for (int rowIndex = 0; rowIndex < rows.Count; rowIndex++)
|
||||
{
|
||||
var rowValue = rows.Item(rowIndex);
|
||||
var xmlCols = rowValue.ChildNodes.Cast<XmlNode>().ToArray();
|
||||
Assert.Equal(columns.Length, xmlCols.Length);
|
||||
Assert.AreEqual(columns.Length, xmlCols.Length);
|
||||
for (int columnIndex = 0; columnIndex < columns.Length; columnIndex++)
|
||||
{
|
||||
var columnName = columns[columnIndex].Name;
|
||||
@@ -338,7 +338,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
Assert.NotNull(xmlColumn);
|
||||
DbCellValue value = data[rowIndex][columnIndex];
|
||||
object expectedValue = GetXmlExpectedValue(value);
|
||||
Assert.Equal(expectedValue, xmlColumn.InnerText);
|
||||
Assert.AreEqual(expectedValue, xmlColumn.InnerText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Workspace;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
{
|
||||
@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
{
|
||||
#region CSV Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsCsvNonExistentQuery()
|
||||
{
|
||||
// Given: A working query and workspace service
|
||||
@@ -48,7 +48,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
evf.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultAsCsvFailure()
|
||||
{
|
||||
// Given:
|
||||
@@ -94,7 +94,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsCsvSuccess()
|
||||
{
|
||||
// Given:
|
||||
@@ -139,7 +139,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
#region JSON tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsJsonNonExistentQuery()
|
||||
{
|
||||
// Given: A working query and workspace service
|
||||
@@ -162,7 +162,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultAsJsonFailure()
|
||||
{
|
||||
// Given:
|
||||
@@ -206,7 +206,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsJsonSuccess()
|
||||
{
|
||||
// Given:
|
||||
@@ -250,7 +250,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
#region XML tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsXmlNonExistentQuery()
|
||||
{
|
||||
// Given: A working query and workspace service
|
||||
@@ -273,7 +273,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultAsXmlFailure()
|
||||
{
|
||||
// Given:
|
||||
@@ -317,7 +317,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsXmlSuccess()
|
||||
{
|
||||
// Given:
|
||||
@@ -363,7 +363,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
|
||||
#region Excel Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsExcelNonExistentQuery()
|
||||
{
|
||||
// Given: A working query and workspace service
|
||||
@@ -386,7 +386,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultAsExcelFailure()
|
||||
{
|
||||
// Given:
|
||||
@@ -430,7 +430,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SaveResultsAsExcelSuccess()
|
||||
{
|
||||
// Given:
|
||||
|
||||
@@ -8,28 +8,28 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
public class SettingsTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ValidateQueryExecuteDefaults()
|
||||
{
|
||||
// If: I create a new settings object
|
||||
var sqlToolsSettings = new SqlToolsSettings();
|
||||
|
||||
// Then: The default values should be as expected
|
||||
Assert.Equal("GO", sqlToolsSettings.QueryExecutionSettings.BatchSeparator);
|
||||
Assert.Equal(ushort.MaxValue, sqlToolsSettings.QueryExecutionSettings.MaxCharsToStore);
|
||||
Assert.Equal(2*1024*1024, sqlToolsSettings.QueryExecutionSettings.MaxXmlCharsToStore);
|
||||
Assert.AreEqual("GO", sqlToolsSettings.QueryExecutionSettings.BatchSeparator);
|
||||
Assert.AreEqual(ushort.MaxValue, sqlToolsSettings.QueryExecutionSettings.MaxCharsToStore);
|
||||
Assert.AreEqual(2*1024*1024, sqlToolsSettings.QueryExecutionSettings.MaxXmlCharsToStore);
|
||||
Assert.False(sqlToolsSettings.QueryExecutionSettings.ExecutionPlanOptions.IncludeActualExecutionPlanXml);
|
||||
Assert.False(sqlToolsSettings.QueryExecutionSettings.ExecutionPlanOptions.IncludeEstimatedExecutionPlanXml);
|
||||
Assert.True(sqlToolsSettings.QueryExecutionSettings.DisplayBitAsNumber);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ValidateSettingsParsedFromJson()
|
||||
{
|
||||
ValidateSettings("mssql");
|
||||
@@ -59,7 +59,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
Assert.False(sqlToolsSettings.QueryExecutionSettings.DisplayBitAsNumber);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ValidateSettingsObjectUpdates()
|
||||
{
|
||||
// If: I update a settings object with a new settings object
|
||||
@@ -110,13 +110,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
Assert.False(qes.Settings.QueryExecutionSettings.DisplayBitAsNumber);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.ExecutionPlanOptions.IncludeActualExecutionPlanXml);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.ExecutionPlanOptions.IncludeEstimatedExecutionPlanXml);
|
||||
Assert.Equal(1, qes.Settings.QueryExecutionSettings.MaxCharsToStore);
|
||||
Assert.Equal(1, qes.Settings.QueryExecutionSettings.MaxXmlCharsToStore);
|
||||
Assert.Equal("YO", qes.Settings.QueryExecutionSettings.BatchSeparator);
|
||||
Assert.Equal(1, qes.Settings.QueryExecutionSettings.MaxCharsToStore);
|
||||
Assert.Equal(0, qes.Settings.QueryExecutionSettings.RowCount);
|
||||
Assert.Equal(1000, qes.Settings.QueryExecutionSettings.TextSize);
|
||||
Assert.Equal(5000, qes.Settings.QueryExecutionSettings.ExecutionTimeout);
|
||||
Assert.AreEqual(1, qes.Settings.QueryExecutionSettings.MaxCharsToStore);
|
||||
Assert.AreEqual(1, qes.Settings.QueryExecutionSettings.MaxXmlCharsToStore);
|
||||
Assert.AreEqual("YO", qes.Settings.QueryExecutionSettings.BatchSeparator);
|
||||
Assert.AreEqual(1, qes.Settings.QueryExecutionSettings.MaxCharsToStore);
|
||||
Assert.AreEqual(0, qes.Settings.QueryExecutionSettings.RowCount);
|
||||
Assert.AreEqual(1000, qes.Settings.QueryExecutionSettings.TextSize);
|
||||
Assert.AreEqual(5000, qes.Settings.QueryExecutionSettings.ExecutionTimeout);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.NoCount);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.NoExec);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.ParseOnly);
|
||||
@@ -124,10 +124,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.StatisticsTime);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.StatisticsIO);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.XactAbortOn);
|
||||
Assert.Equal("REPEATABLE READ", qes.Settings.QueryExecutionSettings.TransactionIsolationLevel);
|
||||
Assert.Equal("LOW", qes.Settings.QueryExecutionSettings.DeadlockPriority);
|
||||
Assert.Equal(5000, qes.Settings.QueryExecutionSettings.LockTimeout);
|
||||
Assert.Equal(2000, qes.Settings.QueryExecutionSettings.QueryGovernorCostLimit);
|
||||
Assert.AreEqual("REPEATABLE READ", qes.Settings.QueryExecutionSettings.TransactionIsolationLevel);
|
||||
Assert.AreEqual("LOW", qes.Settings.QueryExecutionSettings.DeadlockPriority);
|
||||
Assert.AreEqual(5000, qes.Settings.QueryExecutionSettings.LockTimeout);
|
||||
Assert.AreEqual(2000, qes.Settings.QueryExecutionSettings.QueryGovernorCostLimit);
|
||||
Assert.False(qes.Settings.QueryExecutionSettings.AnsiDefaults);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.QuotedIdentifier);
|
||||
Assert.True(qes.Settings.QueryExecutionSettings.AnsiNullDefaultOn);
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
public class SpecialActionTests
|
||||
{
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SpecialActionInstantiation()
|
||||
{
|
||||
// If:
|
||||
@@ -20,11 +20,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... The special action should be set to none and only none
|
||||
Assert.Equal(true, specialAction.None);
|
||||
Assert.Equal(false, specialAction.ExpectYukonXMLShowPlan);
|
||||
Assert.AreEqual(true, specialAction.None);
|
||||
Assert.AreEqual(false, specialAction.ExpectYukonXMLShowPlan);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SpecialActionNoneProperty()
|
||||
{
|
||||
// If:
|
||||
@@ -35,11 +35,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... The special action should be set to none and only none
|
||||
Assert.Equal(true, specialAction.None);
|
||||
Assert.Equal(false, specialAction.ExpectYukonXMLShowPlan);
|
||||
Assert.AreEqual(true, specialAction.None);
|
||||
Assert.AreEqual(false, specialAction.ExpectYukonXMLShowPlan);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SpecialActionExpectYukonXmlShowPlanReset()
|
||||
{
|
||||
// If:
|
||||
@@ -50,11 +50,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... The special action should be set to none and only none
|
||||
Assert.Equal(true, specialAction.None);
|
||||
Assert.Equal(false, specialAction.ExpectYukonXMLShowPlan);
|
||||
Assert.AreEqual(true, specialAction.None);
|
||||
Assert.AreEqual(false, specialAction.ExpectYukonXMLShowPlan);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SpecialActionCombiningProperties()
|
||||
{
|
||||
// If:
|
||||
@@ -69,8 +69,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... The special action should be set to none and only none
|
||||
Assert.Equal(false, specialAction.None);
|
||||
Assert.Equal(true, specialAction.ExpectYukonXMLShowPlan);
|
||||
Assert.AreEqual(false, specialAction.None);
|
||||
Assert.AreEqual(true, specialAction.ExpectYukonXMLShowPlan);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
@@ -20,10 +20,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
{
|
||||
#region ResultSet Class Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 2)]
|
||||
[InlineData(0, 20)]
|
||||
[InlineData(1, 2)]
|
||||
static private readonly object[] validSet =
|
||||
{
|
||||
new object[] {0, 2 },
|
||||
new object[] {0, 20 },
|
||||
new object[] {1, 2 },
|
||||
};
|
||||
|
||||
[Test, TestCaseSource(nameof(validSet))]
|
||||
public void ResultSetValidTest(int startRow, int rowCount)
|
||||
{
|
||||
// Setup:
|
||||
@@ -39,15 +43,18 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... I should get the requested number of rows back
|
||||
Assert.Equal(Math.Min(rowCount, Common.StandardRows), subset.RowCount);
|
||||
Assert.Equal(Math.Min(rowCount, Common.StandardRows), subset.Rows.Length);
|
||||
Assert.AreEqual(Math.Min(rowCount, Common.StandardRows), subset.RowCount);
|
||||
Assert.AreEqual(Math.Min(rowCount, Common.StandardRows), subset.Rows.Length);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1, 2)] // Invalid start index, too low
|
||||
[InlineData(10, 2)] // Invalid start index, too high
|
||||
[InlineData(0, -1)] // Invalid row count, too low
|
||||
[InlineData(0, 0)] // Invalid row count, zero
|
||||
static private readonly object[] invalidSet =
|
||||
{
|
||||
new object[] {-1, 2}, // Invalid start index, too low
|
||||
new object[] {10, 2}, // Invalid start index, too high
|
||||
new object[] {0, -1}, // Invalid row count, too low
|
||||
new object[] {0, 0 }, // Invalid row count, zero
|
||||
};
|
||||
[Test, TestCaseSource(nameof(invalidSet))]
|
||||
public void ResultSetInvalidParmsTest(int rowStartIndex, int rowCount)
|
||||
{
|
||||
// If:
|
||||
@@ -57,28 +64,26 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => rs.GetSubset(rowStartIndex, rowCount)).Wait();
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => rs.GetSubset(rowStartIndex, rowCount));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ResultSetNotReadTest()
|
||||
[Test]
|
||||
public void ResultSetNotReadTest()
|
||||
{
|
||||
// If:
|
||||
// ... I have a resultset that hasn't been executed and I request a valid result set from it
|
||||
// Then:
|
||||
// ... It should throw an exception for having not been read
|
||||
ResultSet rs = new ResultSet(Common.Ordinal, Common.Ordinal, MemoryFileSystem.GetFileStreamFactory());
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => rs.GetSubset(0, 1));
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => rs.GetSubset(0, 1));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Batch Class Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(2)]
|
||||
[InlineData(20)]
|
||||
public void BatchSubsetValidTest(int rowCount)
|
||||
[Test]
|
||||
public void BatchSubsetValidTest([Values(2,20)] int rowCount)
|
||||
{
|
||||
// If I have an executed batch
|
||||
Batch b = Common.GetBasicExecutedBatch();
|
||||
@@ -90,14 +95,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
|
||||
// Then:
|
||||
// I should get the requested number of rows
|
||||
Assert.Equal(Math.Min(rowCount, Common.StandardRows), subset.RowCount);
|
||||
Assert.Equal(Math.Min(rowCount, Common.StandardRows), subset.Rows.Length);
|
||||
Assert.AreEqual(Math.Min(rowCount, Common.StandardRows), subset.RowCount);
|
||||
Assert.AreEqual(Math.Min(rowCount, Common.StandardRows), subset.Rows.Length);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Invalid result set, too low
|
||||
[InlineData(2)] // Invalid result set, too high
|
||||
public void BatchSubsetInvalidParamsTest(int resultSetIndex)
|
||||
[Test]
|
||||
public void BatchSubsetInvalidParamsTest([Values(-1,2)] int resultSetIndex)
|
||||
{
|
||||
// If I have an executed batch
|
||||
Batch b = Common.GetBasicExecutedBatch();
|
||||
@@ -105,17 +108,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// ... And I ask for a subset with an invalid result set index
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => b.GetSubset(resultSetIndex, 0, 2)).Wait();
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => b.GetSubset(resultSetIndex, 0, 2));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Query Class Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Invalid batch, too low
|
||||
[InlineData(2)] // Invalid batch, too high
|
||||
public void QuerySubsetInvalidParamsTest(int batchIndex)
|
||||
[Test]
|
||||
public void QuerySubsetInvalidParamsTest([Values(-1,2)] int batchIndex)
|
||||
{
|
||||
// If I have an executed query
|
||||
Query q = Common.GetBasicExecutedQuery();
|
||||
@@ -123,14 +124,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
// ... And I ask for a subset with an invalid result set index
|
||||
// Then:
|
||||
// ... It should throw an exception
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => q.GetSubset(batchIndex, 0, 0, 1)).Wait();
|
||||
Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => q.GetSubset(batchIndex, 0, 0, 1));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Service Intergration Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SubsetServiceValidTest()
|
||||
{
|
||||
// If:
|
||||
@@ -155,7 +156,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
subsetRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SubsetServiceMissingQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -170,7 +171,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
subsetRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SubsetServiceUnexecutedQueryTest()
|
||||
{
|
||||
// If:
|
||||
@@ -193,7 +194,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
||||
subsetRequest.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SubsetServiceOutOfRangeSubsetTest()
|
||||
{
|
||||
// If:
|
||||
|
||||
Reference in New Issue
Block a user