Convert most tools service tests to nunit (#1037)

* Remove xunit dependency from testdriver

* swap expected/actual as needed

* Convert Test.Common to nunit

* port hosting unit tests to nunit

* port batchparser integration tests to nunit

* port testdriver.tests to nunit

* fix target to copy dependency

* port servicelayer unittests to nunit

* more unit test fixes

* port integration tests to nunit

* fix test method type

* try using latest windows build for PRs

* reduce test memory use
This commit is contained in:
David Shiflet
2020-08-05 13:43:14 -04:00
committed by GitHub
parent bf4911795f
commit 839acf67cd
205 changed files with 4146 additions and 4329 deletions

View File

@@ -4,13 +4,19 @@
//
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class BinaryQueryExpressionFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void BQE_IndentOperands()
{
FormatOptions options = new FormatOptions();
@@ -19,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("BQE_IndentOperands.sql"), options, true);
}
[Fact]
[Test]
public void BQE_KeywordCasing_UpperCase()
{
FormatOptions options = new FormatOptions();
@@ -28,7 +34,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("BQE_KeywordCasing_UpperCase.sql"), options, true);
}
[Fact]
[Test]
public void BQE_KeywordCasing_LowerCase()
{
FormatOptions options = new FormatOptions();
@@ -37,7 +43,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("BQE_KeywordCasing_LowerCase.sql"), options, true);
}
[Fact]
[Test]
public void BQE_KeywordCasing_NoFormat()
{
FormatOptions options = new FormatOptions();
@@ -46,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("BQE_KeywordCasing_NoFormat.sql"), options, true);
}
[Fact]
[Test]
public void BQE_OperatorsOnNewLine()
{
FormatOptions options = new FormatOptions();

View File

@@ -5,35 +5,41 @@
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class CommonTableExpressionFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void CTE()
{
LoadAndFormatAndCompare("CTE", GetInputFile("CTE.sql"),
GetBaselineFile("CTE.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CTE_OneColumn()
{
LoadAndFormatAndCompare("CTE_OneColumn", GetInputFile("CTE_OneColumn.sql"),
GetBaselineFile("CTE_OneColumn.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CTE_MultipleExpressions()
{
LoadAndFormatAndCompare("CTE_MultipleExpressions", GetInputFile("CTE_MultipleExpressions.sql"),
GetBaselineFile("CTE_MultipleExpressions.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CTE_CommasBeforeDefinition()
{
FormatOptions options = new FormatOptions();
@@ -44,7 +50,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("CTE_CommasBeforeDefinition.sql"), options, false);
}
[Fact]
[Test]
public void CTE_EachReferenceOnNewLine()
{
FormatOptions options = new FormatOptions();
@@ -54,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("CTE_EachReferenceOnNewLine.sql"), options, true);
}
[Fact]
[Test]
public void CTE_EachReferenceOnNewLine_CommasBeforeDefinition()
{
FormatOptions options = new FormatOptions();
@@ -66,7 +72,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("CTE_EachReferenceOnNewLine_CommasBeforeDefinition.sql"), options, false);
}
[Fact]
[Test]
public void CTE_UseTabs()
{
FormatOptions options = new FormatOptions();
@@ -76,7 +82,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("CTE_UseTabs.sql"), options, true);
}
[Fact]
[Test]
public void CTE_20Spaces()
{
FormatOptions options = new FormatOptions();
@@ -86,7 +92,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("CTE_20Spaces.sql"), options, true);
}
[Fact]
[Test]
public void CTE_UpperCaseKeywords()
{
FormatOptions options = new FormatOptions();
@@ -96,7 +102,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("CTE_UpperCaseKeywords.sql"), options, true);
}
[Fact]
[Test]
public void CTE_LowerCaseKeywords()
{
FormatOptions options = new FormatOptions();

View File

@@ -4,69 +4,75 @@
//
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class CreateProcedureFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void CreateProcedure_BackwardsCompatible()
{
LoadAndFormatAndCompare("CreateProcedure_BackwardsCompatible", GetInputFile("CreateProcedure_BackwardsCompatible.sql"),
GetBaselineFile("CreateProcedure_BackwardsCompatible.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_BeginEnd()
{
LoadAndFormatAndCompare("CreateProcedure_BeginEnd", GetInputFile("CreateProcedure_BeginEnd.sql"),
GetBaselineFile("CreateProcedure_BeginEnd.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_Minimal()
{
LoadAndFormatAndCompare("CreateProcedure_Minimal", GetInputFile("CreateProcedure_Minimal.sql"),
GetBaselineFile("CreateProcedure_Minimal.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_MultipleBatches()
{
LoadAndFormatAndCompare("CreateProcedure_MultipleBatches", GetInputFile("CreateProcedure_MultipleBatches.sql"),
GetBaselineFile("CreateProcedure_MultipleBatches.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_MultipleParams()
{
LoadAndFormatAndCompare("CreateProcedure_MultipleParams", GetInputFile("CreateProcedure_MultipleParams.sql"),
GetBaselineFile("CreateProcedure_MultipleParams.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_OneParam()
{
LoadAndFormatAndCompare("CreateProcedure_OneParam", GetInputFile("CreateProcedure_OneParam.sql"),
GetBaselineFile("CreateProcedure_OneParam.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_ParamsRecompileReturn()
{
LoadAndFormatAndCompare("CreateProcedure_ParamsRecompileReturn", GetInputFile("CreateProcedure_ParamsRecompileReturn.sql"),
GetBaselineFile("CreateProcedure_ParamsRecompileReturn.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_Select()
{
LoadAndFormatAndCompare("CreateProcedure_Select", GetInputFile("CreateProcedure_Select.sql"),
GetBaselineFile("CreateProcedure_Select.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_CommaBeforeNextColumn()
{
// Verifies that commas are placed before the next column instead of after the current one,
@@ -83,7 +89,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
}, true);
}
[Fact]
[Test]
public void CreateProcedure_CommaBeforeNextColumnRepeated()
{
// Verifies that formatting isn't changed for text that's already been formatted
@@ -101,7 +107,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
true);
}
[Fact]
[Test]
public void CreateProcedure_CommaBeforeNextColumnNoNewline()
{
// Verifies that commas are placed before the next column instead of after the current one,
@@ -119,35 +125,35 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
}, true);
}
[Fact]
[Test]
public void CreateProcedure_TwoPartName()
{
LoadAndFormatAndCompare("CreateProcedure_TwoPartName", GetInputFile("CreateProcedure_TwoPartName.sql"),
GetBaselineFile("CreateProcedure_TwoPartName.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_WithCTE()
{
LoadAndFormatAndCompare("CreateProcedure_WithCTE", GetInputFile("CreateProcedure_WithCTE.sql"),
GetBaselineFile("CreateProcedure_WithCTE.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_WithEncryptionModule()
{
LoadAndFormatAndCompare("CreateProcedure_WithEncryptionModule", GetInputFile("CreateProcedure_WithEncryptionModule.sql"),
GetBaselineFile("CreateProcedure_WithEncryptionModule.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_WithExecuteAsModule()
{
LoadAndFormatAndCompare("CreateProcedure_WithExecuteAsModule", GetInputFile("CreateProcedure_WithExecuteAsModule.sql"),
GetBaselineFile("CreateProcedure_WithExecuteAsModule.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateProcedure_WithThreeModules()
{
LoadAndFormatAndCompare("CreateProcedure_WithThreeModules", GetInputFile("CreateProcedure_WithThreeModules.sql"),

View File

@@ -4,14 +4,20 @@
//
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class CreateTableFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void CreateTable()
{
LoadAndFormatAndCompare("CreateTable", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable.sql"), new FormatOptions(), true);
@@ -20,7 +26,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
/**
* The test contains a timestamp column, which is the shortest (1 token) possible length for a column item.
*/
[Fact]
[Test]
public void CreateTable_Timestamp()
{
FormatOptions options = new FormatOptions();
@@ -28,7 +34,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_Timestamp", GetInputFile("CreateTable_Timestamp.sql"), GetBaselineFile("CreateTable_Timestamp.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_CommasBeforeDefinition()
{
FormatOptions options = new FormatOptions();
@@ -38,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_CommasBeforeDefinition", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_CommasBeforeDefinition.sql"), options, false);
}
[Fact]
[Test]
public void CreateTable_UseTabs()
{
FormatOptions options = new FormatOptions();
@@ -46,7 +52,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_UseTabs", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_UseTabs.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_20Spaces()
{
FormatOptions options = new FormatOptions();
@@ -54,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_20Spaces", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_20Spaces.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_UpperCaseKeywords()
{
FormatOptions options = new FormatOptions();
@@ -62,7 +68,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_UpperCaseKeywords", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_UpperCaseKeywords.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_LowerCaseKeywords()
{
FormatOptions options = new FormatOptions();
@@ -70,7 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_LowerCaseKeywords", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_LowerCaseKeywords.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_UpperCaseDataTypes()
{
FormatOptions options = new FormatOptions();
@@ -78,7 +84,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_UpperCaseDataTypes", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_UpperCaseDataTypes.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_LowerCaseDataTypes()
{
FormatOptions options = new FormatOptions();
@@ -86,14 +92,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_LowerCaseDataTypes", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_LowerCaseDataTypes.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_AlignInColumns()
{
FormatOptions options = new FormatOptions() { AlignColumnDefinitionsInColumns = true };
LoadAndFormatAndCompare("CreateTable_AlignInColumns", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_AlignInColumns.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_AlignInColumnsUseTabs()
{
FormatOptions options = new FormatOptions();
@@ -102,19 +108,19 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_AlignInColumnsUseTabs", GetInputFile("CreateTable.sql"), GetBaselineFile("CreateTable_AlignInColumnsUseTabs.sql"), options, true);
}
[Fact]
[Test]
public void CreateTable_On()
{
LoadAndFormatAndCompare("CreateTableOn", GetInputFile("CreateTableFull.sql"), GetBaselineFile("CreateTableOn.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateTable_Formatted()
{
LoadAndFormatAndCompare("CreateTable_Formatted", GetInputFile("CreateTable_Formatted.sql"), GetBaselineFile("CreateTable_Formatted.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateTable_CommentsBeforeComma()
{
FormatOptions options = new FormatOptions();
@@ -124,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTable_CommentsBeforeComma", GetInputFile("CreateTable_CommentBeforeComma.sql"), GetBaselineFile("CreateTable_CommentBeforeComma.sql"), options, true);
}
[Fact]
[Test]
public void CreateTableAddress_AlignInColumns()
{
FormatOptions options = new FormatOptions();
@@ -132,7 +138,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LoadAndFormatAndCompare("CreateTableAddress_AlignInColumns", GetInputFile("Address.sql"), GetBaselineFile("CreateTableAddress_AlignInColumns.sql"), options, true);
}
[Fact]
[Test]
public void CreateTableAddress_AlignInColumnsUseTabs()
{
FormatOptions options = new FormatOptions();

View File

@@ -5,62 +5,68 @@
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class CreateViewFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void CreateView_Full()
{
LoadAndFormatAndCompare("CreateView_Full", GetInputFile("CreateView_Full.sql"),
GetBaselineFile("CreateView_Full.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_FullWithComments()
{
LoadAndFormatAndCompare("CreateView_FullWithComments", GetInputFile("CreateView_FullWithComments.sql"), GetBaselineFile("CreateView_FullWithComments.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_MultipleColumns()
{
LoadAndFormatAndCompare("CreateView_MultipleColumns", GetInputFile("CreateView_MultipleColumns.sql"),
GetBaselineFile("CreateView_MultipleColumns.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_MultipleOptions()
{
LoadAndFormatAndCompare("CreateView_MultipleOptions", GetInputFile("CreateView_MultipleOptions.sql"),
GetBaselineFile("CreateView_MultipleOptions.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_OneColumn()
{
LoadAndFormatAndCompare("CreateView_OneColumn", GetInputFile("CreateView_OneColumn.sql"),
GetBaselineFile("CreateView_OneColumn.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_OneColumnOneOption()
{
LoadAndFormatAndCompare("CreateView_OneColumnOneOption", GetInputFile("CreateView_OneColumnOneOption.sql"),
GetBaselineFile("CreateView_OneColumnOneOption.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_OneOption()
{
LoadAndFormatAndCompare("CreateView_OneOption", GetInputFile("CreateView_OneOption.sql"),
GetBaselineFile("CreateView_OneOption.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void CreateView_Simple()
{
LoadAndFormatAndCompare("CreateView_Simple", GetInputFile("CreateView_Simple.sql"),

View File

@@ -8,25 +8,25 @@ using Microsoft.SqlTools.ServiceLayer.Formatter;
using Microsoft.SqlTools.ServiceLayer.Formatter.Contracts;
using Microsoft.SqlTools.ServiceLayer.SqlContext;
using Newtonsoft.Json.Linq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class FormatterSettingsTests
{
[Fact]
[Test]
public void ValidateFormatterServiceDefaults()
{
var sqlToolsSettings = new SqlToolsSettings();
Assert.Null(sqlToolsSettings.SqlTools.Format.AlignColumnDefinitionsInColumns);
Assert.Equal(CasingOptions.None, sqlToolsSettings.SqlTools.Format.DatatypeCasing);
Assert.Equal(CasingOptions.None, sqlToolsSettings.SqlTools.Format.KeywordCasing);
Assert.AreEqual(CasingOptions.None, sqlToolsSettings.SqlTools.Format.DatatypeCasing);
Assert.AreEqual(CasingOptions.None, sqlToolsSettings.SqlTools.Format.KeywordCasing);
Assert.Null(sqlToolsSettings.SqlTools.Format.PlaceCommasBeforeNextStatement);
Assert.Null(sqlToolsSettings.SqlTools.Format.PlaceSelectStatementReferencesOnNewLine);
Assert.Null(sqlToolsSettings.SqlTools.Format.UseBracketForIdentifiers);
}
[Fact]
[Test]
public void ValidateFormatSettingsParsedFromJson()
{
ValidateFormatSettings("mssql");
@@ -57,14 +57,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
SqlToolsSettings sqlToolsSettings = messageParams.ToObject<SqlToolsSettings>();
Assert.True(sqlToolsSettings.SqlTools.Format.AlignColumnDefinitionsInColumns);
Assert.Equal(CasingOptions.Lowercase, sqlToolsSettings.SqlTools.Format.DatatypeCasing);
Assert.Equal(CasingOptions.Uppercase, sqlToolsSettings.SqlTools.Format.KeywordCasing);
Assert.AreEqual(CasingOptions.Lowercase, sqlToolsSettings.SqlTools.Format.DatatypeCasing);
Assert.AreEqual(CasingOptions.Uppercase, sqlToolsSettings.SqlTools.Format.KeywordCasing);
Assert.True(sqlToolsSettings.SqlTools.Format.PlaceCommasBeforeNextStatement);
Assert.True(sqlToolsSettings.SqlTools.Format.PlaceSelectStatementReferencesOnNewLine);
Assert.True(sqlToolsSettings.SqlTools.Format.UseBracketForIdentifiers);
}
[Fact]
[Test]
public void FormatOptionsMatchDefaultSettings()
{
var options = new FormatOptions();
@@ -74,14 +74,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
private static void AssertOptionsHaveDefaultValues(FormatOptions options)
{
Assert.False(options.AlignColumnDefinitionsInColumns);
Assert.Equal(CasingOptions.None, options.DatatypeCasing);
Assert.Equal(CasingOptions.None, options.KeywordCasing);
Assert.AreEqual(CasingOptions.None, options.DatatypeCasing);
Assert.AreEqual(CasingOptions.None, options.KeywordCasing);
Assert.False(options.PlaceCommasBeforeNextStatement);
Assert.False(options.PlaceEachReferenceOnNewLineInQueryStatements);
Assert.False(options.EncloseIdentifiersInSquareBrackets);
}
[Fact]
[Test]
public void CanCopyDefaultFormatSettingsToOptions()
{
var sqlToolsSettings = new SqlToolsSettings();
@@ -90,7 +90,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
AssertOptionsHaveDefaultValues(options);
}
[Fact]
[Test]
public void CanCopyAlteredFormatSettingsToOptions()
{
SqlToolsSettings sqlToolsSettings = CreateNonDefaultFormatSettings();
@@ -116,8 +116,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
private static void AssertOptionsHaveExpectedNonDefaultValues(FormatOptions options)
{
Assert.True(options.AlignColumnDefinitionsInColumns);
Assert.Equal(CasingOptions.Lowercase, options.DatatypeCasing);
Assert.Equal(CasingOptions.Uppercase, options.KeywordCasing);
Assert.AreEqual(CasingOptions.Lowercase, options.DatatypeCasing);
Assert.AreEqual(CasingOptions.Uppercase, options.KeywordCasing);
Assert.True(options.PlaceCommasBeforeNextStatement);
Assert.True(options.PlaceEachReferenceOnNewLineInQueryStatements);
Assert.True(options.EncloseIdentifiersInSquareBrackets);
@@ -130,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
Assert.False(options.DoNotFormatKeywords);
}
[Fact]
[Test]
public void CanMergeRequestOptionsAndSettings()
{
var sqlToolsSettings = CreateNonDefaultFormatSettings();
@@ -142,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
AssertOptionsHaveExpectedNonDefaultValues(options);
Assert.False(options.UseTabs);
Assert.True(options.UseSpaces);
Assert.Equal(2, options.SpacesPerIndent);
Assert.AreEqual(2, options.SpacesPerIndent);
}
}
}

View File

@@ -18,7 +18,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class FormatterUnitTestsBase
{
public FormatterUnitTestsBase()
protected void InitFormatterUnitTestsBase()
{
HostMock = new Mock<IProtocolEndpoint>();
WorkspaceServiceMock = new Mock<WorkspaceService<SqlToolsSettings>>();

View File

@@ -4,13 +4,19 @@
//
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class GeneralFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void GoNewLineShouldBePreserved()
{
LoadAndFormatAndCompare("GoNewLineShouldBePreserved",
@@ -24,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verifyFormat: true);
}
[Fact]
[Test]
public void KeywordCaseConversionUppercase()
{
LoadAndFormatAndCompare("KeywordCaseConversion",
@@ -34,7 +40,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verifyFormat: true);
}
[Fact]
[Test]
public void KeywordCaseConversionLowercase()
{
LoadAndFormatAndCompare("KeywordCaseConversion",
@@ -44,7 +50,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verifyFormat: true);
}
[Fact]
[Test]
public void SelectWithOrderByShouldCorrectlyIndent()
{
LoadAndFormatAndCompare("SelectWithOrderByShouldCorrectlyIndent",
@@ -54,7 +60,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verifyFormat: true);
}
[Fact]
[Test]
public void SelectStatementShouldCorrectlyIndent()
{
LoadAndFormatAndCompare("SelectStatementShouldCorrectlyIndent",

View File

@@ -5,42 +5,48 @@
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class InsertFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void Insert_DefaultValues()
{
LoadAndFormatAndCompare("Insert_DefaultValues", GetInputFile("Insert_DefaultValues.sql"),
GetBaselineFile("Insert_DefaultValues.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void Insert_OpenQuery()
{
LoadAndFormatAndCompare("Insert_OpenQuery", GetInputFile("Insert_OpenQuery.sql"),
GetBaselineFile("Insert_OpenQuery.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void Insert_OutputInto()
{
LoadAndFormatAndCompare("Insert_OutputInto", GetInputFile("Insert_OutputInto.sql"),
GetBaselineFile("Insert_OutputInto.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void Insert_OutputStatement()
{
LoadAndFormatAndCompare("Insert_OutputStatement", GetInputFile("Insert_OutputStatement.sql"),
GetBaselineFile("Insert_OutputStatement.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void Insert_Select()
{
FormatOptions options = new FormatOptions();
@@ -49,7 +55,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("Insert_Select.sql"), options, true);
}
[Fact]
[Test]
public void Insert_SelectSource()
{
FormatOptions options = new FormatOptions();
@@ -58,21 +64,21 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("Insert_SelectSource.sql"), options, true);
}
[Fact]
[Test]
public void Insert_TopSpecification()
{
LoadAndFormatAndCompare("Insert_TopSpecification", GetInputFile("Insert_TopSpecification.sql"),
GetBaselineFile("Insert_TopSpecification.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void Insert_TopWithComments()
{
LoadAndFormatAndCompare("Insert_TopWithComments", GetInputFile("Insert_TopWithComments.sql"),
GetBaselineFile("Insert_TopWithComments.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void Insert_Full()
{
LoadAndFormatAndCompare("Insert_Full", GetInputFile("Insert_Full.sql"),

View File

@@ -4,21 +4,27 @@
//
using Microsoft.SqlTools.ServiceLayer.Formatter;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class SqlSelectStatementFormatterTests : FormatterUnitTestsBase
{
[Fact]
[SetUp]
public void Init()
{
InitFormatterUnitTestsBase();
}
[Test]
public void SimpleQuery()
{
LoadAndFormatAndCompare("SimpleQuery", GetInputFile("SimpleQuery.sql"),
GetBaselineFile("SimpleQuery.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void SimpleQuery_CommasBeforeDefinition()
{
FormatOptions options = new FormatOptions();
@@ -29,7 +35,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("SimpleQuery_CommasBeforeDefinition.sql"), options, false);
}
[Fact]
[Test]
public void SimpleQuery_EachReferenceOnNewLine()
{
FormatOptions options = new FormatOptions();
@@ -39,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("SimpleQuery_EachReferenceOnNewLine.sql"), options, true);
}
[Fact]
[Test]
public void SimpleQuery_EachReferenceOnNewLine_CommasBeforeDefinition()
{
FormatOptions options = new FormatOptions();
@@ -51,7 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetInputFile("SimpleQuery.sql"), GetBaselineFile("SimpleQuery_EachReferenceOnNewLine_CommasBeforeDefinition.sql"), options, false);
}
[Fact]
[Test]
public void SimpleQuery_UseTabs()
{
FormatOptions options = new FormatOptions();
@@ -61,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("SimpleQuery_UseTabs.sql"), options, true);
}
[Fact]
[Test]
public void SimpleQuery_20Spaces()
{
FormatOptions options = new FormatOptions();
@@ -71,7 +77,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("SimpleQuery_20Spaces.sql"), options, true);
}
[Fact]
[Test]
public void SimpleQuery_UpperCaseKeywords()
{
FormatOptions options = new FormatOptions();
@@ -81,7 +87,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("SimpleQuery_UpperCaseKeywords.sql"), options, true);
}
[Fact]
[Test]
public void SimpleQuery_LowerCaseKeywords()
{
FormatOptions options = new FormatOptions();
@@ -91,14 +97,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
GetBaselineFile("SimpleQuery_LowerCaseKeywords.sql"), options, true);
}
[Fact]
[Test]
public void SimpleQuery_ForBrowseClause()
{
LoadAndFormatAndCompare("SimpleQuery_ForBrowseClause", GetInputFile("SimpleQuery_ForBrowseClause.sql"),
GetBaselineFile("SimpleQuery_ForBrowseClause.sql"), new FormatOptions(), true);
}
[Fact]
[Test]
public void SimpleQuery_ForXmlClause()
{
LoadAndFormatAndCompare("SimpleQuery_ForXmlClause", GetInputFile("SimpleQuery_ForXmlClause.sql"),

View File

@@ -16,19 +16,22 @@ using Microsoft.SqlTools.ServiceLayer.Test.Common.RequestContextMocking;
using Microsoft.SqlTools.ServiceLayer.UnitTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Moq;
using Xunit;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class TSqlFormatterServiceTests : FormatterUnitTestsBase
{
private Mock<ServiceLayer.Workspace.Workspace> workspaceMock = new Mock<ServiceLayer.Workspace.Workspace>();
private Mock<ServiceLayer.Workspace.Workspace> workspaceMock;
private TextDocumentIdentifier textDocument;
DocumentFormattingParams docFormatParams;
DocumentRangeFormattingParams rangeFormatParams;
public TSqlFormatterServiceTests()
[SetUp]
public void InitTSqlFormatterServiceTests()
{
InitFormatterUnitTestsBase();
workspaceMock = new Mock<ServiceLayer.Workspace.Workspace>();
textDocument = new TextDocumentIdentifier
{
Uri = "script file"
@@ -64,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
LanguageServiceMock.Setup(x => x.ShouldSkipNonMssqlFile(It.IsAny<string>())).Returns(skipFile);
}
[Fact]
[Test]
public async Task FormatDocumentShouldReturnSingleEdit()
{
// Given a document that we want to format
@@ -76,12 +79,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verify: (edits =>
{
// Then expect a single edit to be returned and for it to match the standard formatting
Assert.Equal(1, edits.Length);
Assert.AreEqual(1, edits.Length);
AssertFormattingEqual(formattedSqlContents, edits[0].NewText);
}));
}
[Fact]
[Test]
public async Task FormatDocumentShouldSkipNonMssqlFile()
{
// Given a non-MSSQL document
@@ -93,12 +96,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verify: (edits =>
{
// Then expect a single edit to be returned and for it to match the standard formatting
Assert.Equal(0, edits.Length);
Assert.AreEqual(0, edits.Length);
LanguageServiceMock.Verify(x => x.ShouldSkipNonMssqlFile(docFormatParams.TextDocument.Uri), Times.Once);
}));
}
[Fact]
[Test]
public async Task FormatRangeShouldReturnSingleEdit()
{
// Given a document that we want to format
@@ -110,12 +113,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verify: (edits =>
{
// Then expect a single edit to be returned and for it to match the standard formatting
Assert.Equal(1, edits.Length);
Assert.AreEqual(1, edits.Length);
AssertFormattingEqual(formattedSqlContents, edits[0].NewText);
}));
}
[Fact]
[Test]
public async Task FormatRangeShouldSkipNonMssqlFile()
{
// Given a non-MSSQL document
@@ -127,13 +130,13 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
verify: (edits =>
{
// Then expect a single edit to be returned and for it to match the standard formatting
Assert.Equal(0, edits.Length);
Assert.AreEqual(0, edits.Length);
LanguageServiceMock.Verify(x => x.ShouldSkipNonMssqlFile(docFormatParams.TextDocument.Uri), Times.Once);
}));
}
[Fact]
[Test]
public async Task FormatDocumentTelemetryShouldIncludeFormatTypeProperty()
{
await RunAndVerifyTelemetryTest(
@@ -145,12 +148,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
// Then expect a telemetry event to have been sent with the right format definition
Assert.NotNull(actualParams);
Assert.Equal(TelemetryEventNames.FormatCode, actualParams.Params.EventName);
Assert.Equal(TelemetryPropertyNames.DocumentFormatType, actualParams.Params.Properties[TelemetryPropertyNames.FormatType]);
Assert.AreEqual(TelemetryEventNames.FormatCode, actualParams.Params.EventName);
Assert.AreEqual(TelemetryPropertyNames.DocumentFormatType, actualParams.Params.Properties[TelemetryPropertyNames.FormatType]);
});
}
[Fact]
[Test]
public async Task FormatRangeTelemetryShouldIncludeFormatTypeProperty()
{
await RunAndVerifyTelemetryTest(
@@ -162,11 +165,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
// Then expect a telemetry event to have been sent with the right format definition
Assert.NotNull(actualParams);
Assert.Equal(TelemetryEventNames.FormatCode, actualParams.Params.EventName);
Assert.Equal(TelemetryPropertyNames.RangeFormatType, actualParams.Params.Properties[TelemetryPropertyNames.FormatType]);
Assert.AreEqual(TelemetryEventNames.FormatCode, actualParams.Params.EventName);
Assert.AreEqual(TelemetryPropertyNames.RangeFormatType, actualParams.Params.Properties[TelemetryPropertyNames.FormatType]);
// And expect range to have been correctly formatted
Assert.Equal(1, result.Length);
Assert.AreEqual(1, result.Length);
AssertFormattingEqual(formattedSqlContents, result[0].NewText);
});
}