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:
David Shiflet
2020-08-05 13:43:14 -04:00
committed by GitHub
parent bf4911795f
commit 839acf67cd
205 changed files with 4146 additions and 4329 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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(

View File

@@ -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);
}
}
}

View File

@@ -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: