use path to identify edit target (#1292)

* use path to identify edit target

* async action

* revert RequestContext change

* comments

* address comments

* fix test
This commit is contained in:
Alan Ren
2021-11-10 17:39:48 -08:00
committed by GitHub
parent c738e3bdf7
commit a3c69f3dd2
14 changed files with 528 additions and 173 deletions

View File

@@ -0,0 +1,66 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.ServiceLayer.TableDesigner;
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
{
public class DesignerPathUtilsTest
{
[Test]
public void ParseDesignerPathTest()
{
DesignerEditType editType = DesignerEditType.Add;
this.RunTest(new object[] { "property1" }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, true);
this.RunTest(new object[] { "property1", "xx", "property2" }, editType, false);
this.RunTest(new object[] { "property1", 1 }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3" }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);
editType = DesignerEditType.Remove;
this.RunTest(new object[] { "property1", 0 }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, true);
this.RunTest(new object[] { "property1" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3", 1 }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);
editType = DesignerEditType.Update;
this.RunTest(new object[] { "property1" }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2" }, editType, true);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3" }, editType, true);
this.RunTest(new object[] { "property1", "abc" }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1 }, editType, false);
this.RunTest(new object[] { "property1", 1, "property2", 1, "property3", 2, "property4" }, editType, false);
this.RunTest(new object[] { }, editType, false);
this.RunTest(null, editType, false);
}
private void RunTest(object[] path, DesignerEditType editType, bool isValidPath)
{
if (isValidPath)
{
Assert.DoesNotThrow(() =>
{
DesignerPathUtils.Validate(path, editType);
}, string.Format("Path '{0}' should be a valid path for edit type: '{1}'.", path, editType.ToString()));
}
else
{
Assert.Throws<ArgumentException>(() =>
{
DesignerPathUtils.Validate(path, editType);
}, string.Format("Path '{0}' should not be a valid path for edit type: '{1}'.", path, editType.ToString()));
}
}
}
}

View File

@@ -1,30 +0,0 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Microsoft.SqlTools.ServiceLayer.TableDesigner.Contracts;
using NUnit.Framework;
using Newtonsoft.Json;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.TableDesigner
{
public class TableDesignerChangeInfoTest
{
[Test]
public void DeserializeTableChangeProperty()
{
string testJsonStringType = "{\"type\": 1, \"property\": \"columns\"}";
TableDesignerChangeInfo changeInfo = JsonConvert.DeserializeObject<TableDesignerChangeInfo>(testJsonStringType);
Assert.IsNotNull(changeInfo, "string property: the changeInfo shouldn't be null.");
Assert.IsNotNull(changeInfo.Property, "string property: the property shouldn't be null.");
Assert.IsTrue(changeInfo.Property.GetType() == typeof(string));
string testJsonObjectType = "{\"type\": 1, \"property\": {\"parentProperty\": \"columns\",\"index\": 0,\"property\": \"length\"}}";
changeInfo = JsonConvert.DeserializeObject<TableDesignerChangeInfo>(testJsonObjectType);
Assert.IsNotNull(changeInfo, "object property: the changeInfo shouldn't be null.");
Assert.IsNotNull(changeInfo.Property, "object property: the property shouldn't be null.");
Assert.IsTrue(changeInfo.Property.GetType() == typeof(TableDesignerPropertyIdentifier));
}
}
}