mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user