mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-07 09:35:37 -05:00
Feature/schemacompare scmp save (#824)
* First cut of scmp Save related changes and some test refactoring * Adding Exclude/Include objects in saving * Add diff entry validation as part of test * Adding PR comments - major change is change to nameparts in place of name hence preserving any "."/"[" in name and avoiding any string operations * One more UT scenario addition for create excluded object
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
using System;
|
||||
using Microsoft.SqlTools.ServiceLayer.SchemaCompare;
|
||||
using Microsoft.SqlTools.ServiceLayer.SchemaCompare.Contracts;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
@@ -16,7 +17,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
{
|
||||
string script = "EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Primary key for AWBuildVersion records.', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'AWBuildVersion', @level2type = N'COLUMN', @level2name = N'SystemInformationID';";
|
||||
Assert.DoesNotContain("GO", script);
|
||||
string result = SchemaCompareOperation.FormatScript(script);
|
||||
string result = SchemaCompareUtils.FormatScript(script);
|
||||
Assert.EndsWith("GO", result);
|
||||
}
|
||||
|
||||
@@ -24,12 +25,12 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
public void FormatScriptDoesNotAddGoForNullScripts()
|
||||
{
|
||||
string script1 = null;
|
||||
string result1 = SchemaCompareOperation.FormatScript(script1);
|
||||
string result1 = SchemaCompareUtils.FormatScript(script1);
|
||||
Assert.DoesNotContain("GO", result1);
|
||||
Assert.Equal(null, result1);
|
||||
|
||||
string script2 = "null";
|
||||
string result2 = SchemaCompareOperation.FormatScript(script2);
|
||||
string result2 = SchemaCompareUtils.FormatScript(script2);
|
||||
Assert.DoesNotContain("GO", result2);
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
public void FormatScriptDoesNotAddGoForEmptyStringScripts()
|
||||
{
|
||||
string script = string.Empty;
|
||||
string result = SchemaCompareOperation.FormatScript(script);
|
||||
string result = SchemaCompareUtils.FormatScript(script);
|
||||
Assert.DoesNotContain("GO", result);
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
@@ -47,7 +48,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
{
|
||||
string script = " \t\n";
|
||||
Assert.True(string.IsNullOrWhiteSpace(script));
|
||||
string result = SchemaCompareOperation.FormatScript(script);
|
||||
string result = SchemaCompareUtils.FormatScript(script);
|
||||
Assert.DoesNotContain("GO", result);
|
||||
Assert.Equal(string.Empty, result);
|
||||
}
|
||||
@@ -57,14 +58,14 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
{
|
||||
// leading whitespace
|
||||
string script1 = "\r\n EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Primary key for AWBuildVersion records.', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'AWBuildVersion', @level2type = N'COLUMN', @level2name = N'SystemInformationID';";
|
||||
string result1 = SchemaCompareOperation.RemoveExcessWhitespace(script1);
|
||||
string result1 = SchemaCompareUtils.RemoveExcessWhitespace(script1);
|
||||
Assert.False(script1.Equals(result1));
|
||||
Assert.False(result1.StartsWith("\r"));
|
||||
Assert.True(result1.StartsWith("EXECUTE"));
|
||||
|
||||
// trailing whitespace
|
||||
string script2 = "EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Primary key for AWBuildVersion records.', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'AWBuildVersion', @level2type = N'COLUMN', @level2name = N'SystemInformationID'; \n";
|
||||
string result2 = SchemaCompareOperation.RemoveExcessWhitespace(script2);
|
||||
string result2 = SchemaCompareUtils.RemoveExcessWhitespace(script2);
|
||||
Assert.False(script2.Equals(result2));
|
||||
Assert.False(result2.EndsWith("\n"));
|
||||
Assert.True(result2.EndsWith(";"));
|
||||
@@ -82,8 +83,54 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.SchemaCompare
|
||||
[VersionDate] DATETIME NOT NULL,
|
||||
[ModifiedDate] DATETIME NOT NULL
|
||||
);";
|
||||
string result3 = SchemaCompareOperation.RemoveExcessWhitespace(script3);
|
||||
string result3 = SchemaCompareUtils.RemoveExcessWhitespace(script3);
|
||||
Assert.True(expected3.Equals(result3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateExcludedObjects()
|
||||
{
|
||||
//successful creation
|
||||
ValidateTableCreation(new string[] { "dbo", "Table1" }, "dbo.Table1");
|
||||
ValidateTableCreation(new string[] { "[dbo]", "Table.1" }, "[dbo].Table.1");
|
||||
|
||||
//null creation due to null name
|
||||
SchemaCompareObjectId object1 = new SchemaCompareObjectId
|
||||
{
|
||||
NameParts = null, //null caused by this value
|
||||
SqlObjectType = "Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlTable"
|
||||
};
|
||||
|
||||
var nullResult1 = SchemaCompareUtils.CreateExcludedObject(object1);
|
||||
Assert.Null(nullResult1);
|
||||
|
||||
//null creation due to argumentException
|
||||
SchemaCompareObjectId object2 = new SchemaCompareObjectId
|
||||
{
|
||||
NameParts = new string[] { "dbo", "Table1" },
|
||||
SqlObjectType = "SqlTable" // null caused by this value
|
||||
};
|
||||
|
||||
var nullResult2 = SchemaCompareUtils.CreateExcludedObject(object2);
|
||||
Assert.Null(nullResult2);
|
||||
}
|
||||
|
||||
private void ValidateTableCreation(string[] nameParts, string validationString)
|
||||
{
|
||||
SchemaCompareObjectId validObject1 = new SchemaCompareObjectId
|
||||
{
|
||||
NameParts = nameParts,
|
||||
SqlObjectType = "Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlTable"
|
||||
};
|
||||
var validResult1 = SchemaCompareUtils.CreateExcludedObject(validObject1);
|
||||
Assert.NotNull(validResult1);
|
||||
Assert.Equal(validObject1.SqlObjectType, validResult1.TypeName);
|
||||
Assert.Equal(validObject1.NameParts.Length, validResult1.Identifier.Parts.Count);
|
||||
Assert.Equal(validationString, string.Join(".", validResult1.Identifier.Parts));
|
||||
for (int i = 0; i < validObject1.NameParts.Length; i++)
|
||||
{
|
||||
Assert.Equal(validObject1.NameParts[i], validResult1.Identifier.Parts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user