mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 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:
@@ -9,13 +9,13 @@ using System.Data.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public class CellUpdateTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void NullColumnTest()
|
||||
{
|
||||
// If: I attempt to create a CellUpdate with a null column
|
||||
@@ -23,7 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => new CellUpdate(null, string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void NullStringValueTest()
|
||||
{
|
||||
// If: I attempt to create a CellUpdate with a null string value
|
||||
@@ -31,7 +31,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => new CellUpdate(GetWrapper<string>("ntext"), null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void NullStringAllowedTest()
|
||||
{
|
||||
// If: I attempt to create a CellUpdate to set it to NULL
|
||||
@@ -41,13 +41,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then: The value should be a DBNull and the string value should be the same as what
|
||||
// was given
|
||||
Assert.IsType<DBNull>(cu.Value);
|
||||
Assert.Equal(DBNull.Value, cu.Value);
|
||||
Assert.Equal(nullString, cu.ValueAsString);
|
||||
Assert.Equal(col, cu.Column);
|
||||
Assert.That(cu.Value, Is.InstanceOf<DBNull>());
|
||||
Assert.AreEqual(DBNull.Value, cu.Value);
|
||||
Assert.AreEqual(nullString, cu.ValueAsString);
|
||||
Assert.AreEqual(col, cu.Column);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void NullStringNotAllowedTest()
|
||||
{
|
||||
// If: I attempt to create a cell update to set to null when its not allowed
|
||||
@@ -55,7 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => new CellUpdate(GetWrapper<string>("ntext", false), "NULL"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void NullTextStringTest()
|
||||
{
|
||||
// If: I attempt to create a CellUpdate with the text 'NULL' (with mixed case)
|
||||
@@ -63,16 +63,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
CellUpdate cu = new CellUpdate(col, "'NULL'");
|
||||
|
||||
// Then: The value should be NULL
|
||||
Assert.IsType<string>(cu.Value);
|
||||
Assert.Equal("NULL", cu.Value);
|
||||
Assert.Equal("'NULL'", cu.ValueAsString);
|
||||
Assert.Equal(col, cu.Column);
|
||||
Assert.That(cu.Value, Is.InstanceOf<string>());
|
||||
Assert.AreEqual("NULL", cu.Value);
|
||||
Assert.AreEqual("'NULL'", cu.ValueAsString);
|
||||
Assert.AreEqual(col, cu.Column);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("This is way too long")]
|
||||
[InlineData("TooLong")]
|
||||
public void StringTooLongTest(string value)
|
||||
[Test]
|
||||
public void StringTooLongTest([Values("This is way too long", "TooLong")]string value)
|
||||
{
|
||||
// If: I attempt to create a CellUpdate to set it to a large string
|
||||
// Then: I should get an exception thrown
|
||||
@@ -80,8 +78,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => new CellUpdate(col, value));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ByteArrayTestParams))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(ByteArrayTestParams))]
|
||||
public void ByteArrayTest(string strValue, byte[] expectedValue, string expectedString)
|
||||
{
|
||||
// If: I attempt to create a CellUpdate for a binary column
|
||||
@@ -89,10 +87,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
CellUpdate cu = new CellUpdate(col, strValue);
|
||||
|
||||
// Then: The value should be a binary and should match the expected data
|
||||
Assert.IsType<byte[]>(cu.Value);
|
||||
Assert.Equal(expectedValue, cu.Value);
|
||||
Assert.Equal(expectedString, cu.ValueAsString);
|
||||
Assert.Equal(col, cu.Column);
|
||||
Assert.That(cu.Value, Is.InstanceOf<byte[]>());
|
||||
Assert.AreEqual(expectedValue, cu.Value);
|
||||
Assert.AreEqual(expectedString, cu.ValueAsString);
|
||||
Assert.AreEqual(col, cu.Column);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ByteArrayTestParams
|
||||
@@ -134,7 +132,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ByteArrayInvalidFormatTest()
|
||||
{
|
||||
// If: I attempt to create a CellUpdate for a binary column
|
||||
@@ -143,8 +141,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => new CellUpdate(col, "this is totally invalid"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(BoolTestParams))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(BoolTestParams))]
|
||||
public void BoolTest(string input, bool output, string outputString)
|
||||
{
|
||||
// If: I attempt to create a CellUpdate for a boolean column
|
||||
@@ -152,13 +150,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
CellUpdate cu = new CellUpdate(col, input);
|
||||
|
||||
// Then: The value should match what was expected
|
||||
Assert.IsType<bool>(cu.Value);
|
||||
Assert.Equal(output, cu.Value);
|
||||
Assert.Equal(outputString, cu.ValueAsString);
|
||||
Assert.Equal(col, cu.Column);
|
||||
Assert.That(cu.Value, Is.InstanceOf<bool>());
|
||||
Assert.AreEqual(output, cu.Value);
|
||||
Assert.AreEqual(outputString, cu.ValueAsString);
|
||||
Assert.AreEqual(col, cu.Column);
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> BoolTestParams
|
||||
private static IEnumerable<object[]> BoolTestParams
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -169,7 +167,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BoolInvalidFormatTest()
|
||||
{
|
||||
// If: I create a CellUpdate for a bool column and provide an invalid numeric value
|
||||
@@ -178,10 +176,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => new CellUpdate(col, "12345"));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("24:00:00")]
|
||||
[InlineData("105:00:00")]
|
||||
public void TimeSpanTooLargeTest(string value)
|
||||
[Test]
|
||||
public void TimeSpanTooLargeTest([Values("24:00:00", "105:00:00")] string value)
|
||||
{
|
||||
// If: I create a cell update for a timespan column and provide a value that is over 24hrs
|
||||
// Then: It should throw an exception
|
||||
@@ -189,21 +185,33 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => new CellUpdate(col, value));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RoundTripTestParams))]
|
||||
public void RoundTripTest(DbColumnWrapper col, object obj)
|
||||
/// <summary>
|
||||
/// Not using TestCaseSource because nUnit's test name generator
|
||||
/// doesn't like DbColumnWrapper objects as a source, due
|
||||
/// to that class lacking a ToString override.
|
||||
/// </summary>
|
||||
/// <param name="col"></param>
|
||||
/// <param name="obj"></param>
|
||||
[Test]
|
||||
public void RoundTripTest()
|
||||
{
|
||||
// Setup: Figure out the test string
|
||||
string testString = obj.ToString();
|
||||
|
||||
// If: I attempt to create a CellUpdate
|
||||
CellUpdate cu = new CellUpdate(col, testString);
|
||||
|
||||
// Then: The value and type should match what we put in
|
||||
Assert.IsType(col.DataType, cu.Value);
|
||||
Assert.Equal(obj, cu.Value);
|
||||
Assert.Equal(testString, cu.ValueAsString);
|
||||
Assert.Equal(col, cu.Column);
|
||||
foreach (var inputs in RoundTripTestParams)
|
||||
{
|
||||
|
||||
var col = (DbColumnWrapper)inputs[0];
|
||||
var obj = inputs[1];
|
||||
// Setup: Figure out the test string
|
||||
string testString = obj.ToString();
|
||||
|
||||
// If: I attempt to create a CellUpdate
|
||||
CellUpdate cu = new CellUpdate(col, testString);
|
||||
|
||||
// Then: The value and type should match what we put in
|
||||
Assert.That(cu.Value, Is.InstanceOf(col.DataType));
|
||||
Assert.AreEqual(obj, cu.Value);
|
||||
Assert.AreEqual(testString, cu.ValueAsString);
|
||||
Assert.AreEqual(col, cu.Column);
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> RoundTripTestParams
|
||||
@@ -228,10 +236,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void AsDbCellValue(bool isNull)
|
||||
[Test]
|
||||
public void AsDbCellValue([Values]bool isNull)
|
||||
{
|
||||
// Setup: Create a cell update
|
||||
var value = isNull ? "NULL" : "foo";
|
||||
@@ -246,19 +252,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(dbc);
|
||||
|
||||
// ... The display value should be the same as the value we supplied
|
||||
Assert.Equal(value, dbc.DisplayValue);
|
||||
Assert.AreEqual(value, dbc.DisplayValue);
|
||||
|
||||
// ... The null-ness of the value should be the same as what we supplied
|
||||
Assert.Equal(isNull, dbc.IsNull);
|
||||
Assert.AreEqual(isNull, dbc.IsNull);
|
||||
|
||||
// ... We don't care *too* much about the raw value, but we'll check it anyhow
|
||||
Assert.Equal(isNull ? (object)DBNull.Value : value, dbc.RawObject);
|
||||
Assert.AreEqual(isNull ? (object)DBNull.Value : value, dbc.RawObject);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void AsEditCellValue(bool isNull)
|
||||
[Test]
|
||||
public void AsEditCellValue([Values]bool isNull)
|
||||
{
|
||||
// Setup: Create a cell update
|
||||
var value = isNull ? "NULL" : "foo";
|
||||
@@ -273,13 +277,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(ec);
|
||||
|
||||
// ... The display value should be the same as the value we supplied
|
||||
Assert.Equal(value, ec.DisplayValue);
|
||||
Assert.AreEqual(value, ec.DisplayValue);
|
||||
|
||||
// ... The null-ness of the value should be the same as what we supplied
|
||||
Assert.Equal(isNull, ec.IsNull);
|
||||
Assert.AreEqual(isNull, ec.IsNull);
|
||||
|
||||
// ... We don't care *too* much about the raw value, but we'll check it anyhow
|
||||
Assert.Equal(isNull ? (object)DBNull.Value : value, ec.RawObject);
|
||||
Assert.AreEqual(isNull ? (object)DBNull.Value : value, ec.RawObject);
|
||||
|
||||
// ... The edit cell should be dirty
|
||||
Assert.True(ec.IsDirty);
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public class EditCellTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructNullDbCell()
|
||||
{
|
||||
// If: I construct an EditCell with a null DbCellValue
|
||||
@@ -20,7 +20,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => new EditCell(null, true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructValid()
|
||||
{
|
||||
// Setup: Create a DbCellValue to copy the values from
|
||||
@@ -36,9 +36,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... The values I provided in the DbCellValue should be present
|
||||
Assert.Equal(source.DisplayValue, ec.DisplayValue);
|
||||
Assert.Equal(source.IsNull, ec.IsNull);
|
||||
Assert.Equal(source.RawObject, ec.RawObject);
|
||||
Assert.AreEqual(source.DisplayValue, ec.DisplayValue);
|
||||
Assert.AreEqual(source.IsNull, ec.IsNull);
|
||||
Assert.AreEqual(source.RawObject, ec.RawObject);
|
||||
|
||||
// ... The is dirty value I set should be present
|
||||
Assert.True(ec.IsDirty);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
@@ -19,7 +19,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
/// </summary>
|
||||
public class FilterMetadataTest
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void BasicFilterTest()
|
||||
{
|
||||
EditColumnMetadata[] metas = CreateMetadataColumns(new string[] { "[col1]", "[col2]", "[col3]" });
|
||||
@@ -29,7 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
ValidateFilteredData(filteredData, cols);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ReorderedResultsTest()
|
||||
{
|
||||
EditColumnMetadata[] metas = CreateMetadataColumns(new string[] { "[col1]", "[col2]", "[col3]" });
|
||||
@@ -39,7 +39,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
ValidateFilteredData(filteredData, cols);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void LessResultColumnsTest()
|
||||
{
|
||||
EditColumnMetadata[] metas = CreateMetadataColumns(new string[] { "[col1]", "[col2]", "[col3]", "[fillerCol1]", "[fillerCol2]" });
|
||||
@@ -49,7 +49,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
ValidateFilteredData(filteredData, cols);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void EmptyDataTest()
|
||||
{
|
||||
EditColumnMetadata[] metas = new EditColumnMetadata[0];
|
||||
@@ -81,13 +81,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
private void ValidateFilteredData(EditColumnMetadata[] filteredData, DbColumnWrapper[] cols)
|
||||
{
|
||||
Assert.Equal(cols.Length, filteredData.Length);
|
||||
Assert.AreEqual(cols.Length, filteredData.Length);
|
||||
for (int i = 0; i < cols.Length; i++)
|
||||
{
|
||||
Assert.Equal(cols[i].ColumnName, filteredData[i].EscapedName);
|
||||
Assert.AreEqual(cols[i].ColumnName, filteredData[i].EscapedName);
|
||||
if (cols[i].ColumnOrdinal.HasValue)
|
||||
{
|
||||
Assert.Equal(cols[i].ColumnOrdinal, filteredData[i].Ordinal);
|
||||
Assert.AreEqual(cols[i].ColumnOrdinal, filteredData[i].Ordinal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ using Microsoft.SqlTools.ServiceLayer.EditData.UpdateManagement;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public class RowCreateTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RowCreateConstruction()
|
||||
{
|
||||
// Setup: Create the values to store
|
||||
@@ -33,9 +33,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
RowCreate rc = new RowCreate(rowId, rs, data.TableMetadata);
|
||||
|
||||
// Then: The values I provided should be available
|
||||
Assert.Equal(rowId, rc.RowId);
|
||||
Assert.Equal(rs, rc.AssociatedResultSet);
|
||||
Assert.Equal(data.TableMetadata, rc.AssociatedObjectMetadata);
|
||||
Assert.AreEqual(rowId, rc.RowId);
|
||||
Assert.AreEqual(rs, rc.AssociatedResultSet);
|
||||
Assert.AreEqual(data.TableMetadata, rc.AssociatedObjectMetadata);
|
||||
}
|
||||
|
||||
#region GetScript Tests
|
||||
@@ -58,8 +58,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetScriptMissingCellsData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(GetScriptMissingCellsData))]
|
||||
public async Task GetScriptMissingCell(bool includeIdentity, int defaultCols, int nullableCols, int valuesToSkipSetting)
|
||||
{
|
||||
// Setup: Generate the parameters for the row create
|
||||
@@ -108,8 +108,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetScriptData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(GetScriptData))]
|
||||
public async Task GetScript(bool includeIdentity, int colsWithDefaultConstraints, int colsThatAllowNull, int valuesToSkipSetting, RegexExpectedOutput expectedOutput)
|
||||
{
|
||||
// Setup:
|
||||
@@ -142,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(m.Success);
|
||||
|
||||
// Table name matches
|
||||
Assert.Equal(Common.TableName, m.Groups[1].Value);
|
||||
Assert.AreEqual(Common.TableName, m.Groups[1].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -152,24 +152,22 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(m.Success);
|
||||
|
||||
// Table name matches
|
||||
Assert.Equal(Common.TableName, m.Groups[1].Value);
|
||||
Assert.AreEqual(Common.TableName, m.Groups[1].Value);
|
||||
|
||||
// In columns match
|
||||
string cols = m.Groups[2].Value;
|
||||
Assert.Equal(expectedOutput.ExpectedInColumns, cols.Split(',').Length);
|
||||
Assert.AreEqual(expectedOutput.ExpectedInColumns, cols.Split(',').Length);
|
||||
|
||||
// In values match
|
||||
string vals = m.Groups[3].Value;
|
||||
Assert.Equal(expectedOutput.ExpectedInValues, vals.Split(',').Length);
|
||||
Assert.AreEqual(expectedOutput.ExpectedInValues, vals.Split(',').Length);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task ApplyChanges(bool includeIdentity)
|
||||
[Test]
|
||||
public async Task ApplyChanges([Values]bool includeIdentity)
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate the parameters for the row create
|
||||
@@ -185,12 +183,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
await rc.ApplyChanges(newRowReader);
|
||||
|
||||
// Then: The result set should have an additional row in it
|
||||
Assert.Equal(2, rs.RowCount);
|
||||
Assert.AreEqual(2, rs.RowCount);
|
||||
}
|
||||
|
||||
#region GetCommand Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetCommandNullConnection()
|
||||
{
|
||||
// Setup: Create a row create
|
||||
@@ -219,8 +217,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetCommandMissingCellsData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(GetCommandMissingCellsData))]
|
||||
public async Task GetCommandMissingCellNoDefault(bool includeIdentity, int defaultCols, int nullableCols,
|
||||
int valuesToSkip)
|
||||
{
|
||||
@@ -274,8 +272,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetCommandData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(GetCommandData))]
|
||||
public async Task GetCommand(bool includeIdentity, int defaultCols, int nullableCols, int valuesToSkip, RegexExpectedOutput expectedOutput)
|
||||
{
|
||||
// Setup:
|
||||
@@ -298,7 +296,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(cmd);
|
||||
|
||||
// ... There should be parameters in it
|
||||
Assert.Equal(expectedOutput.ExpectedInValues, cmd.Parameters.Count);
|
||||
Assert.AreEqual(expectedOutput.ExpectedInValues, cmd.Parameters.Count);
|
||||
|
||||
// ... The script should match the expected regex output
|
||||
ValidateCommandAgainstRegex(cmd.CommandText, expectedOutput);
|
||||
@@ -308,7 +306,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
// Break the query into parts
|
||||
string[] splitSql = sql.Split(Environment.NewLine);
|
||||
Assert.Equal(3, splitSql.Length);
|
||||
Assert.AreEqual(3, splitSql.Length);
|
||||
|
||||
// Check the declare statement first
|
||||
Regex declareRegex = new Regex(@"^DECLARE @(.+) TABLE \((.+)\)$");
|
||||
@@ -321,7 +319,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Correct number of columns in declared table
|
||||
string[] declareCols = declareMatch.Groups[2].Value.Split(", ");
|
||||
Assert.Equal(expectedOutput.ExpectedOutColumns, declareCols.Length);
|
||||
Assert.AreEqual(expectedOutput.ExpectedOutColumns, declareCols.Length);
|
||||
|
||||
// Check the insert statement in the middle
|
||||
if (expectedOutput.ExpectedInColumns == 0 || expectedOutput.ExpectedInValues == 0)
|
||||
@@ -332,16 +330,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(insertMatch.Success);
|
||||
|
||||
// Table name matches
|
||||
Assert.Equal(Common.TableName, insertMatch.Groups[1].Value);
|
||||
Assert.AreEqual(Common.TableName, insertMatch.Groups[1].Value);
|
||||
|
||||
// Output columns match
|
||||
string[] outCols = insertMatch.Groups[2].Value.Split(", ");
|
||||
Assert.Equal(expectedOutput.ExpectedOutColumns, outCols.Length);
|
||||
Assert.All(outCols, col => Assert.StartsWith("inserted.", col));
|
||||
|
||||
// Output table name matches
|
||||
Assert.StartsWith("Insert", insertMatch.Groups[3].Value);
|
||||
Assert.EndsWith("Output", insertMatch.Groups[3].Value);
|
||||
Assert.AreEqual(expectedOutput.ExpectedOutColumns, outCols.Length);
|
||||
Assert.That(outCols, Has.All.StartsWith("inserted."), "Output columns match");
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(insertMatch.Groups[3].Value, Does.StartWith("Insert"), "Output table name matches");
|
||||
Assert.That(insertMatch.Groups[3].Value, Does.EndWith("Output"));
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -351,25 +350,31 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(insertMatch.Success);
|
||||
|
||||
// Table name matches
|
||||
Assert.Equal(Common.TableName, insertMatch.Groups[1].Value);
|
||||
Assert.AreEqual(Common.TableName, insertMatch.Groups[1].Value);
|
||||
|
||||
// Output columns match
|
||||
//
|
||||
string[] outCols = insertMatch.Groups[3].Value.Split(", ");
|
||||
Assert.Equal(expectedOutput.ExpectedOutColumns, outCols.Length);
|
||||
Assert.All(outCols, col => Assert.StartsWith("inserted.", col));
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.AreEqual(expectedOutput.ExpectedOutColumns, outCols.Length);
|
||||
Assert.That(outCols, Has.All.StartsWith("inserted."), "Output columns match");
|
||||
});
|
||||
|
||||
// In columns match
|
||||
string[] inCols = insertMatch.Groups[2].Value.Split(", ");
|
||||
Assert.Equal(expectedOutput.ExpectedInColumns, inCols.Length);
|
||||
|
||||
// Output table name matches
|
||||
Assert.StartsWith("Insert", insertMatch.Groups[4].Value);
|
||||
Assert.EndsWith("Output", insertMatch.Groups[4].Value);
|
||||
|
||||
Assert.AreEqual(expectedOutput.ExpectedInColumns, inCols.Length);
|
||||
|
||||
// Output table name matches
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(insertMatch.Groups[4].Value, Does.StartWith("Insert"));
|
||||
Assert.That(insertMatch.Groups[4].Value, Does.EndWith("Output"));
|
||||
});
|
||||
|
||||
// In values match
|
||||
string[] inVals = insertMatch.Groups[5].Value.Split(", ");
|
||||
Assert.Equal(expectedOutput.ExpectedInValues, inVals.Length);
|
||||
Assert.All(inVals, val => Assert.Matches(@"@.+\d+_\d+", val));
|
||||
Assert.AreEqual(expectedOutput.ExpectedInValues, inVals.Length);
|
||||
Assert.That(inVals, Has.All.Match(@"@.+\d+_\d+"));
|
||||
}
|
||||
|
||||
// Check the select statement last
|
||||
@@ -379,7 +384,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Correct number of columns in declared table
|
||||
string[] selectCols = selectMatch.Groups[1].Value.Split(", ");
|
||||
Assert.Equal(expectedOutput.ExpectedOutColumns, selectCols.Length);
|
||||
Assert.AreEqual(expectedOutput.ExpectedOutColumns, selectCols.Length);
|
||||
|
||||
// Declared table name matches
|
||||
Assert.True(selectMatch.Groups[2].Value.StartsWith("Insert"));
|
||||
@@ -390,7 +395,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region GetEditRow Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditRowNoAdditions()
|
||||
{
|
||||
// Setup: Generate a standard row create
|
||||
@@ -405,19 +410,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... The row should not be clean
|
||||
Assert.True(er.IsDirty);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
|
||||
// ... The row should have a bunch of empty cells (equal to number of columns) and all are dirty
|
||||
Assert.Equal(rc.newCells.Length, er.Cells.Length);
|
||||
Assert.All(er.Cells, ec =>
|
||||
{
|
||||
Assert.Equal(string.Empty, ec.DisplayValue);
|
||||
Assert.False(ec.IsNull);
|
||||
Assert.True(ec.IsDirty);
|
||||
});
|
||||
Assert.AreEqual(rc.newCells.Length, er.Cells.Length);
|
||||
Assert.That(er.Cells.Select(c => c.DisplayValue), Has.All.Empty);
|
||||
Assert.That(er.Cells.Select(ec => ec.IsDirty), Has.All.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditRowWithDefaultValue()
|
||||
{
|
||||
// Setup: Generate a row create with default values
|
||||
@@ -435,19 +436,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... The row should not be clean
|
||||
Assert.True(er.IsDirty);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
|
||||
// ... The row sould have a bunch of default values (equal to number of columns) and all are dirty
|
||||
Assert.Equal(rc.newCells.Length, er.Cells.Length);
|
||||
Assert.All(er.Cells, ec =>
|
||||
{
|
||||
Assert.Equal(Common.DefaultValue, ec.DisplayValue);
|
||||
Assert.False(ec.IsNull); // TODO: Update when we support null default values better
|
||||
Assert.True(ec.IsDirty);
|
||||
});
|
||||
Assert.AreEqual(rc.newCells.Length, er.Cells.Length);
|
||||
Assert.That(er.Cells.Select(ec => ec.DisplayValue), Has.All.EqualTo(Common.DefaultValue));
|
||||
Assert.That(er.Cells.Select(ec => ec.IsDirty), Has.All.True);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditRowWithCalculatedValue()
|
||||
{
|
||||
// Setup: Generate a row create with an identity column
|
||||
@@ -462,28 +459,23 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Then:
|
||||
// ... The row should not be null
|
||||
Assert.NotNull(er);
|
||||
Assert.Equal(er.Id, rowId);
|
||||
Assert.AreEqual(er.Id, rowId);
|
||||
|
||||
// ... The row should not be clean
|
||||
Assert.True(er.IsDirty);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
|
||||
// ... The row should have a TBD for the identity column
|
||||
Assert.Equal(rc.newCells.Length, er.Cells.Length);
|
||||
Assert.Equal(SR.EditDataComputedColumnPlaceholder, er.Cells[0].DisplayValue);
|
||||
Assert.AreEqual(rc.newCells.Length, er.Cells.Length);
|
||||
Assert.AreEqual(SR.EditDataComputedColumnPlaceholder, er.Cells[0].DisplayValue);
|
||||
Assert.False(er.Cells[0].IsNull);
|
||||
Assert.True(er.Cells[0].IsDirty);
|
||||
|
||||
// ... The rest of the cells should have empty display values
|
||||
Assert.All(er.Cells.Skip(1), ec =>
|
||||
{
|
||||
Assert.Equal(string.Empty, ec.DisplayValue);
|
||||
Assert.False(ec.IsNull);
|
||||
Assert.True(ec.IsDirty);
|
||||
});
|
||||
Assert.True(er.Cells[0].IsDirty);
|
||||
|
||||
// ... The rest of the cells should have empty display values
|
||||
Assert.That(er.Cells.Skip(1).Select(ec => new { ec.DisplayValue, ec.IsNull, ec.IsDirty }), Has.All.EqualTo(new { DisplayValue = string.Empty, IsNull = false, IsDirty = true }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditRowWithAdditions()
|
||||
{
|
||||
// Setp: Generate a row create with a cell added to it
|
||||
@@ -497,14 +489,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Then:
|
||||
// ... The row should not be null and contain the same number of cells as columns
|
||||
Assert.NotNull(er);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
|
||||
// ... The row should not be clean
|
||||
Assert.True(er.IsDirty);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyInsert, er.State);
|
||||
|
||||
// ... The row should have a single non-empty cell at the beginning that is dirty
|
||||
Assert.Equal(setValue, er.Cells[0].DisplayValue);
|
||||
Assert.AreEqual(setValue, er.Cells[0].DisplayValue);
|
||||
Assert.False(er.Cells[0].IsNull);
|
||||
Assert.True(er.Cells[0].IsDirty);
|
||||
|
||||
@@ -512,7 +504,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
for (int i = 1; i < er.Cells.Length; i++)
|
||||
{
|
||||
EditCell ec = er.Cells[i];
|
||||
Assert.Equal(string.Empty, ec.DisplayValue);
|
||||
Assert.AreEqual(string.Empty, ec.DisplayValue);
|
||||
Assert.False(ec.IsNull);
|
||||
Assert.True(ec.IsDirty);
|
||||
}
|
||||
@@ -522,11 +514,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region SetCell Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public async Task SetCellOutOfRange(int columnId)
|
||||
[Test]
|
||||
public async Task SetCellOutOfRange([Values(-1, 3, 100)]int columnId)
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
@@ -535,7 +524,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => rc.SetCell(columnId, string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCellNoChange()
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
@@ -549,7 +538,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... The returned value should be equal to what we provided
|
||||
Assert.NotNull(eucr);
|
||||
Assert.NotNull(eucr.Cell);
|
||||
Assert.Equal(updateValue, eucr.Cell.DisplayValue);
|
||||
Assert.AreEqual(updateValue, eucr.Cell.DisplayValue);
|
||||
Assert.False(eucr.Cell.IsNull);
|
||||
|
||||
// ... The returned value should be dirty
|
||||
@@ -562,7 +551,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(rc.newCells[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCellHasCorrections()
|
||||
{
|
||||
// Setup:
|
||||
@@ -591,7 +580,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... The returned value should be equal to what we provided
|
||||
Assert.NotNull(eucr);
|
||||
Assert.NotNull(eucr.Cell);
|
||||
Assert.NotEqual("1000", eucr.Cell.DisplayValue);
|
||||
Assert.That(eucr.Cell.DisplayValue, Is.Not.EqualTo("1000"));
|
||||
Assert.False(eucr.Cell.IsNull);
|
||||
|
||||
// ... The returned value should be dirty
|
||||
@@ -604,7 +593,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(rc.newCells[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCellNull()
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
@@ -620,7 +609,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... The returned value should be equal to what we provided
|
||||
Assert.NotNull(eucr);
|
||||
Assert.NotNull(eucr.Cell);
|
||||
Assert.Equal(nullValue, eucr.Cell.DisplayValue);
|
||||
Assert.AreEqual(nullValue, eucr.Cell.DisplayValue);
|
||||
Assert.True(eucr.Cell.IsNull);
|
||||
|
||||
// ... The returned value should be dirty
|
||||
@@ -637,11 +626,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region RevertCell Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public async Task RevertCellOutOfRange(int columnId)
|
||||
[Test]
|
||||
public async Task RevertCellOutOfRange([Values(-1,3,100)]int columnId)
|
||||
{
|
||||
// Setup: Generate the row create
|
||||
RowCreate rc = await GetStandardRowCreate();
|
||||
@@ -651,10 +637,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => rc.RevertCell(columnId));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(0)]
|
||||
public async Task RevertCellNotSet(int defaultCols)
|
||||
[Test]
|
||||
public async Task RevertCellNotSet([Values(0,1)]int defaultCols)
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate the parameters for the row create
|
||||
@@ -672,7 +656,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... We should get back an edit cell with a value based on the default value
|
||||
string expectedDisplayValue = defaultCols > 0 ? Common.DefaultValue : string.Empty;
|
||||
Assert.NotNull(result.Cell);
|
||||
Assert.Equal(expectedDisplayValue, result.Cell.DisplayValue);
|
||||
Assert.AreEqual(expectedDisplayValue, result.Cell.DisplayValue);
|
||||
Assert.False(result.Cell.IsNull); // TODO: Modify to support null defaults
|
||||
|
||||
// ... The row should be dirty
|
||||
@@ -682,10 +666,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Null(rc.newCells[0]);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(0)]
|
||||
public async Task RevertCellThatWasSet(int defaultCols)
|
||||
[Test]
|
||||
public async Task RevertCellThatWasSet([Values(0, 1)] int defaultCols)
|
||||
{
|
||||
// Setup:
|
||||
// ... Generate the parameters for the row create
|
||||
@@ -704,7 +686,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... We should get back an edit cell with a value based on the default value
|
||||
string expectedDisplayValue = defaultCols > 0 ? Common.DefaultValue : string.Empty;
|
||||
Assert.NotNull(result.Cell);
|
||||
Assert.Equal(expectedDisplayValue, result.Cell.DisplayValue);
|
||||
Assert.AreEqual(expectedDisplayValue, result.Cell.DisplayValue);
|
||||
Assert.False(result.Cell.IsNull); // TODO: Modify to support null defaults
|
||||
|
||||
// ... The row should be dirty
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,13 +17,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public class RowEditBaseTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructWithoutExtendedMetadata()
|
||||
{
|
||||
// Setup: Create a table metadata that has not been extended
|
||||
@@ -34,11 +34,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentException>(() => new RowEditTester(null, etm));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative index
|
||||
[InlineData(2)] // Equal to count of columns
|
||||
[InlineData(100)] // Index larger than number of columns
|
||||
public async Task ValidateUpdatableColumnOutOfRange(int columnId)
|
||||
[Test]
|
||||
public async Task ValidateUpdatableColumnOutOfRange([Values(-1,2,100)]int columnId)
|
||||
{
|
||||
// Setup: Create a result set
|
||||
var rs = await GetResultSet(
|
||||
@@ -55,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => tester.ValidateColumn(columnId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ValidateUpdatableColumnNotUpdatable()
|
||||
{
|
||||
// Setup: Create a result set with an identity column
|
||||
@@ -73,8 +70,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => tester.ValidateColumn(0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetWhereClauseIsNotNullData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(GetWhereClauseIsNotNullData))]
|
||||
public async Task GetWhereClauseSimple(DbColumn col, object val, string nullClause)
|
||||
{
|
||||
// Setup: Create a result set and metadata provider with a single column
|
||||
@@ -124,7 +121,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetWhereClauseMultipleKeyColumns()
|
||||
{
|
||||
// Setup: Create a result set and metadata provider with multiple key columns
|
||||
@@ -136,7 +133,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
rt.ValidateWhereClauseMultipleKeys();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetWhereClauseNoKeyColumns()
|
||||
{
|
||||
// Setup: Create a result set and metadata provider with no key columns
|
||||
@@ -148,7 +145,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
rt.ValidateWhereClauseNoKeys();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SortingByTypeTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
@@ -164,12 +161,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
};
|
||||
rowEdits.Sort();
|
||||
|
||||
// Then: Delete should be the last operation to execute
|
||||
// Then:
|
||||
// (we don't care about the order of the other two)
|
||||
Assert.IsType<RowDelete>(rowEdits.Last());
|
||||
Assert.That(rowEdits.Last(), Is.InstanceOf<RowDelete>(), "Delete should be the last operation to execute");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SortingUpdatesByRowIdTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
@@ -186,12 +183,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
rowEdits.Sort();
|
||||
|
||||
// Then: They should be in order by row ID ASCENDING
|
||||
Assert.Equal(1, rowEdits[0].RowId);
|
||||
Assert.Equal(2, rowEdits[1].RowId);
|
||||
Assert.Equal(3, rowEdits[2].RowId);
|
||||
Assert.AreEqual(1, rowEdits[0].RowId);
|
||||
Assert.AreEqual(2, rowEdits[1].RowId);
|
||||
Assert.AreEqual(3, rowEdits[2].RowId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SortingCreatesByRowIdTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
@@ -208,12 +205,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
rowEdits.Sort();
|
||||
|
||||
// Then: They should be in order by row ID ASCENDING
|
||||
Assert.Equal(1, rowEdits[0].RowId);
|
||||
Assert.Equal(2, rowEdits[1].RowId);
|
||||
Assert.Equal(3, rowEdits[2].RowId);
|
||||
Assert.AreEqual(1, rowEdits[0].RowId);
|
||||
Assert.AreEqual(2, rowEdits[1].RowId);
|
||||
Assert.AreEqual(3, rowEdits[2].RowId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SortingDeletesByRowIdTest()
|
||||
{
|
||||
// Setup: Create a result set and metadata we can reuse
|
||||
@@ -230,9 +227,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
rowEdits.Sort();
|
||||
|
||||
// Then: They should be in order by row ID DESCENDING
|
||||
Assert.Equal(3, rowEdits[0].RowId);
|
||||
Assert.Equal(2, rowEdits[1].RowId);
|
||||
Assert.Equal(1, rowEdits[2].RowId);
|
||||
Assert.AreEqual(3, rowEdits[0].RowId);
|
||||
Assert.AreEqual(2, rowEdits[1].RowId);
|
||||
Assert.AreEqual(1, rowEdits[2].RowId);
|
||||
}
|
||||
|
||||
private static async Task<ResultSet> GetResultSet(DbColumn[] columns, object[] row)
|
||||
@@ -262,18 +259,17 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... There should only be one component
|
||||
Assert.Equal(1, wc.ClauseComponents.Count);
|
||||
Assert.AreEqual(1, wc.ClauseComponents.Count);
|
||||
|
||||
// ... Parameterization should be empty
|
||||
Assert.Empty(wc.Parameters);
|
||||
Assert.That(wc.Parameters, Is.Empty, "Parameterization should be empty");
|
||||
|
||||
// ... The component should contain the name of the column and be null
|
||||
Assert.Equal(
|
||||
Assert.AreEqual(
|
||||
$"({AssociatedObjectMetadata.Columns.First().EscapedName} {nullValue})",
|
||||
wc.ClauseComponents[0]);
|
||||
|
||||
// ... The complete clause should contain a single WHERE
|
||||
Assert.Equal($"WHERE {wc.ClauseComponents[0]}", wc.CommandText);
|
||||
Assert.AreEqual($"WHERE {wc.ClauseComponents[0]}", wc.CommandText);
|
||||
}
|
||||
|
||||
public void ValidateWhereClauseMultipleKeys()
|
||||
@@ -284,14 +280,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Then:
|
||||
// ... There should two components
|
||||
var keys = AssociatedObjectMetadata.KeyColumns.ToArray();
|
||||
Assert.Equal(keys.Length, wc.ClauseComponents.Count);
|
||||
Assert.AreEqual(keys.Length, wc.ClauseComponents.Count);
|
||||
|
||||
// ... Parameterization should be empty
|
||||
Assert.Empty(wc.Parameters);
|
||||
Assert.That(wc.Parameters, Is.Empty, "Parameterization should be empty");
|
||||
|
||||
// ... The components should contain the name of the column and the value
|
||||
Regex r = new Regex(@"\([0-9a-z]+ = .+\)");
|
||||
Assert.All(wc.ClauseComponents, s => Assert.True(r.IsMatch(s)));
|
||||
Assert.That(wc.ClauseComponents, Has.All.Match(@"\([0-9a-z]+ = .+\)"), "The components should contain the name of the column and the value");
|
||||
|
||||
// ... The complete clause should contain multiple cause components joined
|
||||
// with and
|
||||
|
||||
@@ -15,13 +15,13 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
public class RowUpdateTests
|
||||
{
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RowUpdateConstruction()
|
||||
{
|
||||
// Setup: Create the values to store
|
||||
@@ -33,18 +33,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
RowUpdate rc = new RowUpdate(rowId, rs, data.TableMetadata);
|
||||
|
||||
// Then: The values I provided should be available
|
||||
Assert.Equal(rowId, rc.RowId);
|
||||
Assert.Equal(rs, rc.AssociatedResultSet);
|
||||
Assert.Equal(data.TableMetadata, rc.AssociatedObjectMetadata);
|
||||
Assert.AreEqual(rowId, rc.RowId);
|
||||
Assert.AreEqual(rs, rc.AssociatedResultSet);
|
||||
Assert.AreEqual(data.TableMetadata, rc.AssociatedObjectMetadata);
|
||||
}
|
||||
|
||||
#region SetCell Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public async Task SetCellOutOfRange(int columnId)
|
||||
[Test]
|
||||
public async Task SetCellOutOfRange([Values(-1,3,100)]int columnId)
|
||||
{
|
||||
// Setup: Generate a row create
|
||||
RowUpdate ru = await GetStandardRowUpdate();
|
||||
@@ -53,7 +50,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => ru.SetCell(columnId, string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCellImplicitRevertTest()
|
||||
{
|
||||
// Setup: Create a fake table to update
|
||||
@@ -74,7 +71,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(eucr.Cell);
|
||||
|
||||
// ... The new value we provided should be returned
|
||||
Assert.Equal(rs.GetRow(0)[1].DisplayValue, eucr.Cell.DisplayValue);
|
||||
Assert.AreEqual(rs.GetRow(0)[1].DisplayValue, eucr.Cell.DisplayValue);
|
||||
Assert.False(eucr.Cell.IsNull);
|
||||
|
||||
// ... The cell should be clean
|
||||
@@ -90,11 +87,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... It should have 2 updates
|
||||
string updates = m.Groups[1].Value;
|
||||
string[] updateSplit = updates.Split(',');
|
||||
Assert.Equal(2, updateSplit.Length);
|
||||
Assert.All(updateSplit, s => Assert.Equal(2, s.Split('=').Length));
|
||||
Assert.AreEqual(2, updateSplit.Length);
|
||||
Assert.That(updateSplit.Select(s => s.Split('=').Length), Has.All.EqualTo(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCellImplicitRowRevertTests()
|
||||
{
|
||||
// Setup: Create a fake column to update
|
||||
@@ -115,7 +112,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(eucr.Cell);
|
||||
|
||||
// ... The old value should be returned
|
||||
Assert.Equal(rs.GetRow(0)[1].DisplayValue, eucr.Cell.DisplayValue);
|
||||
Assert.AreEqual(rs.GetRow(0)[1].DisplayValue, eucr.Cell.DisplayValue);
|
||||
Assert.False(eucr.Cell.IsNull);
|
||||
|
||||
// ... The cell should be clean
|
||||
@@ -127,7 +124,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// TODO: Make sure that the script and command things will return null
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SetCellHasCorrections()
|
||||
{
|
||||
// Setup:
|
||||
@@ -161,8 +158,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(eucr.Cell);
|
||||
|
||||
// ... The value we used won't be returned
|
||||
Assert.NotEmpty(eucr.Cell.DisplayValue);
|
||||
Assert.NotEqual("1000", eucr.Cell.DisplayValue);
|
||||
Assert.That(eucr.Cell.DisplayValue, Is.Not.Empty);
|
||||
Assert.That(eucr.Cell.DisplayValue, Is.Not.EqualTo("1000"));
|
||||
Assert.False(eucr.Cell.IsNull);
|
||||
|
||||
// ... The cell should be dirty
|
||||
@@ -172,11 +169,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(eucr.IsRowDirty);
|
||||
|
||||
// ... There should be a cell update in the cell list
|
||||
Assert.Contains(0, ru.cellUpdates.Keys);
|
||||
Assert.That(ru.cellUpdates.Keys, Has.Member(0));
|
||||
Assert.NotNull(ru.cellUpdates[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SetCell()
|
||||
{
|
||||
// Setup: Create a row update
|
||||
@@ -191,7 +188,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.NotNull(eucr.Cell);
|
||||
|
||||
// ... The new value we provided should be returned
|
||||
Assert.Equal("col1", eucr.Cell.DisplayValue);
|
||||
Assert.AreEqual("col1", eucr.Cell.DisplayValue);
|
||||
Assert.False(eucr.Cell.IsNull);
|
||||
|
||||
// ... The row is still dirty
|
||||
@@ -201,16 +198,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(eucr.Cell.IsDirty);
|
||||
|
||||
// ... There should be a cell update in the cell list
|
||||
Assert.Contains(0, ru.cellUpdates.Keys);
|
||||
Assert.That(ru.cellUpdates.Keys, Has.Member(0));
|
||||
Assert.NotNull(ru.cellUpdates[0]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task GetScriptTest(bool isMemoryOptimized)
|
||||
[Test]
|
||||
public async Task GetScriptTest([Values]bool isMemoryOptimized)
|
||||
{
|
||||
// Setup: Create a fake table to update
|
||||
var data = new Common.TestDbColumnsWithTableMetadata(isMemoryOptimized, true, 0, 0);
|
||||
@@ -237,19 +232,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
string tbl = m.Groups[1].Value;
|
||||
string updates = m.Groups[2].Value;
|
||||
string[] updateSplit = updates.Split(',');
|
||||
Assert.Equal(data.TableMetadata.EscapedMultipartName, tbl);
|
||||
Assert.Equal(3, updateSplit.Length);
|
||||
Assert.All(updateSplit, s => Assert.Equal(2, s.Split('=').Length));
|
||||
Assert.AreEqual(data.TableMetadata.EscapedMultipartName, tbl);
|
||||
Assert.AreEqual(3, updateSplit.Length);
|
||||
Assert.That(updateSplit.Select(s => s.Split('=').Length), Has.All.EqualTo(2));
|
||||
}
|
||||
|
||||
#region GetCommand Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(true, true)]
|
||||
[InlineData(true, false)]
|
||||
[InlineData(false, true)]
|
||||
[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 update with cell updates
|
||||
@@ -284,7 +275,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Correct number of columns in declared table
|
||||
string[] declareCols = declareMatch.Groups[2].Value.Split(", ");
|
||||
Assert.Equal(rs.Columns.Length, declareCols.Length);
|
||||
Assert.AreEqual(rs.Columns.Length, declareCols.Length);
|
||||
|
||||
// Check the update statement in the middle
|
||||
string regex = isMemoryOptimized
|
||||
@@ -295,21 +286,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(updateMatch.Success);
|
||||
|
||||
// Table name matches
|
||||
Assert.Equal(Common.TableName, updateMatch.Groups[1].Value);
|
||||
Assert.AreEqual(Common.TableName, updateMatch.Groups[1].Value);
|
||||
|
||||
// Output columns match
|
||||
string[] outCols = updateMatch.Groups[3].Value.Split(", ");
|
||||
Assert.Equal(rs.Columns.Length, outCols.Length);
|
||||
Assert.All(outCols, col => Assert.StartsWith("inserted.", col));
|
||||
Assert.AreEqual(rs.Columns.Length, outCols.Length);
|
||||
Assert.That(outCols, Has.All.StartsWith("inserted."));
|
||||
|
||||
// Set columns match
|
||||
string[] setCols = updateMatch.Groups[2].Value.Split(", ");
|
||||
Assert.Equal(3, setCols.Length);
|
||||
Assert.All(setCols, s => Assert.Matches(@".+ = @Value\d+_\d+", s));
|
||||
|
||||
// Output table name matches
|
||||
Assert.StartsWith("Update", updateMatch.Groups[4].Value);
|
||||
Assert.EndsWith("Output", updateMatch.Groups[4].Value);
|
||||
Assert.AreEqual(3, setCols.Length);
|
||||
Assert.That(setCols, Has.All.Match(@".+ = @Value\d+_\d+"), "Set columns match");
|
||||
|
||||
// Output table name matches
|
||||
Assert.That(updateMatch.Groups[4].Value, Does.StartWith("Update"));
|
||||
Assert.That(updateMatch.Groups[4].Value, Does.EndWith("Output"));
|
||||
|
||||
// Check the select statement last
|
||||
Regex selectRegex = new Regex(@"^SELECT (.+) FROM @(.+)$");
|
||||
@@ -318,19 +308,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Correct number of columns in select statement
|
||||
string[] selectCols = selectMatch.Groups[1].Value.Split(", ");
|
||||
Assert.Equal(rs.Columns.Length, selectCols.Length);
|
||||
Assert.AreEqual(rs.Columns.Length, selectCols.Length);
|
||||
|
||||
// Select table name matches
|
||||
Assert.StartsWith("Update", selectMatch.Groups[2].Value);
|
||||
Assert.EndsWith("Output", selectMatch.Groups[2].Value);
|
||||
Assert.That(selectMatch.Groups[2].Value, Does.StartWith("Update"));
|
||||
Assert.That(selectMatch.Groups[2].Value, Does.EndWith("Output"));
|
||||
|
||||
// ... There should be an appropriate number of parameters in it
|
||||
// (1 or 3 keys, 3 value parameters)
|
||||
int expectedKeys = includeIdentity ? 1 : 3;
|
||||
Assert.Equal(expectedKeys + 3, cmd.Parameters.Count);
|
||||
Assert.AreEqual(expectedKeys + 3, cmd.Parameters.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetCommandNullConnection()
|
||||
{
|
||||
// Setup: Create a row update
|
||||
@@ -345,7 +335,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region GetEditRow Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditRow()
|
||||
{
|
||||
// Setup: Create a row update with a cell set
|
||||
@@ -361,31 +351,31 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Then:
|
||||
// ... The state should be dirty
|
||||
Assert.True(er.IsDirty);
|
||||
Assert.Equal(EditRow.EditRowState.DirtyUpdate, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyUpdate, 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, except for the updated cell
|
||||
Assert.Equal(cells.Length, er.Cells.Length);
|
||||
Assert.AreEqual(cells.Length, er.Cells.Length);
|
||||
for (int i = 1; i < cells.Length; i++)
|
||||
{
|
||||
DbCellValue originalCell = cells[i];
|
||||
DbCellValue 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);
|
||||
// Note: No real need to check the RawObject property
|
||||
}
|
||||
|
||||
// ... The updated cell should match what it was set to and be dirty
|
||||
EditCell newCell = er.Cells[0];
|
||||
Assert.Equal("foo", newCell.DisplayValue);
|
||||
Assert.AreEqual("foo", newCell.DisplayValue);
|
||||
Assert.False(newCell.IsNull);
|
||||
Assert.True(newCell.IsDirty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetEditNullRow()
|
||||
{
|
||||
// Setup: Create a row update
|
||||
@@ -400,10 +390,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region ApplyChanges Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task ApplyChanges(bool includeIdentity)
|
||||
[Test]
|
||||
public async Task ApplyChanges([Values] bool includeIdentity)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row update (no cell updates needed)
|
||||
@@ -420,11 +408,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... The result set should have the same number of rows as before
|
||||
Assert.Equal(1, rs.RowCount);
|
||||
Assert.AreEqual(1, rs.RowCount);
|
||||
Assert.True(oldBytesWritten < rs.totalBytesWritten);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ApplyChangesNullReader()
|
||||
{
|
||||
// Setup:
|
||||
@@ -435,18 +423,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// If: I ask for the changes to be applied with a null db reader
|
||||
// Then: I should get an exception
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => ru.ApplyChanges(null));
|
||||
Assert.ThrowsAsync<ArgumentNullException>(() => ru.ApplyChanges(null));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RevertCell Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative
|
||||
[InlineData(3)] // At edge of acceptable values
|
||||
[InlineData(100)] // Way too large value
|
||||
public async Task RevertCellOutOfRange(int columnId)
|
||||
[Test]
|
||||
public async Task RevertCellOutOfRange([Values(-1, 3, 100)] int columnId)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a row update (no cell updates needed)
|
||||
@@ -459,7 +444,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => ru.RevertCell(columnId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertCellNotSet()
|
||||
{
|
||||
// Setup:
|
||||
@@ -478,16 +463,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... We should get the original value back
|
||||
// @TODO: Check for a default value when we support it
|
||||
Assert.NotNull(result.Cell);
|
||||
Assert.Equal(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue);
|
||||
Assert.AreEqual(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue);
|
||||
|
||||
// ... The row should be clean
|
||||
Assert.False(result.IsRowDirty);
|
||||
|
||||
// ... The cell should no longer be set
|
||||
Assert.DoesNotContain(0, ru.cellUpdates.Keys);
|
||||
Assert.That(ru.cellUpdates.Keys, Has.None.Zero, "The cell should no longer be set");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertCellThatWasSet()
|
||||
{
|
||||
// Setup:
|
||||
@@ -508,16 +492,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... We should get the original value back
|
||||
// @TODO: Check for a default value when we support it
|
||||
Assert.NotNull(result.Cell);
|
||||
Assert.Equal(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue);
|
||||
Assert.AreEqual(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue);
|
||||
|
||||
// ... The row should be dirty still
|
||||
Assert.True(result.IsRowDirty);
|
||||
|
||||
// ... The cell should no longer be set
|
||||
Assert.DoesNotContain(0, ru.cellUpdates.Keys);
|
||||
Assert.That(ru.cellUpdates.Keys, Has.None.Zero, "The cell should no longer be set");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertCellRevertsRow()
|
||||
{
|
||||
// Setup:
|
||||
@@ -537,13 +520,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... We should get the original value back
|
||||
// @TODO: Check for a default value when we support it
|
||||
Assert.NotNull(result.Cell);
|
||||
Assert.Equal(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue);
|
||||
Assert.AreEqual(rs.GetRow(0)[0].DisplayValue, result.Cell.DisplayValue);
|
||||
|
||||
// ... The row should now be reverted
|
||||
Assert.False(result.IsRowDirty);
|
||||
|
||||
// ... The cell should no longer be set
|
||||
Assert.DoesNotContain(0, ru.cellUpdates.Keys);
|
||||
Assert.That(ru.cellUpdates.Keys, Has.None.Zero, "The cell should no longer be set");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -7,6 +7,7 @@ using System;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlServer.Dac.Model;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData;
|
||||
using Microsoft.SqlTools.ServiceLayer.EditData.Contracts;
|
||||
@@ -17,7 +18,7 @@ using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts.ExecuteRequests;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
@@ -25,12 +26,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
#region EditSession Operation Helper Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" \t\n\r")]
|
||||
[InlineData("Does not exist")]
|
||||
public async Task NullOrMissingSessionId(string sessionId)
|
||||
[Test]
|
||||
public async Task NullOrMissingSessionId([Values(null, "", " \t\n\r", "Does not exist")] string sessionId)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a edit data service
|
||||
@@ -48,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task OperationThrows()
|
||||
{
|
||||
// Setup:
|
||||
@@ -74,12 +71,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region Dispose Tests
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" \t\n\r")]
|
||||
[InlineData("Does not exist")]
|
||||
public async Task DisposeNullOrMissingSessionId(string sessionId)
|
||||
[Test]
|
||||
public async Task DisposeNullOrMissingSessionId([Values(null, "", " \t\n\r", "Does not exist")] string sessionId)
|
||||
{
|
||||
// Setup: Create a edit data service
|
||||
var eds = new EditDataService(null, null, null);
|
||||
@@ -93,7 +86,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
efv.Validate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task DisposeSuccess()
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
@@ -110,13 +103,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// ... It should have completed successfully
|
||||
efv.Validate();
|
||||
|
||||
// ... And the session should have been removed from the active session list
|
||||
Assert.Empty(eds.ActiveSessions);
|
||||
Assert.That(eds.ActiveSessions, Is.Empty, "And the session should have been removed from the active session list");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task DeleteSuccess()
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
@@ -138,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(s.EditCache.Any(e => e.Value is RowDelete));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CreateSucceeds()
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
@@ -160,7 +152,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(s.EditCache.Any(e => e.Value is RowCreate));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertCellSucceeds()
|
||||
{
|
||||
// Setup:
|
||||
@@ -193,10 +185,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... The edit cache should be empty again
|
||||
EditSession s = eds.ActiveSessions[Constants.OwnerUri];
|
||||
Assert.Empty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertRowSucceeds()
|
||||
{
|
||||
// Setup: Create an edit data service with a session that has an pending edit
|
||||
@@ -217,10 +209,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... The edit cache should be empty again
|
||||
EditSession s = eds.ActiveSessions[Constants.OwnerUri];
|
||||
Assert.Empty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task UpdateSuccess()
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
@@ -254,7 +246,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
edit.Verify(e => e.SetCell(It.IsAny<int>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetRowsSuccess()
|
||||
{
|
||||
// Setup: Create an edit data service with a session
|
||||
@@ -268,8 +260,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
.AddResultValidation(esr =>
|
||||
{
|
||||
Assert.NotNull(esr);
|
||||
Assert.NotEmpty(esr.Subset);
|
||||
Assert.NotEqual(0, esr.RowCount);
|
||||
Assert.That(esr.Subset, Is.Not.Empty);
|
||||
Assert.That(esr.RowCount, Is.Not.EqualTo(0));
|
||||
})
|
||||
.Complete();
|
||||
await eds.HandleSubsetRequest(new EditSubsetParams
|
||||
@@ -285,11 +277,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
|
||||
#region Initialize Tests
|
||||
[Theory]
|
||||
[InlineData(null, "table", "table")] // Null owner URI
|
||||
[InlineData(Common.OwnerUri, null, "table")] // Null object name
|
||||
[InlineData(Common.OwnerUri, "table", null)] // Null object type
|
||||
public async Task InitializeNullParams(string ownerUri, string objName, string objType)
|
||||
[Test]
|
||||
[Sequential]
|
||||
public async Task InitializeNullParams([Values(null, Common.OwnerUri, Common.OwnerUri)] string ownerUri,
|
||||
[Values("table", null, "table")] string objName,
|
||||
[Values("table", "table", null)] string objType)
|
||||
{
|
||||
// Setup: Create an edit data service without a session
|
||||
var eds = new EditDataService(null, null, null);
|
||||
@@ -314,10 +306,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
efv.Validate();
|
||||
|
||||
// ... There should not be a session
|
||||
Assert.Empty(eds.ActiveSessions);
|
||||
Assert.That(eds.ActiveSessions, Is.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InitializeSessionExists()
|
||||
{
|
||||
// Setup: Create an edit data service with a session already defined
|
||||
@@ -343,12 +335,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
efv.Validate();
|
||||
|
||||
// ... The original session should still be there
|
||||
Assert.Equal(1, eds.ActiveSessions.Count);
|
||||
Assert.Equal(session, eds.ActiveSessions[Constants.OwnerUri]);
|
||||
Assert.AreEqual(1, eds.ActiveSessions.Count);
|
||||
Assert.AreEqual(session, eds.ActiveSessions[Constants.OwnerUri]);
|
||||
}
|
||||
|
||||
// Disable flaky test for investigation (karlb - 3/13/2018)
|
||||
//[Fact]
|
||||
//[Test]
|
||||
public async Task InitializeSessionSuccess()
|
||||
{
|
||||
// Setup:
|
||||
@@ -391,7 +383,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
.AddEventValidation(EditSessionReadyEvent.Type, esrp =>
|
||||
{
|
||||
Assert.NotNull(esrp);
|
||||
Assert.Equal(Constants.OwnerUri, esrp.OwnerUri);
|
||||
Assert.AreEqual(Constants.OwnerUri, esrp.OwnerUri);
|
||||
Assert.True(esrp.Success);
|
||||
Assert.Null(esrp.Message);
|
||||
})
|
||||
@@ -404,17 +396,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
efv.Validate();
|
||||
|
||||
// ... The session should have been created
|
||||
Assert.Equal(1, eds.ActiveSessions.Count);
|
||||
Assert.AreEqual(1, eds.ActiveSessions.Count);
|
||||
Assert.True(eds.ActiveSessions.Keys.Contains(Constants.OwnerUri));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Theory]
|
||||
[InlineData("table", "myschema", new [] { "myschema", "table" })] // Use schema
|
||||
[InlineData("table", null, new [] { "table" })] // skip schema
|
||||
[InlineData("schema.table", "myschema", new [] { "myschema", "schema.table"})] // Use schema
|
||||
[InlineData("schema.table", null, new [] { "schema", "table"})] // Split object name into schema
|
||||
private static readonly object[] schemaNameParameters =
|
||||
{
|
||||
new object[] {"table", "myschema", new[] { "myschema", "table" } }, // Use schema
|
||||
new object[] {"table", null, new[] { "table" } }, // skip schema
|
||||
new object[] {"schema.table", "myschema", new[] { "myschema", "schema.table" } }, // Use schema
|
||||
new object[] {"schema.table", null, new[] { "schema", "table" } }, // Split object name into schema
|
||||
};
|
||||
|
||||
[Test, TestCaseSource(nameof(schemaNameParameters))]
|
||||
public void ShouldUseSchemaNameIfDefined(string objName, string schemaName, string[] expectedNameParts)
|
||||
{
|
||||
// Setup: Create an edit data service without a session
|
||||
@@ -434,7 +429,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
string[] nameParts = EditSession.GetEditTargetName(initParams);
|
||||
|
||||
// Then:
|
||||
Assert.Equal(expectedNameParts, nameParts);
|
||||
Assert.AreEqual(expectedNameParts, nameParts);
|
||||
}
|
||||
|
||||
private static async Task<EditSession> GetDefaultSession()
|
||||
|
||||
@@ -20,7 +20,7 @@ using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
@@ -28,7 +28,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
{
|
||||
#region Construction Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SessionConstructionNullMetadataFactory()
|
||||
{
|
||||
// If: I create a session object with a null metadata factory
|
||||
@@ -36,7 +36,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => new EditSession(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SessionConstructionValid()
|
||||
{
|
||||
// If: I create a session object with a proper arguments
|
||||
@@ -53,14 +53,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Null(s.CommitTask);
|
||||
|
||||
// ... The next row ID should be the default long
|
||||
Assert.Equal(default(long), s.NextRowId);
|
||||
Assert.AreEqual(default(long), s.NextRowId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Validate Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SessionValidateUnfinishedQuery()
|
||||
{
|
||||
// If: I create a session object with a query that hasn't finished execution
|
||||
@@ -70,7 +70,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => EditSession.ValidateQueryForSession(q));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SessionValidateIncorrectResultSet()
|
||||
{
|
||||
// Setup: Create a query that yields >1 result sets
|
||||
@@ -94,7 +94,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => EditSession.ValidateQueryForSession(query));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void SessionValidateValidResultSet()
|
||||
{
|
||||
// If: I validate a query for a session with a valid query
|
||||
@@ -109,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region Create Row Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CreateRowNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -122,7 +122,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.CreateRow());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CreateRowAddFailure()
|
||||
{
|
||||
// NOTE: This scenario should theoretically never occur, but is tested for completeness
|
||||
@@ -143,13 +143,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.CreateRow());
|
||||
|
||||
// ... The mock edit should still exist
|
||||
Assert.Equal(mockEdit, s.EditCache[rs.RowCount]);
|
||||
Assert.AreEqual(mockEdit, s.EditCache[rs.RowCount]);
|
||||
|
||||
// ... The next row ID should not have changes
|
||||
Assert.Equal(rs.RowCount, s.NextRowId);
|
||||
Assert.AreEqual(rs.RowCount, s.NextRowId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CreateRowSuccess()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
@@ -163,20 +163,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... The new ID should be equal to the row count
|
||||
Assert.Equal(rs.RowCount, result.NewRowId);
|
||||
Assert.AreEqual(rs.RowCount, result.NewRowId);
|
||||
|
||||
// ... The next row ID should have been incremented
|
||||
Assert.Equal(rs.RowCount + 1, s.NextRowId);
|
||||
Assert.AreEqual(rs.RowCount + 1, s.NextRowId);
|
||||
|
||||
// ... There should be a new row create object in the cache
|
||||
Assert.Contains(result.NewRowId, s.EditCache.Keys);
|
||||
Assert.IsType<RowCreate>(s.EditCache[result.NewRowId]);
|
||||
Assert.That(s.EditCache.Keys, Has.Member(result.NewRowId));
|
||||
Assert.That(s.EditCache[result.NewRowId], Is.InstanceOf<RowCreate>());
|
||||
|
||||
// ... The default values should be returned (we will test this in depth below)
|
||||
Assert.NotEmpty(result.DefaultValues);
|
||||
Assert.That(result.DefaultValues, Is.Not.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CreateRowDefaultTest()
|
||||
{
|
||||
// Setup:
|
||||
@@ -229,18 +229,18 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(result.NewRowId > 0);
|
||||
|
||||
// ... There should be 3 default values (3 columns)
|
||||
Assert.NotEmpty(result.DefaultValues);
|
||||
Assert.Equal(3, result.DefaultValues.Length);
|
||||
Assert.That(result.DefaultValues, Is.Not.Empty);
|
||||
Assert.AreEqual(3, result.DefaultValues.Length);
|
||||
|
||||
// ... There should be specific values for each kind of default
|
||||
Assert.Null(result.DefaultValues[0]);
|
||||
Assert.Equal("default", result.DefaultValues[1]);
|
||||
Assert.AreEqual("default", result.DefaultValues[1]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RowIdOutOfRangeData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(RowIdOutOfRangeData))]
|
||||
public async Task RowIdOutOfRange(long rowId, Action<EditSession, long> testAction)
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
@@ -285,7 +285,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region Initialize Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void InitializeAlreadyInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -298,7 +298,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.Initialize(null, null, null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void InitializeAlreadyInitializing()
|
||||
{
|
||||
// Setup:
|
||||
@@ -311,8 +311,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.Initialize(null, null, null, null, null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(InitializeNullParamsData))]
|
||||
[Test]
|
||||
[TestCaseSource(nameof(InitializeNullParamsData))]
|
||||
public void InitializeNullParams(EditInitializeParams initParams, EditSession.Connector c,
|
||||
EditSession.QueryRunner qr, Func<Task> sh, Func<Exception, Task> fh)
|
||||
{
|
||||
@@ -321,9 +321,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Mock<IEditMetadataFactory> emf = new Mock<IEditMetadataFactory>();
|
||||
EditSession s = new EditSession(emf.Object);
|
||||
|
||||
// If: I initialize it with a missing parameter
|
||||
// Then: It should throw an exception
|
||||
Assert.ThrowsAny<ArgumentException>(() => s.Initialize(initParams, c, qr, sh, fh));
|
||||
Assert.That(() => s.Initialize(initParams, c, qr, sh, fh), Throws.InstanceOf<ArgumentException>(), "I initialize it with a missing parameter. It should throw an exception");
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> InitializeNullParamsData
|
||||
@@ -376,7 +374,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InitializeMetadataFails()
|
||||
{
|
||||
// Setup:
|
||||
@@ -407,7 +405,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
successHandler.Verify(f => f(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InitializeQueryFailException()
|
||||
{
|
||||
// Setup:
|
||||
@@ -444,10 +442,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
successHandler.Verify(f => f(), Times.Never);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("It fail.")]
|
||||
public async Task InitializeQueryFailReturnNull(string message)
|
||||
[Test]
|
||||
public async Task InitializeQueryFailReturnNull([Values(null, "It fail.")] string message)
|
||||
{
|
||||
// Setup:
|
||||
// ... Create a metadata factory that will return some generic column information
|
||||
@@ -484,7 +480,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
successHandler.Verify(f => f(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task InitializeSuccess()
|
||||
{
|
||||
// Setup:
|
||||
@@ -521,16 +517,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// ... The session should have been initialized
|
||||
Assert.True(s.IsInitialized);
|
||||
Assert.Equal(rs.RowCount, s.NextRowId);
|
||||
Assert.AreEqual(rs.RowCount, s.NextRowId);
|
||||
Assert.NotNull(s.EditCache);
|
||||
Assert.Empty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delete Row Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void DeleteRowNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -543,7 +539,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.DeleteRow(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task DeleteRowAddFailure()
|
||||
{
|
||||
// Setup:
|
||||
@@ -560,10 +556,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.DeleteRow(0));
|
||||
|
||||
// ... The mock edit should still exist
|
||||
Assert.Equal(mockEdit, s.EditCache[0]);
|
||||
Assert.AreEqual(mockEdit, s.EditCache[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task DeleteRowSuccess()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
@@ -572,16 +568,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// If: I add a row to the session
|
||||
s.DeleteRow(0);
|
||||
|
||||
// Then: There should be a new row delete object in the cache
|
||||
Assert.Contains(0, s.EditCache.Keys);
|
||||
Assert.IsType<RowDelete>(s.EditCache[0]);
|
||||
Assert.That(s.EditCache.Keys, Has.Member(0));
|
||||
Assert.That(s.EditCache[0], Is.InstanceOf<RowDelete>(), "There should be a new row delete object in the cache");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Revert Row Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void RevertRowNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -594,7 +589,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.RevertRow(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertRowSuccess()
|
||||
{
|
||||
// Setup:
|
||||
@@ -608,16 +603,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// If: I revert the row that has a pending update
|
||||
s.RevertRow(0);
|
||||
|
||||
// Then:
|
||||
// ... The edit cache should not contain a pending edit for the row
|
||||
Assert.DoesNotContain(0, s.EditCache.Keys);
|
||||
Assert.That(s.EditCache.Keys, Has.No.Zero, "The edit cache should not contain a pending edit for the row");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Revert Cell Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void RevertCellNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -630,7 +623,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.RevertCell(0, 0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task RevertCellRowRevert()
|
||||
{
|
||||
// Setup:
|
||||
@@ -651,14 +644,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
mockEdit.Verify(e => e.RevertCell(0), Times.Once);
|
||||
|
||||
// ... The mock update should no longer be in the edit cache
|
||||
Assert.Empty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Update Cell Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void UpdateCellNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -671,7 +664,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.UpdateCell(0, 0, ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task UpdateCellExisting()
|
||||
{
|
||||
// Setup:
|
||||
@@ -690,10 +683,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
// Then:
|
||||
// ... The mock update should still be in the cache
|
||||
// ... And it should have had set cell called on it
|
||||
Assert.Contains(mockEdit.Object, s.EditCache.Values);
|
||||
Assert.That(s.EditCache.Values, Has.Member(mockEdit.Object));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task UpdateCellNew()
|
||||
{
|
||||
// Setup:
|
||||
@@ -704,12 +697,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
s.UpdateCell(0, 0, "");
|
||||
|
||||
// Then:
|
||||
// ... A new update row edit should have been added to the cache
|
||||
Assert.Contains(0, s.EditCache.Keys);
|
||||
Assert.IsType<RowUpdate>(s.EditCache[0]);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(s.EditCache.Keys, Has.Member(0));
|
||||
Assert.That(s.EditCache[0], Is.InstanceOf<RowUpdate>(), "A new update row edit should have been added to the cache");
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task UpdateCellRowRevert()
|
||||
{
|
||||
// Setup:
|
||||
@@ -730,7 +725,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
mockEdit.Verify(e => e.SetCell(0, null), Times.Once);
|
||||
|
||||
// ... The mock update should no longer be in the edit cache
|
||||
Assert.Empty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Empty);
|
||||
}
|
||||
|
||||
|
||||
@@ -739,7 +734,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region SubSet Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task SubsetNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -749,10 +744,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// If: I ask to update a cell without initializing
|
||||
// Then: I should get an exception
|
||||
await Assert.ThrowsAsync<InvalidOperationException>(() => s.GetRows(0, 100));
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => s.GetRows(0, 100));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetRowsNoEdits()
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
@@ -766,7 +761,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... I should get back 3 rows
|
||||
Assert.Equal(3, rows.Length);
|
||||
Assert.AreEqual(3, rows.Length);
|
||||
|
||||
// ... Each row should...
|
||||
for (int i = 0; i < rows.Length; i++)
|
||||
@@ -774,25 +769,25 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
EditRow er = rows[i];
|
||||
|
||||
// ... Have properly set IDs
|
||||
Assert.Equal(i + 1, er.Id);
|
||||
Assert.AreEqual(i + 1, er.Id);
|
||||
|
||||
// ... Have cells equal to the cells in the result set
|
||||
DbCellValue[] cachedRow = rs.GetRow(i + 1).ToArray();
|
||||
Assert.Equal(cachedRow.Length, er.Cells.Length);
|
||||
Assert.AreEqual(cachedRow.Length, er.Cells.Length);
|
||||
for (int j = 0; j < cachedRow.Length; j++)
|
||||
{
|
||||
Assert.Equal(cachedRow[j].DisplayValue, er.Cells[j].DisplayValue);
|
||||
Assert.Equal(cachedRow[j].IsNull, er.Cells[j].IsNull);
|
||||
Assert.AreEqual(cachedRow[j].DisplayValue, er.Cells[j].DisplayValue);
|
||||
Assert.AreEqual(cachedRow[j].IsNull, er.Cells[j].IsNull);
|
||||
Assert.False(er.Cells[j].IsDirty);
|
||||
}
|
||||
|
||||
// ... Be clean, since we didn't apply any updates
|
||||
Assert.Equal(EditRow.EditRowState.Clean, er.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.Clean, er.State);
|
||||
Assert.False(er.IsDirty);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetRowsPendingUpdate()
|
||||
{
|
||||
// Setup:
|
||||
@@ -807,22 +802,22 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... I should get back 3 rows
|
||||
Assert.Equal(3, rows.Length);
|
||||
Assert.AreEqual(3, rows.Length);
|
||||
|
||||
// ... The first row should reflect that there is an update pending
|
||||
// (More in depth testing is done in the RowUpdate class tests)
|
||||
var updatedRow = rows[0];
|
||||
Assert.Equal(EditRow.EditRowState.DirtyUpdate, updatedRow.State);
|
||||
Assert.Equal("foo", updatedRow.Cells[0].DisplayValue);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyUpdate, updatedRow.State);
|
||||
Assert.AreEqual("foo", updatedRow.Cells[0].DisplayValue);
|
||||
|
||||
// ... The other rows should be clean
|
||||
for (int i = 1; i < rows.Length; i++)
|
||||
{
|
||||
Assert.Equal(EditRow.EditRowState.Clean, rows[i].State);
|
||||
Assert.AreEqual(EditRow.EditRowState.Clean, rows[i].State);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetRowsPendingDeletion()
|
||||
{
|
||||
// Setup:
|
||||
@@ -837,22 +832,22 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... I should get back 3 rows
|
||||
Assert.Equal(3, rows.Length);
|
||||
Assert.AreEqual(3, rows.Length);
|
||||
|
||||
// ... The first row should reflect that there is an update pending
|
||||
// (More in depth testing is done in the RowUpdate class tests)
|
||||
var updatedRow = rows[0];
|
||||
Assert.Equal(EditRow.EditRowState.DirtyDelete, updatedRow.State);
|
||||
Assert.NotEmpty(updatedRow.Cells[0].DisplayValue);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyDelete, updatedRow.State);
|
||||
Assert.That(updatedRow.Cells[0].DisplayValue, Is.Not.Empty);
|
||||
|
||||
// ... The other rows should be clean
|
||||
for (int i = 1; i < rows.Length; i++)
|
||||
{
|
||||
Assert.Equal(EditRow.EditRowState.Clean, rows[i].State);
|
||||
Assert.AreEqual(EditRow.EditRowState.Clean, rows[i].State);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetRowsPendingInsertion()
|
||||
{
|
||||
// Setup:
|
||||
@@ -867,20 +862,20 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... I should get back 6 rows
|
||||
Assert.Equal(6, rows.Length);
|
||||
Assert.AreEqual(6, rows.Length);
|
||||
|
||||
// ... The last row should reflect that there's a new row
|
||||
var updatedRow = rows[5];
|
||||
Assert.Equal(EditRow.EditRowState.DirtyInsert, updatedRow.State);
|
||||
Assert.AreEqual(EditRow.EditRowState.DirtyInsert, updatedRow.State);
|
||||
|
||||
// ... The other rows should be clean
|
||||
for (int i = 0; i < rows.Length - 1; i++)
|
||||
{
|
||||
Assert.Equal(EditRow.EditRowState.Clean, rows[i].State);
|
||||
Assert.AreEqual(EditRow.EditRowState.Clean, rows[i].State);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task GetRowsAllNew()
|
||||
{
|
||||
// Setup:
|
||||
@@ -897,17 +892,16 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... I should get back 3 rows back
|
||||
Assert.Equal(3, rows.Length);
|
||||
Assert.AreEqual(3, rows.Length);
|
||||
|
||||
// ... All the rows should be new
|
||||
Assert.All(rows, r => Assert.Equal(EditRow.EditRowState.DirtyInsert, r.State));
|
||||
Assert.That(rows.Select(r => r.State), Has.All.EqualTo(EditRow.EditRowState.DirtyInsert), "All the rows should be new");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Script Edits Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ScriptEditsNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -920,11 +914,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.ScriptEdits(string.Empty));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData(" \t\r\n")]
|
||||
public async Task ScriptNullOrEmptyOutput(string outputPath)
|
||||
[Test]
|
||||
public async Task ScriptNullOrEmptyOutput([Values(null, "", " \t\r\n")] string outputPath)
|
||||
{
|
||||
// Setup: Create a session with a proper query and metadata
|
||||
EditSession s = await GetBasicSession();
|
||||
@@ -934,7 +925,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => s.ScriptEdits(outputPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task ScriptProvidedOutputPath()
|
||||
{
|
||||
// Setup:
|
||||
@@ -954,10 +945,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
// Then:
|
||||
// ... The output path used should be the same as the one we provided
|
||||
Assert.Equal(file.FilePath, outputPath);
|
||||
Assert.AreEqual(file.FilePath, outputPath);
|
||||
|
||||
// ... The written file should have two lines, one for each edit
|
||||
Assert.Equal(2, File.ReadAllLines(outputPath).Length);
|
||||
Assert.AreEqual(2, File.ReadAllLines(outputPath).Length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,7 +956,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
|
||||
#region Commit Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void CommitEditsNotInitialized()
|
||||
{
|
||||
// Setup:
|
||||
@@ -978,7 +969,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<InvalidOperationException>(() => s.CommitEdits(null, null, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CommitNullConnection()
|
||||
{
|
||||
// Setup: Create a basic session
|
||||
@@ -990,7 +981,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
() => s.CommitEdits(null, () => Task.CompletedTask, e => Task.CompletedTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CommitNullSuccessHandler()
|
||||
{
|
||||
// Setup:
|
||||
@@ -1005,7 +996,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => s.CommitEdits(conn, null, e => Task.CompletedTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CommitNullFailureHandler()
|
||||
{
|
||||
// Setup:
|
||||
@@ -1020,7 +1011,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentNullException>(() => s.CommitEdits(conn, () => Task.CompletedTask, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CommitInProgress()
|
||||
{
|
||||
// Setup:
|
||||
@@ -1038,7 +1029,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
() => s.CommitEdits(conn, () => Task.CompletedTask, e => Task.CompletedTask));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CommitSuccess()
|
||||
{
|
||||
// Setup:
|
||||
@@ -1079,10 +1070,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
edit.Verify(e => e.ApplyChanges(It.IsAny<DbDataReader>()), Times.Once);
|
||||
|
||||
// ... The edit cache should be empty
|
||||
Assert.Empty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public async Task CommitFailure()
|
||||
{
|
||||
// Setup:
|
||||
@@ -1121,14 +1112,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
edit.Verify(e => e.GetCommand(conn), Times.Once);
|
||||
|
||||
// ... The edit cache should not be empty
|
||||
Assert.NotEmpty(s.EditCache);
|
||||
Assert.That(s.EditCache, Is.Not.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Construct Initialize Query Tests
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructQueryWithoutLimit()
|
||||
{
|
||||
// Setup: Create a metadata provider for some basic columns
|
||||
@@ -1148,16 +1139,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(match.Success);
|
||||
|
||||
// ... There should be columns in it
|
||||
Assert.Equal(data.DbColumns.Length, match.Groups[1].Value.Split(',').Length);
|
||||
Assert.AreEqual(data.DbColumns.Length, match.Groups[1].Value.Split(',').Length);
|
||||
|
||||
// ... The table name should be in it
|
||||
Assert.Equal(data.TableMetadata.EscapedMultipartName, match.Groups[2].Value);
|
||||
Assert.AreEqual(data.TableMetadata.EscapedMultipartName, match.Groups[2].Value);
|
||||
|
||||
// ... It should NOT have a TOP clause in it
|
||||
Assert.DoesNotContain("TOP", query);
|
||||
Assert.That(query, Does.Not.Contain("TOP"), "It should NOT have a TOP clause in it");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Test]
|
||||
public void ConstructQueryNegativeLimit()
|
||||
{
|
||||
// Setup: Create a metadata provider for some basic columns
|
||||
@@ -1172,11 +1162,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => EditSession.ConstructInitializeQuery(data.TableMetadata, eif));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // Yes, zero is valid
|
||||
[InlineData(10)]
|
||||
[InlineData(1000)]
|
||||
public void ConstructQueryWithLimit(int limit)
|
||||
[Test]
|
||||
public void ConstructQueryWithLimit([Values(0,10,1000)]int limit)
|
||||
{
|
||||
// Setup: Create a metadata provider for some basic columns
|
||||
var data = new Common.TestDbColumnsWithTableMetadata(false, false, 0, 0);
|
||||
@@ -1195,15 +1182,15 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
|
||||
Assert.True(match.Success);
|
||||
|
||||
// ... There should be columns in it
|
||||
Assert.Equal(data.DbColumns.Length, match.Groups[2].Value.Split(',').Length);
|
||||
Assert.AreEqual(data.DbColumns.Length, match.Groups[2].Value.Split(',').Length);
|
||||
|
||||
// ... The table name should be in it
|
||||
Assert.Equal(data.TableMetadata.EscapedMultipartName, match.Groups[3].Value);
|
||||
Assert.AreEqual(data.TableMetadata.EscapedMultipartName, match.Groups[3].Value);
|
||||
|
||||
// ... The top count should be equal to what we provided
|
||||
int limitFromQuery;
|
||||
Assert.True(int.TryParse(match.Groups[1].Value, out limitFromQuery));
|
||||
Assert.Equal(limit, limitFromQuery);
|
||||
Assert.AreEqual(limit, limitFromQuery);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user