mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-26 09:35:38 -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:
@@ -13,13 +13,13 @@ using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public class RowDeleteTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RowDeleteConstruction()
|
||||
{
|
||||
// Setup: Create the values to store
|
||||
@@ -30,15 +30,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
RowDelete rc = new RowDelete(100, rs, data.TableMetadata);
|
||||
|
||||
// Then: The values I provided should be available
|
||||
Assert.Equal(100, rc.RowId);
|
||||
Assert.Equal(rs, rc.AssociatedResultSet);
|
||||
Assert.Equal(data.TableMetadata, rc.AssociatedObjectMetadata);
|
||||
Assert.AreEqual(100, rc.RowId);
|
||||
Assert.AreEqual(rs, rc.AssociatedResultSet);
|
||||
Assert.AreEqual(data.TableMetadata, rc.AssociatedObjectMetadata);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task GetScriptTest(bool isMemoryOptimized)
|
||||
[Test]
|
||||
public async Task GetScriptTest([Values]bool isMemoryOptimized)
|
||||
{
|
||||
Common.TestDbColumnsWithTableMetadata data = new Common.TestDbColumnsWithTableMetadata(isMemoryOptimized, true, 0, 0);
|
||||
ResultSet rs = await Common.GetResultSet(data.DbColumns, true);
|
||||
@@ -51,16 +49,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... The script should not be null
|
||||
Assert.NotNull(script);
|
||||
|
||||
// ... It should be formatted as a delete script
|
||||
// ...
|
||||
string scriptStart = $"DELETE FROM {data.TableMetadata.EscapedMultipartName}";
|
||||
if (isMemoryOptimized)
|
||||
{
|
||||
scriptStart += " WITH(SNAPSHOT)";
|
||||
}
|
||||
Assert.StartsWith(scriptStart, script);
|
||||
Assert.That(script, Does.StartWith(scriptStart), "It should be formatted as a delete script");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ApplyChanges()
|
||||
{
|
||||
// Setup: Generate the parameters for the row delete object
|
||||
@@ -72,15 +70,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
await rd.ApplyChanges(null); // Reader not used, can be null
|
||||
|
||||
// Then : The result set should have one less row in it
|
||||
Assert.Equal(0, rs.RowCount);
|
||||
Assert.AreEqual(0, rs.RowCount);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, true)]
|
||||
[InlineData(false, true)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, false)]
|
||||
public async Task GetCommand(bool includeIdentity, bool isMemoryOptimized)
|
||||
[Test]
|
||||
public async Task GetCommand([Values]bool includeIdentity, [Values]bool isMemoryOptimized)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row delete
|
||||
@@ -100,7 +94,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... Only the keys should be used for parameters
|
||||
int expectedKeys = includeIdentity ? 1 : 3;
|
||||
Assert.Equal(expectedKeys, cmd.Parameters.Count);
|
||||
Assert.AreEqual(expectedKeys, cmd.Parameters.Count);
|
||||
|
||||
// ... It should be formatted into an delete script
|
||||
string regexTest = isMemoryOptimized
|
||||
@@ -112,17 +106,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... There should be a table
|
||||
string tbl = m.Groups[1].Value;
|
||||
Assert.Equal(data.TableMetadata.EscapedMultipartName, tbl);
|
||||
Assert.AreEqual(data.TableMetadata.EscapedMultipartName, tbl);
|
||||
|
||||
// ... There should be as many where components as there are keys
|
||||
string[] whereComponents = m.Groups[2].Value.Split(new[] {"AND"}, StringSplitOptions.None);
|
||||
Assert.Equal(expectedKeys, whereComponents.Length);
|
||||
Assert.AreEqual(expectedKeys, whereComponents.Length);
|
||||
|
||||
// ... Each component should have be equal to a parameter
|
||||
Assert.All(whereComponents, c => Assert.True(Regex.IsMatch(c.Trim(), @"\(.+ = @.+\)")));
|
||||
Assert.That(whereComponents.Select(c => c.Trim()), Has.All.Match(@"\(.+ = @.+\)"), "Each component should be equal to a parameter");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetCommandNullConnection()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
@@ -133,7 +126,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => rd.GetCommand(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditRow()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
@@ -148,26 +141,26 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Then:
|
||||
// ... The state should be dirty
|
||||
Assert.True(er.IsDirty);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyDelete, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyDelete, er.State);
|
||||
|
||||
// ... The ID should be the same as the one provided
|
||||
Assert.Equal(0, er.Id);
|
||||
Assert.AreEqual(0, er.Id);
|
||||
|
||||
// ... The row should match the cells that were given and should be dirty
|
||||
Assert.Equal(cells.Length, er.Cells.Length);
|
||||
Assert.AreEqual(cells.Length, er.Cells.Length);
|
||||
for (int i = 0; i < cells.Length; i++)
|
||||
{
|
||||
DbCellValue originalCell = cells[i];
|
||||
EditCell outputCell = er.Cells[i];
|
||||
|
||||
Assert.Equal(originalCell.DisplayValue, outputCell.DisplayValue);
|
||||
Assert.Equal(originalCell.IsNull, outputCell.IsNull);
|
||||
Assert.AreEqual(originalCell.DisplayValue, outputCell.DisplayValue);
|
||||
Assert.AreEqual(originalCell.IsNull, outputCell.IsNull);
|
||||
Assert.True(outputCell.IsDirty);
|
||||
// Note: No real need to check the RawObject property
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditNullRow()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
@@ -178,7 +171,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => rd.GetEditRow(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCell()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
@@ -189,7 +182,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => rd.SetCell(0, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertCell()
|
||||
{
|
||||
// Setup: Create a row delete
|
||||
|
||||
Reference in New Issue
Block a user